зеркало из https://github.com/mozilla/gecko-dev.git
Bug 870622 - Unexpected Unix error when filename is not defined. Typechecking for |writeAtomic| function. r=yoric
This commit is contained in:
Родитель
0e21827b57
Коммит
0869438fd3
|
@ -342,6 +342,10 @@ AbstractFile.read = function read(path, bytes) {
|
|||
AbstractFile.writeAtomic =
|
||||
function writeAtomic(path, buffer, options = noOptions) {
|
||||
|
||||
// Verify that path is defined and of the correct type
|
||||
if (typeof path != "string" || path == "") {
|
||||
throw new TypeError("File path should be a (non-empty) string");
|
||||
}
|
||||
let noOverwrite = options.noOverwrite;
|
||||
if (noOverwrite && OS.File.exists(path)) {
|
||||
throw OS.File.Error.exists("writeAtomic");
|
||||
|
|
|
@ -479,6 +479,27 @@ let test_read_write_all = maketest("read_write_all", function read_write_all(tes
|
|||
// Cleanup.
|
||||
OS.File.remove(pathDest);
|
||||
|
||||
// Check that writeAtomic fails when destination path is undefined
|
||||
try {
|
||||
let path = undefined;
|
||||
let options = {tmpPath: tmpPath};
|
||||
yield OS.File.writeAtomic(path, contents, options);
|
||||
test.fail("With file path undefined, writeAtomic should have failed");
|
||||
} catch (err) {
|
||||
test.ok(err.message == "TypeError: File path should be a (non-empty) string",
|
||||
"With file path undefined, writeAtomic correctly failed");
|
||||
}
|
||||
|
||||
// Check that writeAtomic fails when destination path is an empty string
|
||||
try {
|
||||
let path = "";
|
||||
let options = {tmpPath: tmpPath};
|
||||
yield OS.File.writeAtomic(path, contents, options);
|
||||
test.fail("With file path an empty string, writeAtomic should have failed");
|
||||
} catch (err) {
|
||||
test.ok(err.message == "TypeError: File path should be a (non-empty) string",
|
||||
"With file path an empty string, writeAtomic correctly failed");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -338,6 +338,28 @@ function test_readall_writeall_file()
|
|||
}
|
||||
ok(!!exn && exn instanceof TypeError, "writeAtomic fails if tmpPath is not provided");
|
||||
|
||||
// Check that writeAtomic fails when destination path is undefined
|
||||
exn = null;
|
||||
try {
|
||||
let path = undefined;
|
||||
let options = {tmpPath: tmp_file_name};
|
||||
OS.File.writeAtomic(path, readResult.buffer, options);
|
||||
} catch (x) {
|
||||
exn = x;
|
||||
}
|
||||
ok(!!exn && exn instanceof TypeError, "writeAtomic fails if path is undefined");
|
||||
|
||||
// Check that writeAtomic fails when destination path is an empty string
|
||||
exn = null;
|
||||
try {
|
||||
let path = "";
|
||||
let options = {tmpPath: tmp_file_name};
|
||||
OS.File.writeAtomic(path, readResult.buffer, options);
|
||||
} catch (x) {
|
||||
exn = x;
|
||||
}
|
||||
ok(!!exn && exn instanceof TypeError, "writeAtomic fails if path is an empty string");
|
||||
|
||||
// Cleanup.
|
||||
OS.File.remove(tmp_file_name);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче