Backout 212123 fix because it's wrong. I suck.

This commit is contained in:
roc+%cs.cmu.edu 2005-03-10 21:18:28 +00:00
Родитель c6336e1354
Коммит e7b18ac560
2 изменённых файлов: 7 добавлений и 16 удалений

Просмотреть файл

@ -49,7 +49,6 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsILocalFile.h"
#include "nsIFileStream.h"
#include <string.h>
#include <stdio.h>
@ -910,11 +909,8 @@ void nsFileSpec::MakeUnique(const char* inSuggestedLeafName)
void nsFileSpec::MakeUnique()
//----------------------------------------------------------------------------------------
{
nsCOMPtr<nsISupports> 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);

Просмотреть файл

@ -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);