Backed out changeset 3232989e79e7 (bug 897023) for mochitest-other failures.

This commit is contained in:
Ryan VanderMeulen 2013-11-11 10:55:36 -05:00
parent a4eaee2f3a
commit fbeb6f72ac
6 changed files with 82 additions and 136 deletions

View File

@ -337,14 +337,13 @@
*
* @param {string} path The name of the directory to remove.
* @param {*=} options Additional options.
* - {bool} ignoreAbsent If |false|, throw an error if the directory
* does not exist. |true| by default
* - {bool} ignoreAbsent If |true|, do not fail if the
* directory does not exist yet.
*/
File.removeEmptyDir = function removeEmptyDir(path, options = {}) {
let result = UnixFile.rmdir(path);
if (result == -1) {
if ((!("ignoreAbsent" in options) || options.ignoreAbsent) &&
ctypes.errno == Const.ENOENT) {
if (options.ignoreAbsent && ctypes.errno == Const.ENOENT) {
return;
}
throw new File.Error("removeEmptyDir");
@ -367,19 +366,17 @@
* as per libc function |mkdir|. If unspecified, dirs are
* created with a default mode of 0700 (dir is private to
* the user, the user can read, write and execute).
* - {bool} ignoreExisting If |false|, throw error if the directory
* already exists. |true| by default
* - {bool} ignoreExisting If |true|, do not fail if the
* directory already exists.
*/
File.makeDir = function makeDir(path, options = {}) {
let omode = options.unixMode !== undefined ? options.unixMode : DEFAULT_UNIX_MODE_DIR;
let result = UnixFile.mkdir(path, omode);
if (result == -1) {
if ((!("ignoreExisting" in options) || options.ignoreExisting) &&
ctypes.errno == Const.EEXIST) {
return;
}
throw new File.Error("makeDir");
if (result != -1 ||
options.ignoreExisting && ctypes.errno == Const.EEXIST) {
return;
}
throw new File.Error("makeDir");
};
/**

View File

@ -410,13 +410,13 @@
*
* @param {string} path The name of the directory to remove.
* @param {*=} options Additional options.
* - {bool} ignoreAbsent If |false|, throw an error if the directory
* does not exist. |true| by default
* - {bool} ignoreAbsent If |true|, do not fail if the
* directory does not exist yet.
*/
File.removeEmptyDir = function removeEmptyDir(path, options = {}) {
let result = WinFile.RemoveDirectory(path);
if (!result) {
if ((!("ignoreAbsent" in options) || options.ignoreAbsent) &&
if (options.ignoreAbsent &&
ctypes.winLastError == Const.ERROR_FILE_NOT_FOUND) {
return;
}
@ -435,19 +435,18 @@
* as per winapi function |CreateDirectory|. If unspecified,
* use the default security descriptor, inherited from the
* parent directory.
* - {bool} ignoreExisting If |false|, throw an error if the directory
* already exists. |true| by default
* - {bool} ignoreExisting If |true|, do not fail if the
* directory already exists.
*/
File.makeDir = function makeDir(path, options = {}) {
let security = options.winSecurity || null;
let result = WinFile.CreateDirectory(path, security);
if (!result) {
if ((!("ignoreExisting" in options) || options.ignoreExisting) &&
ctypes.winLastError == Const.ERROR_ALREADY_EXISTS) {
return;
}
throw new File.Error("makeDir");
if (result ||
options.ignoreExisting &&
ctypes.winLastError == Const.ERROR_ALREADY_EXISTS) {
return;
}
throw new File.Error("makeDir");
};
/**

View File

@ -157,6 +157,7 @@ let test = maketest("Main", function main(test) {
yield test_read_write();
yield test_read_write_all();
yield test_position();
yield test_mkdir();
yield test_iter();
yield test_exists();
yield test_debug_test();
@ -428,6 +429,68 @@ let test_position = maketest("position", function position(test) {
});
});
/**
* Test OS.File.{removeEmptyDir, makeDir}
*/
let test_mkdir = maketest("mkdir", function mkdir(test) {
return Task.spawn(function() {
const DIRNAME = "test_dir.tmp";
// Cleanup
yield OS.File.removeEmptyDir(DIRNAME, {ignoreAbsent: true});
// Remove an absent directory with ignoreAbsent
yield OS.File.removeEmptyDir(DIRNAME, {ignoreAbsent: true});
test.ok(true, "Removing an absent directory with ignoreAbsent succeeds");
// Remove an absent directory without ignoreAbsent
try {
yield OS.File.removeEmptyDir(DIRNAME);
test.fail("Removing an absent directory without ignoreAbsent should have failed");
} catch (err) {
test.ok(err, "Removing an absent directory without ignoreAbsent throws the right error");
test.ok(err instanceof OS.File.Error, "Error is an OS.File.Error");
test.ok(err.becauseNoSuchFile, "Error mentions that the file does not exist");
}
// Creating a directory (should succeed)
test.ok(true, "Creating a directory");
yield OS.File.makeDir(DIRNAME);
let stat = yield OS.File.stat(DIRNAME);
test.ok(stat.isDir, "I have effectively created a directory");
// Creating a directory with ignoreExisting (should succeed)
try {
yield OS.File.makeDir(DIRNAME, {ignoreExisting: true});
test.ok(true, "Creating a directory with ignoreExisting succeeds");
} catch(err) {
test.ok(false, "Creating a directory with ignoreExisting fails");
}
// Creating a directory (should fail)
try {
yield OS.File.makeDir(DIRNAME);
test.fail("Creating over an existing directory should have failed");
} catch (err) {
test.ok(err, "Creating over an existing directory throws the right error");
test.ok(err instanceof OS.File.Error, "Error is an OS.File.Error");
test.ok(err.becauseExists, "Error mentions that the file already exists");
}
// Remove a directory and check the result
yield OS.File.removeEmptyDir(DIRNAME);
test.ok(true, "Removing empty directory suceeded");
try {
yield OS.File.stat(DIRNAME);
test.fail("Removing directory should have failed");
} catch (err) {
test.ok(err, "Directory was effectively removed");
test.ok(err instanceof OS.File.Error, "Error is an OS.File.Error");
test.ok(err.becauseNoSuchFile, "Error mentions that the file does not exist");
}
});
});
/**
* Test OS.File.prototype.{DirectoryIterator}
*/

View File

@ -1,56 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
Components.utils.import("resource://gre/modules/osfile.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
do_register_cleanup(function() {
Services.prefs.setBoolPref("toolkit.osfile.log", false);
});
function run_test() {
Services.prefs.setBoolPref("toolkit.osfile.log", true);
run_next_test();
}
/**
* Test OS.File.makeDir
*/
add_task(function() {
// Set up profile. We create the directory in the profile, because the profile
// is removed after every test run.
do_get_profile();
let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory");
// Sanity checking for the test
do_check_false((yield OS.File.exists(dir)));
// Make a directory
yield OS.File.makeDir(dir);
//check if the directory exists
yield OS.File.stat(dir);
// Make a directory that already exists
yield OS.File.makeDir(dir);
// Make a directory with ignoreExisting
yield OS.File.makeDir(dir, {ignoreExisting: true});
// Make a directory with ignoreExisting false
let exception = null;
try {
yield OS.File.makeDir(dir, {ignoreExisting: false});
} catch (ex) {
exception = ex;
}
do_check_true(!!exception);
do_check_true(exception instanceof OS.File.Error);
do_check_true(exception.becauseExists);
});

View File

@ -1,55 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
Components.utils.import("resource://gre/modules/osfile.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
do_register_cleanup(function() {
Services.prefs.setBoolPref("toolkit.osfile.log", false);
});
function run_test() {
Services.prefs.setBoolPref("toolkit.osfile.log", true);
run_next_test();
}
/**
* Test OS.File.removeEmptyDir
*/
add_task(function() {
// Set up profile. We create the directory in the profile, because the profile
// is removed after every test run.
do_get_profile();
let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory");
// Sanity checking for the test
do_check_false((yield OS.File.exists(dir)));
// Remove non-existent directory
yield OS.File.removeEmptyDir(dir);
// Remove non-existent directory with ignoreAbsent
yield OS.File.removeEmptyDir(dir, {ignoreAbsent: true});
// Remove non-existent directory with ignoreAbsent false
let exception = null;
try {
yield OS.File.removeEmptyDir(dir, {ignoreAbsent: false});
} catch (ex) {
exception = ex;
}
do_check_true(!!exception);
do_check_true(exception instanceof OS.File.Error);
do_check_true(exception.becauseNoSuchFile);
// Remove empty directory
yield OS.File.makeDir(dir);
yield OS.File.removeEmptyDir(dir);
do_check_false((yield OS.File.exists(dir)));
});

View File

@ -10,8 +10,6 @@ tail =
[test_osfile_async_copy.js]
[test_osfile_async_flush.js]
[test_osfile_async_setDates.js]
[test_removeEmptyDir.js]
[test_makeDir.js]
[test_profiledir.js]
[test_logging.js]
[test_creationDate.js]