diff --git a/xpcom/tests/utils/cp.js b/xpcom/tests/utils/cp.js new file mode 100644 index 000000000000..197497be0df3 --- /dev/null +++ b/xpcom/tests/utils/cp.js @@ -0,0 +1,89 @@ +const nsILocalFile = Components.interfaces.nsILocalFile; +var prefix = ""; + +function cp(source, dest, followLinks, newName) +{ + try { + var sourceFile = Components.classes["component://netscape/file/local"]. + createInstance(nsILocalFile); + sourceFile.initWithPath(source); + + var destFile = Components.classes["component://netscape/file/local"]. + createInstance(nsILocalFile); + destFile.initWithPath(dest); + + } + catch (e) { + dump("Could not create nsILocalFile\n"); + } + + try { + + if (! destFile.isDirectory()) + { + dump("destination not a directory!\n"); + return; + } + } + catch (e) { + dump("error accessing dest"); + } + + try { + if (followLinks) + { + sourceFile.copyToFollowingLinks(destFile, newName); + } + else + { + sourceFile.copyTo(destFile, newName); + } + } + catch (e) { + dump("error coping" + e + "\n"); + } +} + + +function mv(source, dest, followLinks, newName) +{ + try { + var sourceFile = Components.classes["component://netscape/file/local"]. + createInstance(nsILocalFile); + sourceFile.initWithPath(source); + + var destFile = Components.classes["component://netscape/file/local"]. + createInstance(nsILocalFile); + destFile.initWithPath(dest); + + } + catch (e) { + dump("Could not create nsILocalFile\n"); + } + + try { + + if (! destFile.isDirectory()) + { + dump("destination not a directory!\n"); + return; + } + } + catch (e) { + dump("error accessing dest"); + } + + try { + if (followLinks) + { + sourceFile.moveToFollowingLinks(destFile, newName); + } + else + { + sourceFile.moveTo(destFile, newName); + } + } + catch (e) { + dump("error coping" + e + "\n"); + } +} diff --git a/xpcom/tests/utils/ls.js b/xpcom/tests/utils/ls.js new file mode 100644 index 000000000000..0fb4b07b1de0 --- /dev/null +++ b/xpcom/tests/utils/ls.js @@ -0,0 +1,64 @@ +const nsILocalFile = Components.interfaces.nsILocalFile; +var prefix = ""; + +function ls(path, recur) +{ + var file = Components.classes["component://netscape/file/local"]. + 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); + } +}