out.close();
log.debug("done");
return;
}
BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
VFS vfs = shell.getVFS();
FileName pwd = new FileName(shell.getEnvProperty("PWD"));
String out = OUTPUT_STRING;
boolean output = false; // was out param already processed
boolean longOut = false;
boolean rslvLinks = true;
// boolean help = false;
List paths = new LinkedList();
for (int i = 0; i < params.length; i++) {
String param = params[i];
if (!longOut && param.equals(OPTION_LONG))
longOut = true;
else if (!output && param.startsWith(OUTPUT)) {
out = param.substring(OUTPUT.length());
output = true;
}
/* else if (param.equals(HELP)) {
help = true;
oout.writeObject("Usage: ls [--help] [-ex] [-out=OUTPUT] [-l] [--help]\n");
oout.writeObject(" OUTPUT = string | filename | fileinfo; String is default.\n");
oout.writeObject(" -l = long output; Makes difference only with -out=string.\n");
oout.writeObject(" --help = Prints this.\n");
oout.close();
System.out.println("[LsExe] : done.");
return;
}
*/
else {
FileName path = new FileName(param);
if (path.isRelative())
path = pwd.absolutize(path);
// path = vfs.resolve(shell.getUserCtx(), path, true);
paths.add(path);
}
}
// if no paths given, list working dir
if (paths.isEmpty())
paths.add(pwd);
// now we have all paths resolved and absolute in FileName form in the 'paths' list
//log.debug("Paths: " + paths);
List expPaths = new LinkedList();
Iterator it = paths.iterator();
while (it.hasNext()) {
FileName filename = (FileName) it.next();
List children = vfs.list(shell.getUserCtx(), filename, !rslvLinks);
//log.debug("Expanding children: " + children);
expPaths.addAll(children);
}
paths = expPaths;
//log.debug("Paths after expanding: " + paths);
//log.debug("long output = " +longOut);
//log.debug("output = " +out);
//log.debug("pwd = " +pwd);
//log.debug("paths = ");
//StringUtils.printCollection(paths);
List result = null;
if (out.equals(OUTPUT_STRING)) {
result = new LinkedList();
it = paths.iterator();
while (it.hasNext()) {
FileInfo info = (FileInfo) it.next();
if (longOut) {
List fields, lengths;
fields = new LinkedList();
lengths = new LinkedList();
// field pathname
fields.add(info.getFileName().toString());
lengths.add(pathLen);
// last modified
fields.add(info.isDirectory() ? "DIR" : info.isLink() ? "LINK" : "FILE");
lengths.add(typeLen);
// modified
fields.add(info.getLastModified().toString());
lengths.add(modifiedLen);
if (info.isLink()) {
// link
fields.add(info.getTarget().toString());
lengths.add(new Integer(0));
} else {
// length
fields.add(new Long(info.getLength()).toString());
lengths.add(new Integer(0));
}
// System.out.println("Adding to results (1): " + StringUtils.row(fields, lengths)+"\n");
result.add(StringUtils.row(fields, lengths) + "\r\n");
} else {
// System.out.println("Adding to results (2) info: " + info);
// System.out.println("Adding to results (2) info.FileName: " + info.getFileName());
// System.out.println("Adding to results (2): " + info.getFileName().toString() + "\n");
result.add(info.getFileName().toString() + "\r\n");
}
}
} else if (out.equals(OUTPUT_FILEINFO)) {
// System.out.println("Setting paths as result: " + paths);
result = paths;
} else if (out.equals(OUTPUT_FILENAME)) {
// System.out.println("Iterating paths and replacing infos with names: " + paths);
result = new LinkedList();
it = paths.iterator();
while (it.hasNext()) {
FileInfo info = (FileInfo) it.next();
result.add(info.getFileName());
}
}
it = result.iterator();
while (it.hasNext()) {
Object obj = it.next();
// System.out.println("Writing to out: ");
// System.out.println(obj);
oout.writeObject(obj);
}
finish:
oout.close();
log.debug("done");
}