Bug 786211 - OS.File atomic write (platform code). r=froydnj

This commit is contained in:
David Rajchenbach-Teller 2012-09-27 23:06:00 -04:00
parent 7eb6ad5e49
commit c9140839ad
2 changed files with 22 additions and 7 deletions

View File

@ -348,6 +348,9 @@
* @option {bool} noOverwrite - If set, this function will fail if
* a file already exists at |destPath|. Otherwise, if this file exists,
* it will be erased silently.
* @option {bool} noCopy - If set, this function will fail if the
* operation is more sophisticated than a simple renaming, i.e. if
* |sourcePath| and |destPath| are not situated on the same device.
*
* @throws {OS.File.Error} In case of any error.
*
@ -559,9 +562,11 @@
return;
// If the error is not EXDEV ("not on the same device"),
// throw it.
if (ctypes.errno != Const.EXDEV) {
throw new File.Error();
// or if the error is EXDEV and we have passed an option
// that prevents us from crossing devices, throw the
// error.
if (ctypes.errno != Const.EXDEV || options.noCopy) {
throw new File.Error("move");
}
// Otherwise, copy and remove.
@ -822,6 +827,9 @@
return new File.Info(gStatData);
};
File.read = exports.OS.Shared.AbstractFile.read;
File.writeAtomic = exports.OS.Shared.AbstractFile.writeAtomic;
/**
* Get/set the current directory.
*/

View File

@ -409,6 +409,9 @@
* @option {bool} noOverwrite - If set, this function will fail if
* a file already exists at |destPath|. Otherwise, if this file exists,
* it will be erased silently.
* @option {bool} noCopy - If set, this function will fail if the
* operation is more sophisticated than a simple renaming, i.e. if
* |sourcePath| and |destPath| are not situated on the same drive.
*
* @throws {OS.File.Error} In case of any error.
*
@ -422,11 +425,12 @@
*/
File.move = function move(sourcePath, destPath, options) {
options = options || noOptions;
let flags;
if (options.noOverwrite) {
let flags = 0;
if (!options.noCopy) {
flags = Const.MOVEFILE_COPY_ALLOWED;
} else {
flags = Const.MOVEFILE_COPY_ALLOWED | Const.MOVEFILE_REPLACE_EXISTING;
}
if (!options.noOverwrite) {
flags = flags | Const.MOVEFILE_REPLACE_EXISTING;
}
throw_on_zero("move",
WinFile.MoveFileEx(sourcePath, destPath, flags)
@ -817,6 +821,9 @@
winDisposition: OS.Constants.Win.OPEN_EXISTING
};
File.read = exports.OS.Shared.AbstractFile.read;
File.writeAtomic = exports.OS.Shared.AbstractFile.writeAtomic;
/**
* Get/set the current directory.
*/