mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 920187 - Remove FileUtils.getFile r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D180462
This commit is contained in:
parent
3463d51539
commit
f1e2e8da62
@ -20,24 +20,6 @@ export var FileUtils = {
|
||||
PERMS_FILE: 0o644,
|
||||
PERMS_DIRECTORY: 0o755,
|
||||
|
||||
/**
|
||||
* Gets a file at the specified hierarchy under a nsIDirectoryService key.
|
||||
* @param key
|
||||
* The Directory Service Key to start from
|
||||
* @param pathArray
|
||||
* An array of path components to locate beneath the directory
|
||||
* specified by |key|. The last item in this array must be the
|
||||
* leaf name of a file.
|
||||
* @return nsIFile object for the file specified. The file is NOT created
|
||||
* if it does not exist, however all required directories along
|
||||
* the way are if pathArray has more than one item.
|
||||
*/
|
||||
getFile: function FileUtils_getFile(key, pathArray) {
|
||||
var file = this.getDir(key, pathArray.slice(0, -1), pathArray.length > 1);
|
||||
file.append(pathArray[pathArray.length - 1]);
|
||||
return file;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a directory at the specified hierarchy under a nsIDirectoryService
|
||||
* key.
|
||||
|
@ -23,42 +23,6 @@ function do_check_throws(f, result, stack) {
|
||||
|
||||
const gProfD = do_get_profile();
|
||||
|
||||
add_test(function test_getFile() {
|
||||
let file = FileUtils.getFile("ProfD", ["foobar"]);
|
||||
Assert.ok(file instanceof Ci.nsIFile);
|
||||
Assert.ok(!file.exists());
|
||||
|
||||
let other = gProfD.clone();
|
||||
other.append("foobar");
|
||||
Assert.ok(file.equals(other));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_getFile_nonexistentDir() {
|
||||
do_check_throws(function () {
|
||||
FileUtils.getFile("NonexistentD", ["foobar"]);
|
||||
}, Cr.NS_ERROR_FAILURE);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_getFile_createDirs() {
|
||||
let file = FileUtils.getFile("ProfD", ["a", "b", "foobar"]);
|
||||
Assert.ok(file instanceof Ci.nsIFile);
|
||||
Assert.ok(!file.exists());
|
||||
|
||||
let other = gProfD.clone();
|
||||
other.append("a");
|
||||
Assert.ok(other.isDirectory());
|
||||
other.append("b");
|
||||
Assert.ok(other.isDirectory());
|
||||
other.append("foobar");
|
||||
Assert.ok(file.equals(other));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_getDir() {
|
||||
let dir = FileUtils.getDir("ProfD", ["foodir"]);
|
||||
Assert.ok(dir instanceof Ci.nsIFile);
|
||||
@ -97,7 +61,9 @@ add_test(function test_getDir_shouldCreate() {
|
||||
});
|
||||
|
||||
var openFileOutputStream_defaultFlags = function (aKind, aFileName) {
|
||||
let file = FileUtils.getFile("ProfD", [aFileName]);
|
||||
let file = new FileUtils.File(
|
||||
PathUtils.join(PathUtils.profileDir, aFileName)
|
||||
);
|
||||
let fos;
|
||||
Assert.ok(aKind == "atomic" || aKind == "safe" || aKind == "");
|
||||
if (aKind == "atomic") {
|
||||
@ -133,7 +99,9 @@ var openFileOutputStream_defaultFlags = function (aKind, aFileName) {
|
||||
};
|
||||
|
||||
var openFileOutputStream_modeFlags = function (aKind, aFileName) {
|
||||
let file = FileUtils.getFile("ProfD", [aFileName]);
|
||||
let file = new FileUtils.File(
|
||||
PathUtils.join(PathUtils.profileDir, aFileName)
|
||||
);
|
||||
let fos;
|
||||
Assert.ok(aKind == "atomic" || aKind == "safe" || aKind == "");
|
||||
if (aKind == "atomic") {
|
||||
@ -153,7 +121,9 @@ var openFileOutputStream_modeFlags = function (aKind, aFileName) {
|
||||
};
|
||||
|
||||
var closeFileOutputStream = function (aKind, aFileName) {
|
||||
let file = FileUtils.getFile("ProfD", [aFileName]);
|
||||
let file = new FileUtils.File(
|
||||
PathUtils.join(PathUtils.profileDir, aFileName)
|
||||
);
|
||||
let fos;
|
||||
Assert.ok(aKind == "atomic" || aKind == "safe");
|
||||
if (aKind == "atomic") {
|
||||
@ -217,7 +187,9 @@ add_test(function test_closeSafeFileOutputStream() {
|
||||
});
|
||||
|
||||
add_test(function test_newFile() {
|
||||
let testfile = FileUtils.getFile("ProfD", ["test"]);
|
||||
let testfile = new FileUtils.File(
|
||||
PathUtils.join(PathUtils.profileDir, "test")
|
||||
);
|
||||
let testpath = testfile.path;
|
||||
let file = new FileUtils.File(testpath);
|
||||
Assert.ok(file instanceof Ci.nsIFile);
|
||||
|
Loading…
Reference in New Issue
Block a user