зеркало из https://github.com/mozilla/gecko-dev.git
Bug 375778 - Read-Only Files Changed to Read-Write p=Simon Bunzli (busy) <zeniko@gmail.com> r=dougt, sr=bsmedberg, a=bz
This commit is contained in:
Родитель
fbab3d6b56
Коммит
a54df5b5bf
|
@ -1435,67 +1435,12 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent,
|
|||
if (!move)
|
||||
copyOK = ::CopyFileW(filePath.get(), destPath.get(), PR_TRUE);
|
||||
else
|
||||
{
|
||||
// What we have to do is check to see if the destPath exists. If it
|
||||
// does, we have to move it out of the say so that MoveFile will
|
||||
// succeed. However, we don't want to just remove it since MoveFile
|
||||
// can fail leaving us without a file.
|
||||
copyOK = ::MoveFileExW(filePath.get(), destPath.get(),
|
||||
MOVEFILE_REPLACE_EXISTING |
|
||||
MOVEFILE_COPY_ALLOWED |
|
||||
MOVEFILE_WRITE_THROUGH);
|
||||
|
||||
nsAutoString backup;
|
||||
PRFileInfo64 fileInfo64;
|
||||
if (NS_SUCCEEDED(GetFileInfo(destPath, &fileInfo64)))
|
||||
{
|
||||
|
||||
// the file exists. Check to make sure it is not a directory,
|
||||
// then move it out of the way.
|
||||
if (fileInfo64.type == PR_FILE_FILE)
|
||||
{
|
||||
backup.Append(destPath);
|
||||
backup.Append(L".moztmp");
|
||||
|
||||
// we are about to remove the .moztmp file,
|
||||
// so attempt to make sure the file is writable
|
||||
// (meaning: the "read only" attribute is not set)
|
||||
// _wchmod can silently fail (return -1) if
|
||||
// the file doesn't exist but that's ok, because
|
||||
// _wremove() will also silently fail if the file
|
||||
// doesn't exist.
|
||||
(void)_wchmod(backup.get(), _S_IREAD | _S_IWRITE);
|
||||
|
||||
// remove any existing backup file that we may already have.
|
||||
// maybe we should be doing some kind of unique naming here,
|
||||
// but why bother.
|
||||
(void)_wremove(backup.get());
|
||||
|
||||
// move destination file to backup file
|
||||
copyOK = ::MoveFileW(destPath.get(), backup.get());
|
||||
if (!copyOK)
|
||||
{
|
||||
// I guess we can't do the backup copy, so return.
|
||||
rv = ConvertWinError(GetLastError());
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
// move source file to destination file
|
||||
copyOK = ::MoveFileW(filePath.get(), destPath.get());
|
||||
|
||||
if (!backup.IsEmpty())
|
||||
{
|
||||
if (copyOK)
|
||||
{
|
||||
// remove the backup copy.
|
||||
_wremove(backup.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
// restore backup
|
||||
int backupOk = ::MoveFileW(backup.get(), destPath.get());
|
||||
NS_ASSERTION(backupOk, "move backup failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!copyOK) // CopyFile and MoveFile returns non-zero if succeeds (backward if you ask me).
|
||||
if (!copyOK) // CopyFile and MoveFileEx return zero at failure.
|
||||
rv = ConvertWinError(GetLastError());
|
||||
|
||||
return rv;
|
||||
|
|
Загрузка…
Ссылка в новой задаче