*** empty log message ***

This commit is contained in:
dougt%netscape.com 2000-01-04 00:50:08 +00:00
parent c1bf0f6491
commit bbba930444
2 changed files with 153 additions and 0 deletions

89
xpcom/tests/utils/cp.js Normal file
View File

@ -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");
}
}

64
xpcom/tests/utils/ls.js Normal file
View File

@ -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);
}
}