Now adjusting the nsFileSpec after a Move().
Also fixing a bug with Rename(). Now it should successfully take partial pathnames on Unix and Windows. git-svn-id: svn://10.0.0.236/trunk@24612 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -284,11 +284,19 @@ nsresult nsFileSpec::Rename(const char* inNewName)
|
||||
if (strchr(inNewName, '/'))
|
||||
return NS_FILE_FAILURE;
|
||||
|
||||
if (PR_Rename(*this, inNewName) != NS_OK)
|
||||
char* oldPath = PL_strdup(mPath);
|
||||
|
||||
SetLeafName(inNewName);
|
||||
|
||||
if (PR_Rename(oldPath, mPath) != NS_OK)
|
||||
{
|
||||
// Could not rename, set back to the original.
|
||||
mPath = oldPath;
|
||||
return NS_FILE_FAILURE;
|
||||
}
|
||||
SetLeafName(inNewName);
|
||||
|
||||
delete [] oldPath;
|
||||
|
||||
return NS_OK;
|
||||
} // nsFileSpec::Rename
|
||||
|
||||
@@ -314,7 +322,7 @@ nsresult nsFileSpec::Copy(const nsFileSpec& inParentDirectory) const
|
||||
} // nsFileSpec::Copy
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsFileSpec::Move(const nsFileSpec& inNewParentDirectory) const
|
||||
nsresult nsFileSpec::Move(const nsFileSpec& inNewParentDirectory)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// We can only copy into a directory, and (for now) can not copy entire directories
|
||||
@@ -328,8 +336,14 @@ nsresult nsFileSpec::Move(const nsFileSpec& inNewParentDirectory) const
|
||||
|
||||
// MoveFile returns non-zero if succeeds
|
||||
int copyOK = MoveFile(GetCString(), destPath);
|
||||
|
||||
if (copyOK)
|
||||
{
|
||||
*this = inNewParentDirectory + GetLeafName();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
delete [] destPath;
|
||||
}
|
||||
return NS_FILE_FAILURE;
|
||||
} // nsFileSpec::Move
|
||||
|
||||
Reference in New Issue
Block a user