diff --git a/xpcom/obsolete/nsFileSpec.cpp b/xpcom/obsolete/nsFileSpec.cpp index 68d6e5e8c1ab..9be29eb903bd 100644 --- a/xpcom/obsolete/nsFileSpec.cpp +++ b/xpcom/obsolete/nsFileSpec.cpp @@ -49,7 +49,6 @@ #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "nsILocalFile.h" -#include "nsIFileStream.h" #include #include @@ -910,11 +909,8 @@ void nsFileSpec::MakeUnique(const char* inSuggestedLeafName) void nsFileSpec::MakeUnique() //---------------------------------------------------------------------------------------- { - nsCOMPtr file; - nsresult rv = NS_NewIOFileStream(getter_AddRefs(file), *this, - PR_WRONLY | PR_CREATE_FILE | PR_EXCL | PR_TRUNCATE, 0600); - if (NS_SUCCEEDED(rv)) - return; // the stream will be closed automatically + if (!Exists()) + return; char* leafName = GetLeafName(); if (!leafName) @@ -931,16 +927,12 @@ void nsFileSpec::MakeUnique() = nsFileSpecHelpers::kMaxCoreLeafNameLength - strlen(suffix) - 1; if ((int)strlen(leafName) > (int)kMaxRootLength) leafName[kMaxRootLength] = '\0'; - for (short indx = 1; indx < 1000; indx++) + for (short indx = 1; indx < 1000 && Exists(); indx++) { // start with "Picture-1.jpg" after "Picture.jpg" exists char newName[nsFileSpecHelpers::kMaxFilenameLength + 1]; sprintf(newName, "%s-%d%s", leafName, indx, suffix); SetLeafName(newName); - rv = NS_NewIOFileStream(getter_AddRefs(file), *this, - PR_WRONLY | PR_CREATE_FILE | PR_EXCL | PR_TRUNCATE, 0600); - if (NS_SUCCEEDED(rv)) - break; } if (*suffix) nsCRT::free(suffix); diff --git a/xpcom/obsolete/nsFileSpec.h b/xpcom/obsolete/nsFileSpec.h index 6d86aac99a27..53fa6c1a18b9 100644 --- a/xpcom/obsolete/nsFileSpec.h +++ b/xpcom/obsolete/nsFileSpec.h @@ -460,6 +460,10 @@ class NS_COM_OBSOLETE nsFileSpec void operator += (const char* inRelativeUnixPath); + void MakeUnique(); + void MakeUnique(const char* inSuggestedLeafName); + + PRBool IsDirectory() const; // More stringent than Exists() PRBool IsFile() const; // More stringent than Exists() PRBool Exists() const; @@ -472,11 +476,6 @@ class NS_COM_OBSOLETE nsFileSpec // Creation and deletion of objects. These can modify the disk. //-------------------------------------------------- - // For security reasons, these create the file. - void MakeUnique(); - void MakeUnique(const char* inSuggestedLeafName); - - // Called for the spec of an alias. Modifies the spec to // point to the original. Sets mError. nsresult ResolveSymlink(PRBool& wasSymlink);