diff --git a/mozilla/xpcom/io/nsIFile.idl b/mozilla/xpcom/io/nsIFile.idl index 616c06a6816..8d428b46238 100644 --- a/mozilla/xpcom/io/nsIFile.idl +++ b/mozilla/xpcom/io/nsIFile.idl @@ -229,10 +229,10 @@ interface nsIFile : nsISupports boolean equals(in nsIFile inFile); /** - * Will determine the inFile is a descendant + * Will determine if the inFile is a descendant * If |recur| is true, it will descend subdirectories looking for */ - boolean isContainedIn(in nsIFile inFile, in boolean recur); + boolean contains(in nsIFile inFile, in boolean recur); /** * Parent will be nsnull when this is at the top of the volume. diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index 2b1093fb12f..eb55956d027 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -1381,7 +1381,7 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) } NS_IMETHODIMP -nsLocalFile::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) +nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) { *_retval = PR_FALSE; diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index b91b0ab5e97..33104d94cb2 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -986,44 +986,33 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) } NS_IMETHODIMP -nsLocalFile::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) +nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) { NS_ENSURE_ARG(inFile); NS_ENSURE_ARG_POINTER(_retval); - + nsXPIDLCString inPath; nsresult rv; + + *_retval = PR_FALSE; if (NS_FAILED(rv = inFile->GetPath(getter_Copies(inPath)))) return rv; - ssize_t inLen = strlen(inPath); + ssize_t len = strlen(mPath); - /* remove trailing slashes */ - while (((const char *)mPath)[inLen - 1] == '/') - inLen--; + if ( strncmp( mPath, inPath, len) == 0) + { + // now make sure that the |inFile|'s path has a trailing + // separator. + + if (inPath[len] == '/') + { + *_retval = PR_TRUE; + } - /* - * See if the given path is a prefix of our path, but make sure that - * we don't treat /foo as a parent of /foobar/thing. - */ - if (strncmp(inPath, mPath, inLen) || ((const char *)mPath)[inLen] != '/') { - *_retval = PR_FALSE; - return NS_OK; - } - if (recur) { - /* good enough -- don't need to check for direct parentage */ - *_retval = PR_TRUE; - return NS_OK; } - const char *parentEnd = strrchr(mPath, '/'); - if (inLen == (parentEnd - (const char *)mPath)) { - *_retval = PR_TRUE; - return NS_OK; - } - - *_retval = PR_FALSE; return NS_OK; } diff --git a/mozilla/xpcom/io/nsLocalFileWin.cpp b/mozilla/xpcom/io/nsLocalFileWin.cpp index e52435c43ea..ad39a973636 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.cpp +++ b/mozilla/xpcom/io/nsLocalFileWin.cpp @@ -1692,34 +1692,32 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) } NS_IMETHODIMP -nsLocalFile::IsContainedIn(nsIFile *inFile, PRBool recur, PRBool *_retval) +nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) { + NS_ENSURE_ARG(inFile); + NS_ENSURE_ARG_POINTER(_retval); + + nsXPIDLCString inPath; + nsresult rv; + *_retval = PR_FALSE; - - char* myFilePath; - if ( NS_FAILED(GetTarget(&myFilePath))) - GetPath(&myFilePath); - - PRInt32 myFilePathLen = strlen(myFilePath); - - char* inFilePath; - if ( NS_FAILED(inFile->GetTarget(&inFilePath))) - inFile->GetPath(&inFilePath); - if ( strncmp( myFilePath, inFilePath, myFilePathLen) == 0) + if (NS_FAILED(rv = inFile->GetPath(getter_Copies(inPath)))) + return rv; + + size_t len = strlen(mPath); + + if ( strncmp( mPath, inPath, len) == 0) { // now make sure that the |inFile|'s path has a trailing // separator. - if (inFilePath[myFilePathLen] == '\\') + if (inPath[len] == '\\') { *_retval = PR_TRUE; } } - - nsAllocator::Free(inFilePath); - nsAllocator::Free(myFilePath); return NS_OK; }