From c422448137e7faa425c90679ce84fe2d7307836c Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Wed, 12 Jul 2000 23:31:31 +0000 Subject: [PATCH] bug 40750. Adding followSymlink flag to nsILocalFile. Adjusting callers. windows shortcut optimizations. r=blizzard@mozilla.org. a=brendan@mozilla.org --- docshell/base/nsDocShell.cpp | 1 + embedding/base/nsEmbedAPI.cpp | 3 +- .../tools/src/nsXPCToolsCompiler.cpp | 13 +- layout/html/forms/src/nsFormFrame.cpp | 2 +- netwerk/base/src/nsStdURL.cpp | 2 +- netwerk/cache/filecache/nsDiskCacheRecord.cpp | 2 +- netwerk/cache/filecache/nsNetDiskCache.cpp | 2 +- netwerk/protocol/file/src/nsFileChannel.cpp | 4 + netwerk/protocol/http/src/nsHTTPHandler.cpp | 2 +- netwerk/test/TestFileInput.cpp | 4 +- netwerk/test/TestFileInput2.cpp | 4 +- netwerk/test/TestFileTransport.cpp | 8 +- netwerk/test/TestWriteStream.cpp | 2 +- widget/src/gtk/nsAppShell.cpp | 3 +- widget/src/mac/nsDragService.cpp | 2 +- widget/src/windows/nsClipboard.cpp | 2 +- xpcom/build/dlldeps.cpp | 2 +- xpcom/io/nsFileSpec.cpp | 1 + xpcom/io/nsILocalFile.idl | 23 ++- xpcom/io/nsILocalFileMac.h | 2 +- xpcom/io/nsLocalFileCommon.cpp | 136 ++++++++++-------- xpcom/io/nsLocalFileMac.cpp | 31 +++- xpcom/io/nsLocalFileMac.h | 6 +- xpcom/io/nsLocalFileOS2.cpp | 38 ++++- xpcom/io/nsLocalFileOS2.h | 5 +- xpcom/io/nsLocalFileUnix.cpp | 18 ++- xpcom/io/nsLocalFileWin.cpp | 70 ++++++--- xpcom/io/nsLocalFileWin.h | 8 +- xpcom/tests/makefile.win | 4 + xpfe/components/xfer/src/nsStreamTransfer.cpp | 4 +- xpfe/components/xfer/src/nsStreamXferOp.cpp | 2 +- xpinstall/src/ScheduledTasks.cpp | 6 +- xpinstall/src/nsInstall.cpp | 4 +- xpinstall/src/nsInstallDelete.cpp | 2 +- xpinstall/src/nsInstallFolder.cpp | 4 +- xpinstall/src/nsInstallPatch.cpp | 2 +- xpinstall/src/nsInstallUninstall.cpp | 2 +- xpinstall/src/nsJSFile.cpp | 8 +- xpinstall/src/nsSoftwareUpdateRun.cpp | 4 +- xpinstall/stub/xpistub.cpp | 14 +- 40 files changed, 295 insertions(+), 157 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 885a9214c59..7b906fbb218 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1188,6 +1188,7 @@ nsDocShell::GotoIndex(PRInt32 aIndex) return NS_OK; } + NS_IMETHODIMP nsDocShell::LoadURI(const PRUnichar* aURI) { nsCOMPtr uri; diff --git a/embedding/base/nsEmbedAPI.cpp b/embedding/base/nsEmbedAPI.cpp index b32b200f852..1be3a4b251e 100644 --- a/embedding/base/nsEmbedAPI.cpp +++ b/embedding/base/nsEmbedAPI.cpp @@ -75,7 +75,7 @@ nsresult NS_InitEmbedding(const char *aPath) nsILocalFile *localFile = nsnull; if (aPath && strlen(aPath) > 0) { - NS_NewLocalFile(aPath, &localFile); + NS_NewLocalFile(aPath, PR_FALSE, &localFile); } nsresult rv = NS_InitEmbedding(localFile); @@ -170,7 +170,6 @@ nsresult NS_InitEmbedding(nsILocalFile *aPath) } - nsresult NS_TermEmbedding() { // Reentrant calls to this method do nothing except decrement a counter diff --git a/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp b/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp index c62e9a184e1..3f9b2514272 100644 --- a/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp +++ b/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp @@ -53,16 +53,13 @@ NS_IMETHODIMP nsXPCToolsCompiler::GetBinDir(nsILocalFile * *aBinDir) { *aBinDir = nsnull; - nsCOMPtr dir = do_CreateInstance(NS_LOCAL_FILE_PROGID); - if(!dir) - return NS_ERROR_FAILURE; - - nsresult rv = dir->InitWithPath( - nsSpecialSystemDirectory( - nsSpecialSystemDirectory::OS_CurrentProcessDirectory)); + nsCOMPtr file; + nsresult rv = NS_GetSpecialDirectory("xpcom.currentProcessDirectory", getter_AddRefs(file)); if(NS_FAILED(rv)) return rv; - NS_ADDREF(*aBinDir = dir); + + nsCOMPtr lfile = do_QueryInterface(file); + NS_ADDREF(*aBinDir = lfile); return NS_OK; } diff --git a/layout/html/forms/src/nsFormFrame.cpp b/layout/html/forms/src/nsFormFrame.cpp index e53065db307..1ea82b52763 100644 --- a/layout/html/forms/src/nsFormFrame.cpp +++ b/layout/html/forms/src/nsFormFrame.cpp @@ -1312,7 +1312,7 @@ nsresult nsFormFrame::ProcessAsMultipart(nsIFormProcessor* aFormProcessor,nsIFil // on the Mac as it expects a Unix style path. Instead we'll use our // spiffy new nsILocalFile nsILocalFile* tempFile = nsnull; - rv = NS_NewLocalFile(value, &tempFile); + rv = NS_NewLocalFile(value, PR_TRUE, &tempFile); NS_ASSERTION(tempFile, "Couldn't create nsIFileSpec to get file size!"); if (NS_FAILED(rv) || !tempFile) break; // NS_ERROR_OUT_OF_MEMORY diff --git a/netwerk/base/src/nsStdURL.cpp b/netwerk/base/src/nsStdURL.cpp index 21b21bf2eb6..9c7fef61fac 100644 --- a/netwerk/base/src/nsStdURL.cpp +++ b/netwerk/base/src/nsStdURL.cpp @@ -1004,7 +1004,7 @@ nsStdURL::GetFile(nsIFile * *aFile) path.Cut(0, 1); #endif nsCOMPtr localFile; - rv = NS_NewLocalFile(path, getter_AddRefs(localFile)); + rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(localFile)); mFile = localFile; *aFile = mFile; diff --git a/netwerk/cache/filecache/nsDiskCacheRecord.cpp b/netwerk/cache/filecache/nsDiskCacheRecord.cpp index e26f456ca5f..21d88e3a1cd 100644 --- a/netwerk/cache/filecache/nsDiskCacheRecord.cpp +++ b/netwerk/cache/filecache/nsDiskCacheRecord.cpp @@ -463,7 +463,7 @@ nsDiskCacheRecord::RetrieveInfo(void* aInfo, PRUint32 aInfoLength) // create mFile if Init() isn't called if(!mFile.get() ) { nsCOMPtr< nsILocalFile> file; - NS_NewLocalFile( file_url ,getter_AddRefs(file)); + NS_NewLocalFile( file_url, PR_FALSE ,getter_AddRefs(file)); mFile = file; if(!mFile.get()) diff --git a/netwerk/cache/filecache/nsNetDiskCache.cpp b/netwerk/cache/filecache/nsNetDiskCache.cpp index feba66d5f17..6714695c6d9 100644 --- a/netwerk/cache/filecache/nsNetDiskCache.cpp +++ b/netwerk/cache/filecache/nsNetDiskCache.cpp @@ -96,7 +96,7 @@ static int PR_CALLBACK folderChanged(const char *pref, void *closure) if ( NS_FAILED ( rv ) ) return rv; - rv = NS_NewLocalFile( path, getter_AddRefs(cacheFolder)); + rv = NS_NewLocalFile( path, PR_FALSE, getter_AddRefs(cacheFolder)); nsMemory::Free( path ); return ( (nsNetDiskCache*)closure )->SetDiskCacheFolder( cacheFolder ); diff --git a/netwerk/protocol/file/src/nsFileChannel.cpp b/netwerk/protocol/file/src/nsFileChannel.cpp index 1e80ab5acfe..93c864d638f 100644 --- a/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/netwerk/protocol/file/src/nsFileChannel.cpp @@ -76,6 +76,10 @@ nsFileChannel::Init(PRInt32 ioFlags, rv = fileURL->GetFile(getter_AddRefs(mFile)); if (NS_FAILED(rv)) return rv; + nsCOMPtr localFile = do_QueryInterface(mFile); + if (localFile) + localFile->SetFollowLinks(PR_TRUE); + return rv; } diff --git a/netwerk/protocol/http/src/nsHTTPHandler.cpp b/netwerk/protocol/http/src/nsHTTPHandler.cpp index 56dfcf47406..4dec1a1baad 100644 --- a/netwerk/protocol/http/src/nsHTTPHandler.cpp +++ b/netwerk/protocol/http/src/nsHTTPHandler.cpp @@ -315,7 +315,7 @@ nsHTTPHandler::NewPostDataStream(PRBool isFile, nsresult rv; if (isFile) { nsCOMPtr file; - rv = NS_NewLocalFile(data, getter_AddRefs(file)); + rv = NS_NewLocalFile(data, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; nsCOMPtr in; diff --git a/netwerk/test/TestFileInput.cpp b/netwerk/test/TestFileInput.cpp index 9a7fdc9616f..43cc7480684 100644 --- a/netwerk/test/TestFileInput.cpp +++ b/netwerk/test/TestFileInput.cpp @@ -211,7 +211,7 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) rv = reader->OnStartRequest(nsnull, nsnull); if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer? - rv = NS_NewLocalFile(path, getter_AddRefs(file)); + rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) goto done; rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStr), file); @@ -326,7 +326,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) PRDirEntry* entry; while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH)) != nsnull) { nsCOMPtr file; - rv = NS_NewLocalFile(dirName, getter_AddRefs(file)); + rv = NS_NewLocalFile(dirName, PR_FALSE, getter_AddRefs(file)); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewLocalFile failed"); rv = file->Append(entry->name); diff --git a/netwerk/test/TestFileInput2.cpp b/netwerk/test/TestFileInput2.cpp index 7dd79732d5d..cad66aa679d 100644 --- a/netwerk/test/TestFileInput2.cpp +++ b/netwerk/test/TestFileInput2.cpp @@ -449,11 +449,11 @@ main(int argc, char* argv[]) if (NS_FAILED(rv)) return rv; nsCOMPtr inDirFile; - rv = NS_NewLocalFile(inDir, getter_AddRefs(inDirFile)); + rv = NS_NewLocalFile(inDir, PR_FALSE, getter_AddRefs(inDirFile)); if (NS_FAILED(rv)) return rv; nsCOMPtr outDirFile; - rv = NS_NewLocalFile(outDir, getter_AddRefs(outDirFile)); + rv = NS_NewLocalFile(outDir, PR_FALSE, getter_AddRefs(outDirFile)); if (NS_FAILED(rv)) return rv; CreateFun create = FileChannelWorker::Create; diff --git a/netwerk/test/TestFileTransport.cpp b/netwerk/test/TestFileTransport.cpp index 3cf80e6332c..cbbc41cd73b 100644 --- a/netwerk/test/TestFileTransport.cpp +++ b/netwerk/test/TestFileTransport.cpp @@ -87,7 +87,7 @@ public: nsresult Init(const char* origFile) { nsresult rv; nsCOMPtr file; - rv = NS_NewLocalFile(origFile, getter_AddRefs(file)); + rv = NS_NewLocalFile(origFile, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; char* name; rv = file->GetLeafName(&name); @@ -129,7 +129,7 @@ TestAsyncRead(const char* fileName, PRUint32 offset, PRInt32 length) nsIChannel* fileTrans; nsCOMPtr file; - rv = NS_NewLocalFile(fileName, getter_AddRefs(file)); + rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = fts->CreateTransport(file, PR_RDONLY, 0, &fileTrans); if (NS_FAILED(rv)) return rv; @@ -176,7 +176,7 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) outFile.Append(".out"); nsIChannel* fileTrans; nsCOMPtr file; - rv = NS_NewLocalFile(outFile, getter_AddRefs(file)); + rv = NS_NewLocalFile(outFile, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = fts->CreateTransport(file, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, @@ -191,7 +191,7 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) if (NS_FAILED(rv)) return rv; nsCOMPtr f; - rv = NS_NewLocalFile(fileName, getter_AddRefs(f)); + rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(f)); if (NS_FAILED(rv)) return rv; nsCOMPtr inStr; rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), f); diff --git a/netwerk/test/TestWriteStream.cpp b/netwerk/test/TestWriteStream.cpp index fa632680e54..4b57b0b0a70 100644 --- a/netwerk/test/TestWriteStream.cpp +++ b/netwerk/test/TestWriteStream.cpp @@ -112,7 +112,7 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length) if (NS_FAILED(rv)) return rv ; nsCOMPtr fs; - rv = NS_NewLocalFile(filename, getter_AddRefs(fs)); + rv = NS_NewLocalFile(filename, PR_FALSE, getter_AddRefs(fs)); if (NS_FAILED(rv)) return rv ; nsCOMPtr transport; diff --git a/widget/src/gtk/nsAppShell.cpp b/widget/src/gtk/nsAppShell.cpp index 716dd544f63..9d02dc11a08 100644 --- a/widget/src/gtk/nsAppShell.cpp +++ b/widget/src/gtk/nsAppShell.cpp @@ -155,7 +155,8 @@ static void event_processor_callback(gpointer data, { nsIEventQueue *eventQueue = (nsIEventQueue*)data; if (eventQueue) - eventQueue->ProcessPendingEvents(); + eventQueue->ProcessPendingEvents(); + } #define PREF_NCOLS "browser.ncols" diff --git a/widget/src/mac/nsDragService.cpp b/widget/src/mac/nsDragService.cpp index dd4bbe732b4..a694b65a6e0 100644 --- a/widget/src/mac/nsDragService.cpp +++ b/widget/src/mac/nsDragService.cpp @@ -468,7 +468,7 @@ printf("looking for data in type %s, mac flavor %ld\n", NS_STATIC_CAST(const cha HFSFlavor* fileData = NS_REINTERPRET_CAST(HFSFlavor*, dataBuff); NS_ASSERTION ( sizeof(HFSFlavor) == dataSize, "Ooops, we realy don't have a HFSFlavor" ); nsCOMPtr file; - if ( NS_SUCCEEDED(NS_NewLocalFileWithFSSpec(&fileData->fileSpec, getter_AddRefs(file))) ) + if ( NS_SUCCEEDED(NS_NewLocalFileWithFSSpec(&fileData->fileSpec, PR_TRUE, getter_AddRefs(file))) ) genericDataWrapper = do_QueryInterface(file); } else { diff --git a/widget/src/windows/nsClipboard.cpp b/widget/src/windows/nsClipboard.cpp index 2dc9495c9c7..7a5c697f486 100644 --- a/widget/src/windows/nsClipboard.cpp +++ b/widget/src/windows/nsClipboard.cpp @@ -624,7 +624,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject, // we have a file path in |data|. Create an nsLocalFile object. char* filepath = NS_REINTERPRET_CAST(char*, data); nsCOMPtr file; - if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, getter_AddRefs(file))) ) + if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) ) genericDataWrapper = do_QueryInterface(file); } else { diff --git a/xpcom/build/dlldeps.cpp b/xpcom/build/dlldeps.cpp index 25452e7a769..34b6247cb3e 100644 --- a/xpcom/build/dlldeps.cpp +++ b/xpcom/build/dlldeps.cpp @@ -134,6 +134,6 @@ void XXXNeverCalled() nsString foo; nsLinebreakConverter::ConvertStringLineBreaks(foo, nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent); - NS_NewLocalFile(NULL, NULL); + NS_NewLocalFile(NULL, PR_FALSE, NULL); NS_NewByteArrayInputStream (NULL, NULL, 0); } diff --git a/xpcom/io/nsFileSpec.cpp b/xpcom/io/nsFileSpec.cpp index 7865dd5f209..0ea6aebf816 100644 --- a/xpcom/io/nsFileSpec.cpp +++ b/xpcom/io/nsFileSpec.cpp @@ -1443,3 +1443,4 @@ NS_FileSpecToIFile(nsFileSpec* fileSpec, nsILocalFile* *result) + diff --git a/xpcom/io/nsILocalFile.idl b/xpcom/io/nsILocalFile.idl index c0dc6026d71..51a141d5499 100644 --- a/xpcom/io/nsILocalFile.idl +++ b/xpcom/io/nsILocalFile.idl @@ -57,7 +57,24 @@ interface nsILocalFile : nsIFile */ void initWithPath([const] in string filePath); void initWithUnicodePath([const] in wstring filePath); - + + /** + * followLinks + * + * This attribute will determine if the nsLocalFile will auto + * resolve symbolic links. By default, this value will be false + * on all non unix systems. On unix, this attribute is effectively + * a noop. + * + * Be aware that changing this attribute from true to false after + * the nsILocalFile has been initialized may lead to errors. This + * could happen if there were resolved symlink in the initialized + * path. For example if you had /a/b/c where |b| was a symlink, + * and you change this attribute to false, the next usage would + * mostlikely fail. + */ + attribute PRBool followLinks; + [noscript] PRFileDescStar openNSPRFileDesc(in long flags, in long mode); [noscript] FILE openANSIFileDesc(in string mode); @@ -84,9 +101,9 @@ interface nsILocalFile : nsIFile #define NS_LOCAL_FILE_CLASSNAME "Local File Specification" extern "C" NS_EXPORT nsresult -NS_NewLocalFile(const char* path, nsILocalFile* *result); +NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result); extern "C" NS_EXPORT nsresult -NS_NewUnicodeLocalFile(const PRUnichar* path, nsILocalFile* *result); +NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result); %} diff --git a/xpcom/io/nsILocalFileMac.h b/xpcom/io/nsILocalFileMac.h index 96b31b8aa3b..32f3d442e61 100644 --- a/xpcom/io/nsILocalFileMac.h +++ b/xpcom/io/nsILocalFileMac.h @@ -100,6 +100,6 @@ public: extern "C" NS_EXPORT nsresult -NS_NewLocalFileWithFSSpec(FSSpec* inSpec, nsILocalFileMac* *result); +NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followSymlinks, nsILocalFileMac* *result); #endif diff --git a/xpcom/io/nsLocalFileCommon.cpp b/xpcom/io/nsLocalFileCommon.cpp index 3a3525c9773..7ed52879aff 100644 --- a/xpcom/io/nsLocalFileCommon.cpp +++ b/xpcom/io/nsLocalFileCommon.cpp @@ -29,8 +29,7 @@ #include "nsIUnicodeDecoder.h" #endif /* XPCOM_STANDALONE */ -/* nsFileSpec stuff. put here untill it got obsoleted */ -#include "nsFileSpec.h" +#include "nsFileSpec.h" // evil ftang hack #ifdef XP_PC #ifdef XP_OS2 @@ -111,12 +110,12 @@ private: } \ return res; \ } -#define SET_UCS_2ARGS_1( func , arg1, arg2) \ +#define SET_UCS_2ARGS_1( func , path, followLinks, result) \ { \ char* tmp; \ nsresult res; \ - if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((arg1), &tmp))){ \ - res = (func)(tmp, arg2); \ + if(NS_SUCCEEDED(res = gConverter.UCSToNewFS((path), &tmp))){ \ + res = (func)(tmp, followLinks, result); \ nsMemory::Free(tmp); \ } \ return res; \ @@ -305,10 +304,78 @@ nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) GET_UCS(GetTarget, _retval); } nsresult -NS_NewUnicodeLocalFile(const PRUnichar* path, nsILocalFile* *result) +NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result) { - SET_UCS_2ARGS_1( NS_NewLocalFile , path, result) + SET_UCS_2ARGS_1( NS_NewLocalFile, path, followLinks, result) } +// should work on Macintosh, Unix, and Win32. +#define kMaxFilenameLength 31 + + +NS_IMETHODIMP +nsLocalFile::CreateUnique(const char* suggestedName, PRUint32 type, PRUint32 attributes) +{ + nsresult rv = Create(type, attributes); + + if (NS_SUCCEEDED(rv)) return NS_OK; + if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; + + char* leafName; + rv = GetLeafName(&leafName); + + if (NS_FAILED(rv)) return rv; + + char* lastDot = strrchr(leafName, '.'); + char suffix[kMaxFilenameLength + 1] = ""; + if (lastDot) + { + strncpy(suffix, lastDot, kMaxFilenameLength); // include '.' + suffix[kMaxFilenameLength] = 0; // make sure it's null terminated + *lastDot = '\0'; // strip suffix and dot. + } + + // 27 should work on Macintosh, Unix, and Win32. + const int maxRootLength = 27 - nsCRT::strlen(suffix) - 1; + + if ((int)nsCRT::strlen(leafName) > (int)maxRootLength) + leafName[maxRootLength] = '\0'; + + for (short indx = 1; indx < 10000; indx++) + { + // start with "Picture-1.jpg" after "Picture.jpg" exists + char newName[kMaxFilenameLength + 1]; + sprintf(newName, "%s-%d%s", leafName, indx, suffix); + SetLeafName(newName); + + rv = Create(type, attributes); + + if (NS_SUCCEEDED(rv) || rv != NS_ERROR_FILE_ALREADY_EXISTS) + { + nsMemory::Free(leafName); + return rv; + } + } + + nsMemory::Free(leafName); + // The disk is full, sort of + return NS_ERROR_FILE_TOO_BIG; +} + + + + + + + + + + + +// E_V_I_L Below! E_V_I_L Below! E_V_I_L Below! E_V_I_L Below! + + +// FTANG need to move this crap out of here. Mixing nsFileSpec here is +// E_V_I_L // ================================================================== // nsFileSpec stuff . put here untill nsFileSpec get obsoleted @@ -366,58 +433,3 @@ nsresult nsFileSpec::Execute(const nsString& args) const { SET_UCS( Execute , args.GetUnicode()); } - -// should work on Macintosh, Unix, and Win32. -#define kMaxFilenameLength 31 - - -NS_IMETHODIMP -nsLocalFile::CreateUnique(const char* suggestedName, PRUint32 type, PRUint32 attributes) -{ - nsresult rv = Create(type, attributes); - - if (NS_SUCCEEDED(rv)) return NS_OK; - if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; - - char* leafName; - rv = GetLeafName(&leafName); - - if (NS_FAILED(rv)) return rv; - - char* lastDot = strrchr(leafName, '.'); - char suffix[kMaxFilenameLength + 1] = ""; - if (lastDot) - { - strncpy(suffix, lastDot, kMaxFilenameLength); // include '.' - suffix[kMaxFilenameLength] = 0; // make sure it's null terminated - *lastDot = '\0'; // strip suffix and dot. - } - - // 27 should work on Macintosh, Unix, and Win32. - const int maxRootLength = 27 - nsCRT::strlen(suffix) - 1; - - if ((int)nsCRT::strlen(leafName) > (int)maxRootLength) - leafName[maxRootLength] = '\0'; - - for (short indx = 1; indx < 10000; indx++) - { - // start with "Picture-1.jpg" after "Picture.jpg" exists - char newName[kMaxFilenameLength + 1]; - sprintf(newName, "%s-%d%s", leafName, indx, suffix); - SetLeafName(newName); - - rv = Create(type, attributes); - - if (NS_SUCCEEDED(rv) || rv != NS_ERROR_FILE_ALREADY_EXISTS) - { - nsMemory::Free(leafName); - return rv; - } - } - - nsMemory::Free(leafName); - // The disk is full, sort of - return NS_ERROR_FILE_TOO_BIG; -} - - diff --git a/xpcom/io/nsLocalFileMac.cpp b/xpcom/io/nsLocalFileMac.cpp index bd45c4fcd07..25cbbb88b2f 100644 --- a/xpcom/io/nsLocalFileMac.cpp +++ b/xpcom/io/nsLocalFileMac.cpp @@ -707,7 +707,7 @@ class nsDirEnumerator : public nsISimpleEnumerator // Make a new nsILocalFile for the new element nsCOMPtr file; - rv = NS_NewLocalFile("dummy:path", getter_AddRefs(file)); + rv = NS_NewLocalFile("dummy:path", PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; @@ -768,6 +768,7 @@ nsLocalFile::nsLocalFile() : mInitType(eNotInitialized) , mLastResolveFlag(PR_FALSE) , mHaveFileInfo(PR_FALSE) +, mFollowSymlinks(PR_FALSE) , mType('????') , mCreator('MOSS') { @@ -820,6 +821,21 @@ nsLocalFile::MakeDirty() } +/* attribute PRBool followLinks; */ +NS_IMETHODIMP +nsLocalFile::GetFollowLinks(PRBool *aFollowLinks) +{ + *aFollowLinks = mFollowSymlinks; + return NS_OK; +} +NS_IMETHODIMP +nsLocalFile::SetFollowLinks(PRBool aFollowLinks) +{ + MakeDirty(); + mFollowSymlinks = aFollowLinks; + return NS_OK; +} + NS_IMETHODIMP nsLocalFile::ResolveAndStat(PRBool resolveTerminal) { @@ -1698,7 +1714,7 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentPath.Truncate(offset); nsCOMPtr localFile; - rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile)); + rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv) && localFile) { rv = localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent); @@ -1739,7 +1755,7 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentFolderSpec.parID = pBlock.dirInfo.ioDrParID; nsCOMPtr file; - rv = NS_NewLocalFile("dummy:path", getter_AddRefs(file)); + rv = NS_NewLocalFile("dummy:path", mFollowSymlinks, getter_AddRefs(file)); if (NS_FAILED(rv)) goto bail; @@ -2047,7 +2063,6 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) return NS_OK; } - #pragma mark - // a stack-based, exception safe class for an AEDesc @@ -2625,13 +2640,15 @@ nsLocalFile::OpenDocWithApp(nsILocalFile* aAppToOpenWith, PRBool aLaunchInBackgr // Handy dandy utility create routine for something or the other nsresult -NS_NewLocalFile(const char* path, nsILocalFile* *result) +NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(file); + file->SetFollowLinks(followLinks); + nsresult rv = file->InitWithPath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); @@ -2642,13 +2659,15 @@ NS_NewLocalFile(const char* path, nsILocalFile* *result) } nsresult -NS_NewLocalFileWithFSSpec(FSSpec* inSpec, nsILocalFileMac* *result) +NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followLinks, nsILocalFileMac* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(file); + file->SetFollowLinks(followLinks); + nsresult rv = file->InitWithFSSpec(inSpec); if (NS_FAILED(rv)) { NS_RELEASE(file); diff --git a/xpcom/io/nsLocalFileMac.h b/xpcom/io/nsLocalFileMac.h index 11f3cc14dd1..5b11f31b2d4 100644 --- a/xpcom/io/nsLocalFileMac.h +++ b/xpcom/io/nsLocalFileMac.h @@ -96,10 +96,12 @@ private: // It's important we keep track of how we were initialized nsLocalFileMacInitType mInitType; - + // this is the flag which indicates if I can used cached information about the file - PRPackedBool mStatDirty; + PRPackedBool mStatDirty; PRPackedBool mLastResolveFlag; + + PRPackedBool mFollowSymlinks; // Is the mResolvedSpec member valid? Only after we resolve the mSpec or mWorkingPath // PRPackedBool mHaveValidSpec; diff --git a/xpcom/io/nsLocalFileOS2.cpp b/xpcom/io/nsLocalFileOS2.cpp index 9b4a4ddf427..49182532f34 100644 --- a/xpcom/io/nsLocalFileOS2.cpp +++ b/xpcom/io/nsLocalFileOS2.cpp @@ -263,6 +263,7 @@ nsLocalFile::nsLocalFile() mPersistFile = nsnull; mShellLink = nsnull; #endif + mFollowSymlinks = PR_FALSE; mLastResolution = PR_FALSE; MakeDirty(); } @@ -566,6 +567,8 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) return(NS_ERROR_FILE_NOT_FOUND); } #else + if (!mFollowSymlinks) + return NS_ERROR_FILE_NOT_FOUND; // if we are not resolving, we just give up here. nsresult result; @@ -610,7 +613,7 @@ nsLocalFile::Clone(nsIFile **file) nsCOMPtr localFile; - rv = NS_NewLocalFile(aFilePath, getter_AddRefs(localFile)); + rv = NS_NewLocalFile(aFilePath, mFollowSymlinks, getter_AddRefs(localFile)); nsMemory::Free(aFilePath); if (NS_SUCCEEDED(rv) && localFile) @@ -1683,7 +1686,7 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentPath.Truncate(offset); nsCOMPtr localFile; - nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile)); + nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile)); if(NS_SUCCEEDED(rv) && localFile) { @@ -2027,6 +2030,21 @@ nsLocalFile::GetTarget(char **_retval) } +/* attribute PRBool followLinks; */ +NS_IMETHODIMP +nsLocalFile::GetFollowLinks(PRBool *aFollowLinks) +{ + *aFollowLinks = mFollowSymlinks; + return NS_OK; +} +NS_IMETHODIMP +nsLocalFile::SetFollowLinks(PRBool aFollowLinks) +{ + MakeDirty(); + mFollowSymlinks = aFollowLinks; + return NS_OK; +} + NS_IMETHODIMP nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) { @@ -2056,15 +2074,29 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) return NS_OK; } +/* attribute PRBool followLinks; */ +NS_IMETHODIMP +nsLocalFile::GetFollowLinks(PRBool *aFollowLinks) +{ + *aFollowLinks = PR_TRUE; + return NS_OK; +} +NS_IMETHODIMP +nsLocalFile::SetFollowLinks(PRBool aFollowLinks) +{ + return NS_OK; +} nsresult -NS_NewLocalFile(const char* path, nsILocalFile* *result) +NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(file); + file->SetFollowLinks(followLinks); + nsresult rv = file->InitWithPath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); diff --git a/xpcom/io/nsLocalFileOS2.h b/xpcom/io/nsLocalFileOS2.h index fb6ea0f0439..f42715d8bbe 100644 --- a/xpcom/io/nsLocalFileOS2.h +++ b/xpcom/io/nsLocalFileOS2.h @@ -109,8 +109,9 @@ public: private: // this is the flag which indicates if I can used cached information about the file - PRBool mDirty; - PRBool mLastResolution; + PRPackedBool mDirty; + PRPackedBool mLastResolution; + PRPackedBool mFollowSymlinks; // this string will alway be in native format! nsCString mWorkingPath; diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index 95bea30a812..4db471c4a45 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -1065,7 +1065,7 @@ nsLocalFile::GetParent(nsIFile **aParent) parentPath.Truncate(offset); nsCOMPtr localFile; - nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile)); + nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile)); if(NS_SUCCEEDED(rv) && localFile) { @@ -1286,6 +1286,20 @@ nsLocalFile::Spawn(const char **args, PRUint32 count) return NS_ERROR_FILE_EXECUTION_FAILED; } + +/* attribute PRBool followLinks; */ +NS_IMETHODIMP +nsLocalFile::GetFollowLinks(PRBool *aFollowLinks) +{ + *aFollowLinks = PR_TRUE; + return NS_OK; +} +NS_IMETHODIMP +nsLocalFile::SetFollowLinks(PRBool aFollowLinks) +{ + return NS_OK; +} + NS_IMETHODIMP nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator **entries) { @@ -1315,7 +1329,7 @@ nsLocalFile::Load(PRLibrary **_retval) } nsresult -NS_NewLocalFile(const char* path, nsILocalFile* *result) +NS_NewLocalFile(const char* path, PRBool followSymlinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index 3f9b2eb6d45..ca77c3e7132 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -243,6 +243,7 @@ nsLocalFile::nsLocalFile() mPersistFile = nsnull; mShellLink = nsnull; mLastResolution = PR_FALSE; + mFollowSymlinks = PR_FALSE; MakeDirty(); } @@ -291,7 +292,7 @@ nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* void nsLocalFile::MakeDirty() { - mDirty = PR_TRUE; + mDirty = PR_TRUE; } @@ -307,6 +308,10 @@ nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char** { nsresult rv = NS_OK; + + if (strstr(workingPath, ".lnk") == nsnull) + return NS_ERROR_FILE_INVALID_PATH; + if (mPersistFile == nsnull || mShellLink == nsnull) { CoInitialize(NULL); // FIX: we should probably move somewhere higher up during startup @@ -507,6 +512,7 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) return NS_OK; } mLastResolution = resolveTerminal; + mResolvedPath.Assign(mWorkingPath); //until we know better. // First we will see if the workingPath exists. If it does, then we // can simply use that as the resolved path. This simplification can @@ -528,11 +534,27 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) PRStatus status = PR_GetFileInfo64(nsprPath, &mFileInfo64); if ( status == PR_SUCCESS ) { - mResolvedPath.Assign(workingFilePath); - mDirty = PR_FALSE; - return NS_OK; + if (!resolveTerminal) + { + mDirty = PR_FALSE; + return NS_OK; + } + + // check to see that this is shortcut. + + int pathLen = strlen(workingFilePath); + const char* leaf = workingFilePath + pathLen - 4; + + if ( (strcmp(leaf, ".lnk") != 0)) + { + mDirty = PR_FALSE; + return NS_OK; + } } + if (!mFollowSymlinks) + return NS_ERROR_FILE_NOT_FOUND; // if we are not resolving, we just give up here. + nsresult result; // okay, something is wrong with the working path. We will try to resolve it. @@ -541,22 +563,12 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) result = ResolvePath(workingFilePath, resolveTerminal, &resolvePath); if (NS_FAILED(result)) - return result; + return NS_ERROR_FILE_NOT_FOUND; mResolvedPath.Assign(resolvePath); nsMemory::Free(resolvePath); - // if we are not resolving the terminal node, we have to "fake" windows - // out and append the ".lnk" file extension before getting any information - // about the shortcut. If resoveTerminal was TRUE, than it the shortcut was - // resolved by the call to ResolvePath above. - - - char linkStr[MAX_PATH]; - strcpy(linkStr, mResolvedPath.GetBuffer()); - strcat(linkStr, ".lnk"); - - status = PR_GetFileInfo64(linkStr, &mFileInfo64); + status = PR_GetFileInfo64(mResolvedPath, &mFileInfo64); if ( status == PR_SUCCESS ) mDirty = PR_FALSE; @@ -575,7 +587,7 @@ nsLocalFile::Clone(nsIFile **file) nsCOMPtr localFile; - rv = NS_NewLocalFile(aFilePath, getter_AddRefs(localFile)); + rv = NS_NewLocalFile(aFilePath, mFollowSymlinks, getter_AddRefs(localFile)); nsMemory::Free(aFilePath); if (NS_SUCCEEDED(rv) && localFile) @@ -625,6 +637,7 @@ nsLocalFile::InitWithPath(const char *filePath) mWorkingPath.Assign(nativeFilePath); nsMemory::Free( nativeFilePath ); + return NS_OK; } @@ -1505,7 +1518,7 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentPath.Truncate(offset); nsCOMPtr localFile; - nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), getter_AddRefs(localFile)); + nsresult rv = NS_NewLocalFile(parentPath.GetBuffer(), mFollowSymlinks, getter_AddRefs(localFile)); if(NS_SUCCEEDED(rv) && localFile) { @@ -1777,6 +1790,22 @@ nsLocalFile::GetTarget(char **_retval) } +/* attribute PRBool followLinks; */ +NS_IMETHODIMP +nsLocalFile::GetFollowLinks(PRBool *aFollowLinks) +{ + *aFollowLinks = mFollowSymlinks; + return NS_OK; +} +NS_IMETHODIMP +nsLocalFile::SetFollowLinks(PRBool aFollowLinks) +{ + MakeDirty(); + mFollowSymlinks = aFollowLinks; + return NS_OK; +} + + NS_IMETHODIMP nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) { @@ -1808,18 +1837,21 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) nsresult -NS_NewLocalFile(const char* path, nsILocalFile* *result) +NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(file); + file->SetFollowLinks(followLinks); + nsresult rv = file->InitWithPath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); return rv; } + *result = file; return NS_OK; } diff --git a/xpcom/io/nsLocalFileWin.h b/xpcom/io/nsLocalFileWin.h index e9b90771766..b005a0717a6 100644 --- a/xpcom/io/nsLocalFileWin.h +++ b/xpcom/io/nsLocalFileWin.h @@ -68,9 +68,11 @@ public: private: // this is the flag which indicates if I can used cached information about the file - PRBool mDirty; - PRBool mLastResolution; - + PRPackedBool mDirty; + PRPackedBool mLastResolution; + + PRPackedBool mFollowSymlinks; + // this string will alway be in native format! nsCString mWorkingPath; diff --git a/xpcom/tests/makefile.win b/xpcom/tests/makefile.win index a182e242e24..3cf74670774 100644 --- a/xpcom/tests/makefile.win +++ b/xpcom/tests/makefile.win @@ -44,6 +44,7 @@ PROG16 = .\$(OBJDIR)\TestPipes.exe PROG17 = .\$(OBJDIR)\TestShutdown.exe PROG18 = .\$(OBJDIR)\TestStackCrawl.exe PROG19 = .\$(OBJDIR)\TestVoidBTree.exe +PROG20 = .\$(OBJDIR)\nsIFileEnumerator.exe RESFILE = timer.res @@ -64,6 +65,7 @@ PROGRAMS = $(PROG1) \ $(PROG17) \ $(PROG18) \ $(PROG19) \ + $(PROG20) \ $(NULL) LCFLAGS=-DUSE_NSREG -GX @@ -106,4 +108,6 @@ $(PROG16): $(OBJDIR) TestPipes.cpp $(PROG17): $(OBJDIR) TestShutdown.cpp $(PROG18): $(OBJDIR) TestStackCrawl.cpp $(PROG19): $(OBJDIR) TestVoidBTree.cpp +$(PROG20): $(OBJDIR) nsIFileEnumerator.cpp + diff --git a/xpfe/components/xfer/src/nsStreamTransfer.cpp b/xpfe/components/xfer/src/nsStreamTransfer.cpp index 3b70c970c82..8021a3d92e3 100644 --- a/xpfe/components/xfer/src/nsStreamTransfer.cpp +++ b/xpfe/components/xfer/src/nsStreamTransfer.cpp @@ -221,7 +221,7 @@ nsStreamTransfer::SelectFile( nsIDOMWindow *parent, nsIFileSpec **aResult, const nsXPIDLCString nativeStartDir; startDir->GetNativePath( getter_Copies( nativeStartDir ) ); nsCOMPtr startLocalFile; - if ( NS_SUCCEEDED( NS_NewLocalFile( nativeStartDir, getter_AddRefs( startLocalFile ) ) ) ) { + if ( NS_SUCCEEDED( NS_NewLocalFile( nativeStartDir, PR_FALSE, getter_AddRefs( startLocalFile ) ) ) ) { #ifdef DEBUG_law printf( "\nSetting display directory to %s\n\n", (const char*)nativeStartDir ); #endif @@ -310,7 +310,7 @@ nsCString nsStreamTransfer::SuggestNameFor( nsIChannel *aChannel, char const *su // this suggested name comes from a http response header and could // try to overwrite c:\config.sys or something. nsCOMPtr localFile; - if ( NS_SUCCEEDED( NS_NewLocalFile( result, getter_AddRefs( localFile ) ) ) ) { + if ( NS_SUCCEEDED( NS_NewLocalFile( result, PR_FALSE, getter_AddRefs( localFile ) ) ) ) { // We want base part of name only. nsXPIDLCString baseName; if ( NS_SUCCEEDED( localFile->GetLeafName( getter_Copies( baseName ) ) ) ) { diff --git a/xpfe/components/xfer/src/nsStreamXferOp.cpp b/xpfe/components/xfer/src/nsStreamXferOp.cpp index 5388dc24232..2dcd703ae3a 100644 --- a/xpfe/components/xfer/src/nsStreamXferOp.cpp +++ b/xpfe/components/xfer/src/nsStreamXferOp.cpp @@ -167,7 +167,7 @@ nsStreamXferOp::Start( void ) { nsFileSpec target; // XXX eliminate mOutputSpec->GetFileSpec( &target ); nsCOMPtr file; - rv = NS_NewLocalFile(target, getter_AddRefs(file)); + rv = NS_NewLocalFile(target, PR_FALSE, getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) { rv = fts->CreateTransport(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664, getter_AddRefs( mOutputChannel)); diff --git a/xpinstall/src/ScheduledTasks.cpp b/xpinstall/src/ScheduledTasks.cpp index 2126885e0b2..04845054276 100644 --- a/xpinstall/src/ScheduledTasks.cpp +++ b/xpinstall/src/ScheduledTasks.cpp @@ -414,7 +414,7 @@ void DeleteScheduledFiles( HREG reg ) // no need to check return value of // SetPersistentDescriptorString, it's always NS_OK //spec->SetPersistentDescriptorString(valbuf); //nsIFileXXX: Do we still need this instead of InitWithPath? - NS_NewLocalFile((char*)valbuf, getter_AddRefs(spec)); + NS_NewLocalFile((char*)valbuf, PR_TRUE, getter_AddRefs(spec)); spec->Clone(getter_AddRefs(doomedFile)); if (NS_SUCCEEDED(rv)) { @@ -478,10 +478,10 @@ void ReplaceScheduledFiles( HREG reg ) if ( err1 == REGERR_OK && err2 == REGERR_OK ) { - rv1 = NS_NewLocalFile((char*)srcFile, getter_AddRefs(src)); + rv1 = NS_NewLocalFile((char*)srcFile, PR_TRUE, getter_AddRefs(src)); rv1 = src->Clone(getter_AddRefs(srcSpec)); - rv2 = NS_NewLocalFile((char*)doomedFile, getter_AddRefs(dest)); + rv2 = NS_NewLocalFile((char*)doomedFile, PR_TRUE, getter_AddRefs(dest)); rv2 = dest->Clone(getter_AddRefs(doomedSpec)); if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 93417dfcc6a..2e25574e9cc 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -726,7 +726,7 @@ nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn) } nsAutoCString temp(aFolder); nsCOMPtr folder; - NS_NewLocalFile(temp, getter_AddRefs(folder)); + NS_NewLocalFile(temp, PR_TRUE, getter_AddRefs(folder)); result = folder->GetDiskSpaceAvailable(aReturn); return NS_OK; @@ -2477,7 +2477,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, extractHereSpec->Delete(PR_FALSE); //nsCOMPtr file; - //rv = NS_NewLocalFile(*extractHereSpec, getter_AddRefs(file)); + //rv = NS_NewLocalFile(*extractHereSpec, PR_TRUE, getter_AddRefs(file)); //if (NS_SUCCEEDED(rv)) rv = mJarFileData->Extract(nsAutoCString(aJarfile), extractHereSpec); if (NS_FAILED(rv)) diff --git a/xpinstall/src/nsInstallDelete.cpp b/xpinstall/src/nsInstallDelete.cpp index 999b0a4c736..d847d760546 100644 --- a/xpinstall/src/nsInstallDelete.cpp +++ b/xpinstall/src/nsInstallDelete.cpp @@ -236,7 +236,7 @@ PRInt32 nsInstallDelete::ProcessInstallDelete() // delete mFinalFile; nsCOMPtr tempLocalFile; - NS_NewLocalFile(tempRegistryString, getter_AddRefs(tempLocalFile)); + NS_NewLocalFile(tempRegistryString, PR_TRUE, getter_AddRefs(tempLocalFile)); mFinalFile = tempLocalFile; if (mFinalFile == nsnull) diff --git a/xpinstall/src/nsInstallFolder.cpp b/xpinstall/src/nsInstallFolder.cpp index 82492cdc770..18d4d57d7f1 100644 --- a/xpinstall/src/nsInstallFolder.cpp +++ b/xpinstall/src/nsInstallFolder.cpp @@ -168,7 +168,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe // XXX the filespec creation will fail due to unix slashes on Mac nsAutoCString tempRelPath(aRelativePath); nsCOMPtr temp; - NS_NewLocalFile(tempRelPath, getter_AddRefs(temp)); + NS_NewLocalFile(tempRelPath, PR_TRUE, getter_AddRefs(temp)); mFileSpec = temp; // creates the directories to the relative path. return; } @@ -269,7 +269,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe { nsAutoCString tempRelPath(aRelativePath); nsCOMPtr temp; - NS_NewLocalFile(tempRelPath, getter_AddRefs(temp)); + NS_NewLocalFile(tempRelPath, PR_TRUE, getter_AddRefs(temp)); mFileSpec = temp; // file:// is a special case where it returns and does not diff --git a/xpinstall/src/nsInstallPatch.cpp b/xpinstall/src/nsInstallPatch.cpp index 61c2692adff..b3fc71375cd 100644 --- a/xpinstall/src/nsInstallPatch.cpp +++ b/xpinstall/src/nsInstallPatch.cpp @@ -93,7 +93,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, nsString folderSpec; folderSpec.AssignWithConversion(tempTargetFile); nsCOMPtr tmp; - NS_NewLocalFile((char*)tempTargetFile, getter_AddRefs(tmp)); + NS_NewLocalFile((char*)tempTargetFile, PR_TRUE, getter_AddRefs(tmp)); mPatchFile = nsnull; mTargetFile = nsnull; diff --git a/xpinstall/src/nsInstallUninstall.cpp b/xpinstall/src/nsInstallUninstall.cpp index 10a4a723f11..906bcf6db55 100644 --- a/xpinstall/src/nsInstallUninstall.cpp +++ b/xpinstall/src/nsInstallUninstall.cpp @@ -195,7 +195,7 @@ REGERR su_UninstallProcessItem(char *component_path) err = VR_GetPath(component_path, sizeof(filepath), filepath); if ( err == REGERR_OK ) { - NS_NewLocalFile((char*)filepath, getter_AddRefs(nsLFPath)); + NS_NewLocalFile((char*)filepath, PR_TRUE, getter_AddRefs(nsLFPath)); nsFPath = nsLFPath; err = VR_GetRefCount(component_path, &refcount); if ( err == REGERR_OK ) diff --git a/xpinstall/src/nsJSFile.cpp b/xpinstall/src/nsJSFile.cpp index e6c3c287882..de8bdea6a54 100644 --- a/xpinstall/src/nsJSFile.cpp +++ b/xpinstall/src/nsJSFile.cpp @@ -1028,15 +1028,15 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval ConvertJSValToStr(b0, cx, argv[0]); - NS_NewLocalFile(nsAutoCString(b0), getter_AddRefs(nsfsB0)); + NS_NewLocalFile(nsAutoCString(b0), PR_TRUE, getter_AddRefs(nsfsB0)); ConvertJSValToStr(b1, cx, argv[1]); - NS_NewLocalFile(nsAutoCString(b1), getter_AddRefs(nsfsB1)); + NS_NewLocalFile(nsAutoCString(b1), PR_TRUE, getter_AddRefs(nsfsB1)); ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); - NS_NewLocalFile(nsAutoCString(b3), getter_AddRefs(nsfsB3)); + NS_NewLocalFile(nsAutoCString(b3), PR_TRUE, getter_AddRefs(nsfsB3)); ConvertJSValToStr(b4, cx, argv[4]); ConvertJSValToStr(b5, cx, argv[5]); - NS_NewLocalFile(nsAutoCString(b5), getter_AddRefs(nsfsB5)); + NS_NewLocalFile(nsAutoCString(b5), PR_TRUE, getter_AddRefs(nsfsB5)); if(JSVAL_IS_NULL(argv[6])) { diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index 399f027a396..546db2a0d02 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -173,7 +173,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB nsIFile* jFile; nsresult rv =jarFile->Clone(&jFile); - //NS_NewLocalFile(jarFile, getter_AddRefs(jFile)); + //NS_NewLocalFile(jarFile, PR_TRUE, getter_AddRefs(jFile)); if (NS_SUCCEEDED(rv)) rv = hZip->Init(jFile); @@ -191,7 +191,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB // Extract the install.js file. nsCOMPtr iFile; - rv = NS_NewLocalFile(installJSFileSpec, getter_AddRefs(iFile)); + rv = NS_NewLocalFile(installJSFileSpec, PR_TRUE, getter_AddRefs(iFile)); if (NS_SUCCEEDED(rv)) rv = hZip->Extract("install.js", iFile); if ( NS_SUCCEEDED(rv) ) diff --git a/xpinstall/stub/xpistub.cpp b/xpinstall/stub/xpistub.cpp index 45f00e8621a..29b83416240 100644 --- a/xpinstall/stub/xpistub.cpp +++ b/xpinstall/stub/xpistub.cpp @@ -126,14 +126,14 @@ PR_PUBLIC_API(nsresult) XPI_Init( getcwd(componentPath, MAX_PATH); nsCOMPtr file; - NS_NewLocalFile(componentPath, getter_AddRefs(file)); + NS_NewLocalFile(componentPath, PR_TRUE, getter_AddRefs(file)); rv = NS_InitXPCOM(&gServiceMgr, file); #elif defined(XP_UNIX) nsCOMPtr file; - NS_NewLocalFile(aProgramDir, getter_AddRefs(file)); + NS_NewLocalFile(aProgramDir, PR_TRUE, getter_AddRefs(file)); rv = NS_InitXPCOM(&gServiceMgr, file); @@ -146,7 +146,7 @@ PR_PUBLIC_API(nsresult) XPI_Init( sprintf(compDirPath, "%s/components", cwd); nsCOMPtr compDir; - NS_NewLocalFile(compDirPath, getter_AddRefs(compDir)); + NS_NewLocalFile(compDirPath, PR_TRUE, getter_AddRefs(compDir)); #else @@ -193,10 +193,10 @@ PR_PUBLIC_API(nsresult) XPI_Init( #if XP_MAC nsCOMPtr iMacDirSpec; - NS_NewLocalFileWithFSSpec((FSSpec *)&aProgramDir, getter_AddRefs(iMacDirSpec)); + NS_NewLocalFileWithFSSpec((FSSpec *)&aProgramDir, PR_TRUE, getter_AddRefs(iMacDirSpec)); iDirSpec = do_QueryInterface(iMacDirSpec); #else - NS_NewLocalFile(aProgramDir, getter_AddRefs(iDirSpec)); + NS_NewLocalFile(aProgramDir, PR_TRUE, getter_AddRefs(iDirSpec)); #endif if (hook && iDirSpec) @@ -267,10 +267,10 @@ PR_PUBLIC_API(PRInt32) XPI_Install( #if XP_MAC nsCOMPtr iMacFile; - NS_NewLocalFileWithFSSpec((FSSpec *)&aFile, getter_AddRefs(iMacFile)); + NS_NewLocalFileWithFSSpec((FSSpec *)&aFile, PR_TRUE, getter_AddRefs(iMacFile)); iFile = do_QueryInterface(iMacFile); #else - NS_NewLocalFile(aFile, getter_AddRefs(iFile)); + NS_NewLocalFile(aFile, PR_TRUE, getter_AddRefs(iFile)); #endif if (iFile && gXPI)