mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 02:25:34 +00:00
Bug 1712642: allow overwrite for WriteMode::Overwrite and WriteMode::Append r=barret
Differential Revision: https://phabricator.services.mozilla.com/D115849
This commit is contained in:
parent
dd9149a109
commit
16596721d7
@ -932,7 +932,7 @@ Result<uint32_t, IOUtils::IOError> IOUtils::WriteSync(
|
||||
nsCOMPtr<nsIFile> toMove;
|
||||
MOZ_ALWAYS_SUCCEEDS(aFile->Clone(getter_AddRefs(toMove)));
|
||||
|
||||
bool noOverwrite = aOptions.mMode != WriteMode::Create;
|
||||
bool noOverwrite = aOptions.mMode == WriteMode::Create;
|
||||
|
||||
if (MoveSync(toMove, backupFile, noOverwrite).isErr()) {
|
||||
return Err(IOError(NS_ERROR_FILE_COPY_OR_MOVE_FAILED)
|
||||
|
@ -153,6 +153,7 @@
|
||||
|
||||
info("Test backup with tmp and backup file options, existing destination");
|
||||
let newFileContents = new TextEncoder().encode("New file contents");
|
||||
ok(await fileExists(destFileName), `Expected ${destFileName} to exist`);
|
||||
bytesWritten =
|
||||
await IOUtils.write(destFileName, newFileContents, {
|
||||
backupFile: backupFileName,
|
||||
@ -174,6 +175,31 @@
|
||||
"IOUtils::write IOUtils::write can move tmp file to destination after performing a backup"
|
||||
);
|
||||
|
||||
info("Test backup with tmp and backup file options, existing destination and backup");
|
||||
newFileContents = new TextEncoder().encode("Updated new file contents");
|
||||
ok(await fileExists(destFileName), `Expected ${destFileName} to exist`);
|
||||
ok(await fileExists(backupFileName), `Expected ${backupFileName} to exist`);
|
||||
bytesWritten =
|
||||
await IOUtils.write(destFileName, newFileContents, {
|
||||
backupFile: backupFileName,
|
||||
tmpPath: tmpFileName,
|
||||
});
|
||||
|
||||
ok(!await fileExists(tmpFileName), "IOUtils::write cleans up the tmpFile");
|
||||
ok(
|
||||
await fileHasTextContents(backupFileName, "New file contents"),
|
||||
"IOUtils::write can create a backup if the target file exists"
|
||||
);
|
||||
ok(
|
||||
await fileHasTextContents(destFileName, "Updated new file contents"),
|
||||
"IOUtils::write can write to the destination when a temporary file is used"
|
||||
);
|
||||
is(
|
||||
bytesWritten,
|
||||
newFileContents.length,
|
||||
"IOUtils::write IOUtils::write can move tmp file to destination after performing a backup"
|
||||
);
|
||||
|
||||
await cleanup(destFileName, backupFileName);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user