summaryrefslogtreecommitdiffstats
path: root/src/libs/xpcom18a4/xpcom/tests/utils/ls.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 03:01:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 03:01:46 +0000
commitf8fe689a81f906d1b91bb3220acde2a4ecb14c5b (patch)
tree26484e9d7e2c67806c2d1760196ff01aaa858e8c /src/libs/xpcom18a4/xpcom/tests/utils/ls.js
parentInitial commit. (diff)
downloadvirtualbox-f8fe689a81f906d1b91bb3220acde2a4ecb14c5b.tar.xz
virtualbox-f8fe689a81f906d1b91bb3220acde2a4ecb14c5b.zip
Adding upstream version 6.0.4-dfsg.upstream/6.0.4-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libs/xpcom18a4/xpcom/tests/utils/ls.js')
-rw-r--r--src/libs/xpcom18a4/xpcom/tests/utils/ls.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/libs/xpcom18a4/xpcom/tests/utils/ls.js b/src/libs/xpcom18a4/xpcom/tests/utils/ls.js
new file mode 100644
index 00000000..8ae62f06
--- /dev/null
+++ b/src/libs/xpcom18a4/xpcom/tests/utils/ls.js
@@ -0,0 +1,64 @@
+const nsILocalFile = Components.interfaces.nsILocalFile;
+var prefix = "";
+
+function ls(path, recur)
+{
+ var file = Components.classes["@mozilla.org/file/local;1"].
+ createInstance(nsILocalFile);
+ try {
+ file.initWithPath( path );
+
+ if (file.isDirectory() && arguments.length == 1)
+ ls_dir(file, recur);
+ else
+ ls_file(file, recur);
+ }
+ catch (e) {
+ dump("Error Returned " + e + "\n");
+ }
+}
+function ls_file(file, recur)
+{
+ dump(prefix);
+
+ try {
+ if (file.isDirectory()) {
+ dump("directory " + file.leafName + "\n");
+ if(recur)
+ ls_dir(file, true);
+ return;
+ }
+
+ dump(file.leafName + " " + file.fileSize);
+ if (file.isSymlink())
+ dump(" -> " + file.target);
+ dump("\n");
+ }
+
+ catch (e) {
+ dump(file.leafName + " (error accessing)\n");
+ }
+}
+
+function ls_dir(file, recur)
+{
+ var leafName = file.leafName;
+
+ var old = prefix;
+ prefix = prefix + " ";
+
+ iter = file.directoryEntries;
+ dump(iter + "\n");
+
+ foreach_iter(iter,
+ function (file) { ls_file(file, recur); });
+ prefix = old;
+}
+
+function foreach_iter(iter, fun)
+{
+ while (iter.hasMoreElements()) {
+ var item = iter.getNext().QueryInterface(nsILocalFile);
+ fun(item);
+ }
+}