package org.jboss.fresh.shell.commands;
import org.jboss.fresh.vfs.FileName;
import org.jboss.fresh.vfs.VFS;
import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.io.PrintWriter2;
import org.jboss.fresh.shell.AbstractExecutable;
import java.util.LinkedList;
import java.util.List;
// EX OK
public class RmExe extends AbstractExecutable {
private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(RmExe.class);
/**
Deletes the files specified.
*/
public void process(String exename, String[] params) throws Exception {
log.debug("entered");
if (helpRequested()) {
PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
out.println("Usage: RM [--help] [-ex] FILES");
out.println(" FILES : files to be removed.");
out.println(" --help : this help");
out.close();
log.debug("done");
return;
}
PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
VFS vfs = shell.getVFS();
FileName pwd = new FileName(shell.getEnvProperty("PWD"));
List paths = new LinkedList();
for (int i = 0; i < params.length; i++) {
String param = params[i];
FileName path = new FileName(param);
if (path.isRelative())
path = pwd.absolutize(path);
// path = vfs.resolve(shell.getUserCtx(), path, true);
log.debug("FREAKING PATH = " + path);
if (vfs.exists(shell.getUserCtx(), path, true)) {
vfs.remove(shell.getUserCtx(), path, true);
out.println(param + ": Path and all children removed!");
} else {
if (canThrowEx()) {
throw new RuntimeException(param + ": Path does not exist! Cannot delete inexisting path!");
} else {
out.println(param + ": Path does not exist! Cannot delete inexisting path!");
}
}
}
out.close();
log.debug("done");
}
}