Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
5 var EXPORTED_SYMBOLS = ['listDirectory', 'getFileForPath', 'abspath', 'getPlatform'];
7 const Cc = Components.classes;
8 const Ci = Components.interfaces;
9 const Cu = Components.utils;
11 Cu.import("resource://gre/modules/Services.jsm");
13 function listDirectory(file) {
14 // file is the given directory (nsIFile)
15 var entries = file.directoryEntries;
16 var array = [];
18 while (entries.hasMoreElements()) {
19 var entry = entries.getNext();
20 entry.QueryInterface(Ci.nsIFile);
21 array.push(entry);
22 }
24 return array;
25 }
27 function getFileForPath(path) {
28 var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
29 file.initWithPath(path);
30 return file;
31 }
33 function abspath(rel, file) {
34 var relSplit = rel.split('/');
36 if (relSplit[0] == '..' && !file.isDirectory()) {
37 file = file.parent;
38 }
40 for each(var p in relSplit) {
41 if (p == '..') {
42 file = file.parent;
43 } else if (p == '.') {
44 if (!file.isDirectory()) {
45 file = file.parent;
46 }
47 } else {
48 file.append(p);
49 }
50 }
52 return file.path;
53 }
55 function getPlatform() {
56 return Services.appinfo.OS.toLowerCase();
57 }