зеркало из https://github.com/mozilla/pjs.git
bug 212123 reduce bloat and avoid fork in obsolete nsFileSpec by not reimplementing stuff the internal nsLocalFile gives us for free. r=timeless,sr=dougt,a=jay
This commit is contained in:
Родитель
ce289541bf
Коммит
26ae06eb2e
|
@ -909,34 +909,22 @@ void nsFileSpec::MakeUnique(const char* inSuggestedLeafName)
|
||||||
void nsFileSpec::MakeUnique()
|
void nsFileSpec::MakeUnique()
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
if (!Exists())
|
// XXX: updated path starts empty. In case of error this will cause
|
||||||
return;
|
// any callers to fail badly, but that seems better than letting them
|
||||||
|
// re-use the default name which has failed to be unique.
|
||||||
char* leafName = GetLeafName();
|
nsCAutoString path;
|
||||||
if (!leafName)
|
nsCOMPtr<nsILocalFile> localFile;
|
||||||
return;
|
NS_NewNativeLocalFile(nsDependentCString(*this), PR_TRUE, getter_AddRefs(localFile));
|
||||||
|
if (localFile)
|
||||||
char* lastDot = strrchr(leafName, '.');
|
|
||||||
char* suffix = "";
|
|
||||||
if (lastDot)
|
|
||||||
{
|
{
|
||||||
suffix = nsCRT::strdup(lastDot); // include '.'
|
nsresult rv = localFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
||||||
*lastDot = '\0'; // strip suffix and dot.
|
if (NS_SUCCEEDED(rv))
|
||||||
|
localFile->GetNativePath(path);
|
||||||
}
|
}
|
||||||
const int kMaxRootLength
|
|
||||||
= nsFileSpecHelpers::kMaxCoreLeafNameLength - strlen(suffix) - 1;
|
NS_WARN_IF_FALSE(!path.IsEmpty(), "MakeUnique() failed!");
|
||||||
if ((int)strlen(leafName) > (int)kMaxRootLength)
|
*this = path.get(); // reset the filepath to point to the unique location
|
||||||
leafName[kMaxRootLength] = '\0';
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
if (*suffix)
|
|
||||||
nsCRT::free(suffix);
|
|
||||||
nsCRT::free(leafName);
|
|
||||||
} // nsFileSpec::MakeUnique
|
} // nsFileSpec::MakeUnique
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -460,9 +460,6 @@ class NS_COM_OBSOLETE nsFileSpec
|
||||||
void operator += (const char* inRelativeUnixPath);
|
void operator += (const char* inRelativeUnixPath);
|
||||||
|
|
||||||
|
|
||||||
void MakeUnique();
|
|
||||||
void MakeUnique(const char* inSuggestedLeafName);
|
|
||||||
|
|
||||||
|
|
||||||
PRBool IsDirectory() const; // More stringent than Exists()
|
PRBool IsDirectory() const; // More stringent than Exists()
|
||||||
PRBool IsFile() const; // More stringent than Exists()
|
PRBool IsFile() const; // More stringent than Exists()
|
||||||
|
@ -476,6 +473,10 @@ class NS_COM_OBSOLETE nsFileSpec
|
||||||
// Creation and deletion of objects. These can modify the disk.
|
// 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
|
// Called for the spec of an alias. Modifies the spec to
|
||||||
// point to the original. Sets mError.
|
// point to the original. Sets mError.
|
||||||
nsresult ResolveSymlink(PRBool& wasSymlink);
|
nsresult ResolveSymlink(PRBool& wasSymlink);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче