Bug 173311 - RealPlayer One 9.0b2 plugin causes crash at startup for Mach-0 build because of symlink (alias) handling problems. r=bnesse/sr=sfraser/a=dbaron

This commit is contained in:
ccarlen%netscape.com 2002-11-01 15:45:38 +00:00
parent cbdc43aebe
commit 88535bd0b1
3 changed files with 52 additions and 57 deletions

View File

@ -1124,46 +1124,6 @@ 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<nsILocalFile> 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;
@ -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<nsString>::iterator iter(mNonExtantNodes.begin());
deque<nsString>::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<nsString>::iterator iter(mNonExtantNodes.begin());

View File

@ -80,6 +80,7 @@ protected:
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);

View File

@ -343,9 +343,10 @@ xptiInterfaceInfoManager::BuildFileList(nsISupportsArray* aSearchPath,
entries->GetNext(getter_AddRefs(sup));
if(!sup)
return PR_FALSE;
nsCOMPtr<nsIFile> file = do_QueryInterface(sup);
nsCOMPtr<nsILocalFile> file = do_QueryInterface(sup);
if(!file)
return PR_FALSE;
file->SetFollowLinks(PR_FALSE);
PRBool isFile;
if(NS_FAILED(file->IsFile(&isFile)) || !isFile)
@ -386,14 +387,20 @@ xptiInterfaceInfoManager::ReadXPTFile(nsILocalFile* aFile,
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;
}