mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 19:33:18 +00:00
Now adjusting the nsFileSpec after a Move().
Also fixing a bug with Rename(). Now it should successfully take partial pathnames on Unix and Windows.
This commit is contained in:
parent
bccf315074
commit
aae2baf3ab
@ -458,7 +458,7 @@ class NS_BASE nsFileSpec
|
||||
return Rename(newName);
|
||||
}
|
||||
nsresult Copy(const nsFileSpec& inNewParentDirectory) const;
|
||||
nsresult Move(const nsFileSpec& inNewParentDirectory) const;
|
||||
nsresult Move(const nsFileSpec& inNewParentDirectory);
|
||||
nsresult Execute(const char* args) const;
|
||||
nsresult Execute(const nsString& args) const
|
||||
{
|
||||
|
@ -816,7 +816,7 @@ nsresult nsFileSpec::Copy(const nsFileSpec& newParentDir) const
|
||||
} // nsFileSpec::Copy
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsFileSpec::Move(const nsFileSpec& newParentDir) const
|
||||
nsresult nsFileSpec::Move(const nsFileSpec& newParentDir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// We can only move into a directory
|
||||
@ -827,6 +827,9 @@ nsresult nsFileSpec::Move(const nsFileSpec& newParentDir) const
|
||||
nsresult result = NS_FILE_RESULT(::FSpMoveRenameCompat(&mSpec,
|
||||
&newParentDir.mSpec,
|
||||
const_cast<StringPtr>(GetLeafPName())));
|
||||
|
||||
if ( NS_SUCCEEDED(result) )
|
||||
*this = newParentDir + GetLeafName();
|
||||
|
||||
return result;
|
||||
} // nsFileSpec::Move
|
||||
|
@ -231,11 +231,19 @@ nsresult nsFileSpec::Rename(const char* inNewName)
|
||||
if (strchr(inNewName, '/'))
|
||||
return NS_FILE_FAILURE;
|
||||
|
||||
if (PR_Rename(mPath, inNewName) != 0)
|
||||
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
|
||||
|
||||
@ -313,7 +321,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
|
||||
@ -331,8 +339,11 @@ nsresult nsFileSpec::Move(const nsFileSpec& inNewParentDirectory) const
|
||||
if (result == NS_OK)
|
||||
{
|
||||
// cast to fix const-ness
|
||||
((nsFileSpec*)this)->Delete(PR_FALSE);
|
||||
}
|
||||
((nsFileSpec*)this)->Delete(PR_FALSE);
|
||||
|
||||
*this = inNewParentDirectory + GetLeafName();
|
||||
}
|
||||
delete [] destPath;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -458,7 +458,7 @@ class NS_BASE nsFileSpec
|
||||
return Rename(newName);
|
||||
}
|
||||
nsresult Copy(const nsFileSpec& inNewParentDirectory) const;
|
||||
nsresult Move(const nsFileSpec& inNewParentDirectory) const;
|
||||
nsresult Move(const nsFileSpec& inNewParentDirectory);
|
||||
nsresult Execute(const char* args) const;
|
||||
nsresult Execute(const nsString& args) const
|
||||
{
|
||||
|
@ -816,7 +816,7 @@ nsresult nsFileSpec::Copy(const nsFileSpec& newParentDir) const
|
||||
} // nsFileSpec::Copy
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsFileSpec::Move(const nsFileSpec& newParentDir) const
|
||||
nsresult nsFileSpec::Move(const nsFileSpec& newParentDir)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// We can only move into a directory
|
||||
@ -827,6 +827,9 @@ nsresult nsFileSpec::Move(const nsFileSpec& newParentDir) const
|
||||
nsresult result = NS_FILE_RESULT(::FSpMoveRenameCompat(&mSpec,
|
||||
&newParentDir.mSpec,
|
||||
const_cast<StringPtr>(GetLeafPName())));
|
||||
|
||||
if ( NS_SUCCEEDED(result) )
|
||||
*this = newParentDir + GetLeafName();
|
||||
|
||||
return result;
|
||||
} // nsFileSpec::Move
|
||||
|
@ -231,11 +231,19 @@ nsresult nsFileSpec::Rename(const char* inNewName)
|
||||
if (strchr(inNewName, '/'))
|
||||
return NS_FILE_FAILURE;
|
||||
|
||||
if (PR_Rename(mPath, inNewName) != 0)
|
||||
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
|
||||
|
||||
@ -313,7 +321,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
|
||||
@ -331,8 +339,11 @@ nsresult nsFileSpec::Move(const nsFileSpec& inNewParentDirectory) const
|
||||
if (result == NS_OK)
|
||||
{
|
||||
// cast to fix const-ness
|
||||
((nsFileSpec*)this)->Delete(PR_FALSE);
|
||||
}
|
||||
((nsFileSpec*)this)->Delete(PR_FALSE);
|
||||
|
||||
*this = inNewParentDirectory + GetLeafName();
|
||||
}
|
||||
delete [] destPath;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user