}
try {
PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
VFS vfs = shell.getVFS();
FileName pwd = new FileName(shell.getEnvProperty("PWD"));
LinkedList paths = new LinkedList();
boolean force = false;
boolean errors = false;
for (int i = 0; i < params.length; i++) {
String param = params[i];
log.debug("param:" + param);
if ((i == 0) && param.equals(FORCE))
force = true;
else {
FileName path = new FileName(param);
if (path.isRelative())
path = pwd.absolutize(path);
//path = vfs.resolve(shell.getUserCtx(), path, true);
if (!vfs.exists(shell.getUserCtx(), path, true) && i != params.length - 1) {
if (canThrowEx()) {
throw new RuntimeException(param + ": Path already exists!");
} else {
out.println(param + ": Path does not exists!");
errors = true;
}
break;
} else
paths.add(path);
}
}
if ((paths.size() <= 1) || (errors && !force)) {
out.println("Usage: mv FILES DEST_DIR");
out.println(" mv FILE DEST_FILE");
} else {
FileName lastPath = (FileName) paths.removeLast();
boolean lastPathXsists = vfs.exists(shell.getUserCtx(), lastPath, true);
if (lastPathXsists) {
FileInfo lastInfo = vfs.getFileInfo(shell.getUserCtx(), lastPath, false);
if (lastInfo.isDirectory() && (force || !errors)) {
log.debug("1.Moving multiple files to dir.");
Iterator it = paths.iterator();
while (it.hasNext()) {
FileName path = (FileName) it.next();
FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
if (move(info, lastPath.absolutize(path.getName()), force, vfs, out) && !force)
return;
}
} else if ((paths.size() == 1) && force) {
log.debug("1.Moving file (overwrite).");
FileName path = (FileName) paths.getFirst();
FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
if (move(info, lastPath, force, vfs, out) && !force)
return;
} else {
if (canThrowEx()) {
throw new RuntimeException(lastPath + ": Destination path is not a directory!");
} else {
out.println(lastPath + ": Destination path is not a directory!");
}
}
} else if (paths.size() == 1) {
log.debug("1.Moving file.");
FileName path = (FileName) paths.getFirst();
FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
if (move(info, lastPath, force, vfs, out) && !force)
return;
} else {