mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 857077 - Add ignoreAbsent option to OS.File.remove. r=yoric
This commit is contained in:
parent
688f174edb
commit
22e4a95eb5
@ -268,11 +268,21 @@
|
||||
* Remove an existing file.
|
||||
*
|
||||
* @param {string} path The name of the file.
|
||||
* @param {*=} options Additional options.
|
||||
* - {bool} ignoreAbsent If |false|, throw an error if the file does
|
||||
* not exist. |true| by default.
|
||||
*
|
||||
* @throws {OS.File.Error} In case of I/O error.
|
||||
*/
|
||||
File.remove = function remove(path) {
|
||||
throw_on_negative("remove",
|
||||
UnixFile.unlink(path)
|
||||
);
|
||||
File.remove = function remove(path, options = {}) {
|
||||
let result = UnixFile.unlink(path);
|
||||
if (result == -1) {
|
||||
if ((!("ignoreAbsent" in options) || options.ignoreAbsent) &&
|
||||
ctypes.errno == Const.ENOENT) {
|
||||
return;
|
||||
}
|
||||
throw new File.Error("remove");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -329,11 +329,21 @@
|
||||
* Remove an existing file.
|
||||
*
|
||||
* @param {string} path The name of the file.
|
||||
* @param {*=} options Additional options.
|
||||
* - {bool} ignoreAbsent If |false|, throw an error if the file does
|
||||
* not exist. |true| by default.
|
||||
*
|
||||
* @throws {OS.File.Error} In case of I/O error.
|
||||
*/
|
||||
File.remove = function remove(path) {
|
||||
throw_on_zero("remove",
|
||||
WinFile.DeleteFile(path));
|
||||
File.remove = function remove(path, options = {}) {
|
||||
let result = WinFile.DeleteFile(path);
|
||||
if (!result) {
|
||||
if ((!("ignoreAbsent" in options) || options.ignoreAbsent) &&
|
||||
ctypes.winLastError == Const.ERROR_FILE_NOT_FOUND) {
|
||||
return;
|
||||
}
|
||||
throw new File.Error("remove");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@ self.onmessage = function onmessage_start(msg) {
|
||||
test_info();
|
||||
test_path();
|
||||
test_exists_file();
|
||||
test_remove_file();
|
||||
} catch (x) {
|
||||
log("Catching error: " + x);
|
||||
log("Stack: " + x.stack);
|
||||
@ -819,3 +820,23 @@ function test_exists_file()
|
||||
|
||||
info("test_exists_file: complete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the file |remove| method.
|
||||
*/
|
||||
function test_remove_file()
|
||||
{
|
||||
let absent_file_name = "test_osfile_front_absent.tmp";
|
||||
|
||||
// Check that removing absent files is handled correctly
|
||||
let exn = should_throw(function() {
|
||||
OS.File.remove(absent_file_name, {ignoreAbsent: false});
|
||||
});
|
||||
ok(!!exn, "test_remove_file: throws if there is no such file");
|
||||
|
||||
exn = should_throw(function() {
|
||||
OS.File.remove(absent_file_name, {ignoreAbsent: true});
|
||||
OS.File.remove(absent_file_name);
|
||||
});
|
||||
ok(!exn, "test_remove_file: ignoreAbsent works");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user