From f8fe689a81f906d1b91bb3220acde2a4ecb14c5b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 05:01:46 +0200 Subject: Adding upstream version 6.0.4-dfsg. Signed-off-by: Daniel Baumann --- src/libs/xpcom18a4/xpcom/tests/utils/ls.js | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/libs/xpcom18a4/xpcom/tests/utils/ls.js (limited to 'src/libs/xpcom18a4/xpcom/tests/utils/ls.js') 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); + } +} -- cgit v1.2.3