Refactor RenameAction

This commit is contained in:
Reinhard Pointner 2016-11-25 19:37:20 +08:00
parent 5b693caf22
commit fd54c59c71
2 changed files with 13 additions and 17 deletions

View File

@ -108,21 +108,6 @@ public enum StandardRenameAction implements RenameAction {
} }
}, },
RENAME {
@Override
public File rename(File from, File to) throws Exception {
// rename only the filename
File dest = new File(from.getParentFile(), to.getName());
if (!from.renameTo(dest)) {
throw new IOException("Failed to rename " + from + " to " + dest);
}
return dest;
}
},
TEST { TEST {
@Override @Override
@ -148,8 +133,12 @@ public enum StandardRenameAction implements RenameAction {
return "Symlink"; return "Symlink";
case HARDLINK: case HARDLINK:
return "Hardlink"; return "Hardlink";
case DUPLICATE:
return "Hardlink or Copy";
case REFLINK:
return "Lightweight Copy";
default: default:
return null; return "Test";
} }
} }

View File

@ -529,9 +529,11 @@ public abstract class ScriptShellBaseClass extends Script {
if (obj instanceof RenameAction) { if (obj instanceof RenameAction) {
return (RenameAction) obj; return (RenameAction) obj;
} }
if (obj instanceof CharSequence) { if (obj instanceof CharSequence) {
return StandardRenameAction.forName(obj.toString()); return StandardRenameAction.forName(obj.toString());
} }
if (obj instanceof Closure<?>) { if (obj instanceof Closure<?>) {
return new RenameAction() { return new RenameAction() {
@ -542,7 +544,12 @@ public abstract class ScriptShellBaseClass extends Script {
Object value = closure.call(from, to); Object value = closure.call(from, to);
// must return File object, so we try the result of the closure, but if it's not a File we just return the original destination parameter // must return File object, so we try the result of the closure, but if it's not a File we just return the original destination parameter
return value instanceof File ? (File) value : to; return new File(value.toString());
}
@Override
public boolean canRevert() {
return false;
} }
@Override @Override