diff --git a/xpcom/io/nsLocalFileOSX.cpp b/xpcom/io/nsLocalFileOSX.cpp index 423eb6ae846..61508ba0f9e 100644 --- a/xpcom/io/nsLocalFileOSX.cpp +++ b/xpcom/io/nsLocalFileOSX.cpp @@ -1124,53 +1124,13 @@ NS_IMETHODIMP nsLocalFile::GetParent(nsIFile * *aParent) *aParent = nsnull; nsresult rv; - -#if DEBUG - // In a debug build, where components are symlinks, we need to do it this way. - // If a file object which is a symlink is asked for its parent, its parent - // will be that of the resolved link which isn't what the component mgr - // expects. - nsCAutoString thisPath; - rv = GetNativePath(thisPath); - if (NS_FAILED(rv)) - return rv; - - char *buffer = NS_CONST_CAST(char *, thisPath.get()), - *slashp = buffer; - - // find the last significant slash in buffer - slashp = strrchr(buffer, '/'); - NS_ASSERTION(slashp, "non-canonical mPath?"); - if (!slashp) - return NS_ERROR_FILE_INVALID_PATH; - - // for the case where we are at '/' - if (slashp == buffer) - slashp++; - - // temporarily terminate buffer at the last significant slash - char c = *slashp; - *slashp = '\0'; - - nsCOMPtr localFile; - rv = NS_NewNativeLocalFile(nsDependentCString(buffer), PR_TRUE, - getter_AddRefs(localFile)); - - // make buffer whole again - *slashp = c; - - *aParent = localFile; - NS_IF_ADDREF(*aParent); - -#else - FSRef fsRef; nsLocalFile *newFile = nsnull; // If it can be determined without error that a file does not // have a parent, return nsnull for the parent and NS_OK as the result. // See bug 133617. - + rv = GetFSRefInternal(fsRef); if (NS_SUCCEEDED(rv)) { FSRef parentRef; @@ -1203,7 +1163,6 @@ NS_IMETHODIMP nsLocalFile::GetParent(nsIFile * *aParent) return NS_ERROR_FAILURE; *aParent = newFile; NS_ADDREF(*aParent); -#endif return NS_OK; } @@ -1356,7 +1315,7 @@ NS_IMETHODIMP nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileD NS_ENSURE_ARG_POINTER(_retval); nsCAutoString path; - nsresult rv = GetNativePath(path); + nsresult rv = GetPathInternal(path); if (NS_FAILED(rv)) return rv; @@ -1374,7 +1333,7 @@ NS_IMETHODIMP nsLocalFile::OpenANSIFileDesc(const char *mode, FILE **_retval) NS_ENSURE_ARG_POINTER(_retval); nsCAutoString path; - nsresult rv = GetNativePath(path); + nsresult rv = GetPathInternal(path); if (NS_FAILED(rv)) return rv; @@ -1394,7 +1353,7 @@ NS_IMETHODIMP nsLocalFile::Load(PRLibrary **_retval) NS_TIMELINE_START_TIMER("PR_LoadLibrary"); nsCAutoString path; - nsresult rv = GetNativePath(path); + nsresult rv = GetPathInternal(path); if (NS_FAILED(rv)) return rv; @@ -1998,6 +1957,33 @@ nsresult nsLocalFile::GetFSRefInternal(FSRef& aFSSpec) return NS_OK; } +nsresult nsLocalFile::GetPathInternal(nsACString& path) +{ + FSRef fsRef; + UInt8 pathBuf[PATH_MAX + 1]; + + if (NS_SUCCEEDED(Resolve())) + fsRef = mFollowLinks ? mTargetFSRef : mFSRef; + else + fsRef = mFSRef; + + OSErr err = ::FSRefMakePath(&fsRef, pathBuf, sizeof(pathBuf)); + if (err != noErr) + return MacErrorMapper(err); + path.Assign((char *)pathBuf); + + // If Resolve() succeeds, mNonExtantNodes is empty. + deque::iterator iter(mNonExtantNodes.begin()); + deque::iterator end(mNonExtantNodes.end()); + while (iter != end) { + path.Append(kPathSepChar); + path.Append((NS_ConvertUCS2toUTF8(*iter))); + ++iter; + } + + return NS_OK; +} + nsresult nsLocalFile::ResolveNonExtantNodes(PRBool aCreateDirs) { deque::iterator iter(mNonExtantNodes.begin()); diff --git a/xpcom/io/nsLocalFileOSX.h b/xpcom/io/nsLocalFileOSX.h index fa36dffb33c..d22c3146574 100644 --- a/xpcom/io/nsLocalFileOSX.h +++ b/xpcom/io/nsLocalFileOSX.h @@ -78,14 +78,15 @@ protected: nsLocalFile(const FSRef& aFSRef, const nsAString& aRelativePath); nsLocalFile(const nsLocalFile& src); - nsresult Resolve(); - nsresult GetFSRefInternal(FSRef& aFSSpec); + nsresult Resolve(); + nsresult GetFSRefInternal(FSRef& aFSSpec); + nsresult GetPathInternal(nsACString& path); // Returns path WRT mFollowLinks nsresult ResolveNonExtantNodes(PRBool aCreateDirs); - nsresult MoveCopy(nsIFile* newParentDir, const nsAString &newName, PRBool isCopy, PRBool followLinks); + nsresult MoveCopy(nsIFile* newParentDir, const nsAString &newName, PRBool isCopy, PRBool followLinks); - static PRInt64 HFSPlustoNSPRTime(const UTCDateTime& utcTime); - static void NSPRtoHFSPlusTime(PRInt64 nsprTime, UTCDateTime& utcTime); + static PRInt64 HFSPlustoNSPRTime(const UTCDateTime& utcTime); + static void NSPRtoHFSPlusTime(PRInt64 nsprTime, UTCDateTime& utcTime); protected: FSRef mFSRef; @@ -93,16 +94,16 @@ protected: FSRef mTargetFSRef; // If mFSRef is an alias file, its target - PRPackedBool mFollowLinks; + PRPackedBool mFollowLinks; - PRPackedBool mIdentityDirty; - PRPackedBool mFollowLinksDirty; + PRPackedBool mIdentityDirty; + PRPackedBool mFollowLinksDirty; - static PRInt64 kJanuaryFirst1970Seconds; + static PRInt64 kJanuaryFirst1970Seconds; static PRUnichar kPathSepUnichar; - static char kPathSepChar; + static char kPathSepChar; static FSRef kInvalidFSRef; - static FSRef kRootFSRef; + static FSRef kRootFSRef; }; #endif // nsLocalFileMac_h__ diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index 3f89ba553b3..172b41bafb8 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -343,9 +343,10 @@ xptiInterfaceInfoManager::BuildFileList(nsISupportsArray* aSearchPath, entries->GetNext(getter_AddRefs(sup)); if(!sup) return PR_FALSE; - nsCOMPtr file = do_QueryInterface(sup); + nsCOMPtr file = do_QueryInterface(sup); if(!file) return PR_FALSE; + file->SetFollowLinks(PR_FALSE); PRBool isFile; if(NS_FAILED(file->IsFile(&isFile)) || !isFile) @@ -385,15 +386,21 @@ xptiInterfaceInfoManager::ReadXPTFile(nsILocalFile* aFile, XPTCursor cursor; PRInt32 flen; PRInt64 fileSize; + + PRBool saveFollowLinks; + aFile->GetFollowLinks(&saveFollowLinks); + aFile->SetFollowLinks(PR_TRUE); if(NS_FAILED(aFile->GetFileSize(&fileSize)) || !(flen = nsInt64(fileSize))) { + aFile->SetFollowLinks(saveFollowLinks); return nsnull; } whole = new char[flen]; if (!whole) { + aFile->SetFollowLinks(saveFollowLinks); return nsnull; } @@ -432,6 +439,7 @@ xptiInterfaceInfoManager::ReadXPTFile(nsILocalFile* aFile, XPT_DestroyXDRState(state); if(whole) delete [] whole; + aFile->SetFollowLinks(saveFollowLinks); return header; }