From 851457b19fda05dfc4008fd8ccbb8af000667d2f Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Thu, 29 Jul 1999 04:31:04 +0000 Subject: [PATCH] fix for #10697. ResolveSymlink() messes with mCurrent, so we need to restore it. Also, make ResolveSymlink() return an absolute file, instead of a relative one. git-svn-id: svn://10.0.0.236/trunk@41541 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsFileSpec.h | 1 + mozilla/xpcom/io/nsFileSpecBeOS.cpp | 11 ++++++++++- mozilla/xpcom/io/nsFileSpecUnix.cpp | 11 ++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mozilla/xpcom/io/nsFileSpec.h b/mozilla/xpcom/io/nsFileSpec.h index 320c22fd3fd..563e7711098 100644 --- a/mozilla/xpcom/io/nsFileSpec.h +++ b/mozilla/xpcom/io/nsFileSpec.h @@ -717,6 +717,7 @@ class NS_COM nsDirectoryIterator PRBool mResoveSymLinks; #if defined(XP_UNIX) || defined(XP_BEOS) + nsFileSpec mStarting; DIR* mDir; #elif defined(XP_PC) PRDir* mDir; // XXX why not use PRDir for Unix too? diff --git a/mozilla/xpcom/io/nsFileSpecBeOS.cpp b/mozilla/xpcom/io/nsFileSpecBeOS.cpp index d859ef17ac8..7fdf8fc5cba 100644 --- a/mozilla/xpcom/io/nsFileSpecBeOS.cpp +++ b/mozilla/xpcom/io/nsFileSpecBeOS.cpp @@ -156,7 +156,13 @@ nsresult nsFileSpec::ResolveSymlink(PRBool& wasAliased) resolvedPath[charCount] = '\0'; wasAliased = PR_TRUE; - mPath = (char*)&resolvedPath; + /* if it's not an absolute path, replace the leaf with what got resolved */ + if (resolvedPath[0] != '/') { + SetLeafName(resolvedPath); + } + else { + mPath = (char*)&resolvedPath; + } } return NS_OK; @@ -442,10 +448,12 @@ nsDirectoryIterator::nsDirectoryIterator( , PRBool resolveSymlinks) //---------------------------------------------------------------------------------------- : mCurrent(inDirectory) + , mStarting(inDirectory) , mExists(PR_FALSE) , mDir(nsnull) , mResoveSymLinks(resolveSymlinks) { + mStarting += "sysygy"; // save off the starting directory mCurrent += "sysygy"; // prepare the path for SetLeafName mDir = opendir((const char*)nsFilePath(inDirectory)); ++(*this); @@ -476,6 +484,7 @@ nsDirectoryIterator& nsDirectoryIterator::operator ++ () if (entry) { mExists = PR_TRUE; + mCurrent = mStarting; // restore mCurrent to be the starting directory. ResolveSymlink() may have taken us to another directory mCurrent.SetLeafName(entry->d_name); if (mResoveSymLinks) { diff --git a/mozilla/xpcom/io/nsFileSpecUnix.cpp b/mozilla/xpcom/io/nsFileSpecUnix.cpp index 357b88befd7..d20cf486151 100644 --- a/mozilla/xpcom/io/nsFileSpecUnix.cpp +++ b/mozilla/xpcom/io/nsFileSpecUnix.cpp @@ -225,7 +225,13 @@ nsresult nsFileSpec::ResolveSymlink(PRBool& wasAliased) resolvedPath[charCount] = '\0'; wasAliased = PR_TRUE; - mPath = (char*)&resolvedPath; + /* if it's not an absolute path, replace the leaf with what got resolved */ + if (resolvedPath[0] != '/') { + SetLeafName(resolvedPath); + } + else { + mPath = (char*)&resolvedPath; + } } return NS_OK; @@ -523,10 +529,12 @@ PRUint32 nsFileSpec::GetDiskSpaceAvailable() const nsDirectoryIterator::nsDirectoryIterator(const nsFileSpec& inDirectory, PRBool resolveSymLinks) //---------------------------------------------------------------------------------------- : mCurrent(inDirectory) + , mStarting(inDirectory) , mExists(PR_FALSE) , mDir(nsnull) , mResoveSymLinks(resolveSymLinks) { + mStarting += "sysygy"; // save off the starting directory mCurrent += "sysygy"; // prepare the path for SetLeafName mDir = opendir((const char*)nsFilePath(inDirectory)); ++(*this); @@ -557,6 +565,7 @@ nsDirectoryIterator& nsDirectoryIterator::operator ++ () if (entry) { mExists = PR_TRUE; + mCurrent = mStarting; // restore mCurrent to be the starting directory. ResolveSymlink() may have taken us to another directory mCurrent.SetLeafName(entry->d_name); if (mResoveSymLinks) {