Refactor RenameAction
This commit is contained in:
parent
5b693caf22
commit
fd54c59c71
|
@ -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 {
|
||||
|
||||
@Override
|
||||
|
@ -148,8 +133,12 @@ public enum StandardRenameAction implements RenameAction {
|
|||
return "Symlink";
|
||||
case HARDLINK:
|
||||
return "Hardlink";
|
||||
case DUPLICATE:
|
||||
return "Hardlink or Copy";
|
||||
case REFLINK:
|
||||
return "Lightweight Copy";
|
||||
default:
|
||||
return null;
|
||||
return "Test";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -529,9 +529,11 @@ public abstract class ScriptShellBaseClass extends Script {
|
|||
if (obj instanceof RenameAction) {
|
||||
return (RenameAction) obj;
|
||||
}
|
||||
|
||||
if (obj instanceof CharSequence) {
|
||||
return StandardRenameAction.forName(obj.toString());
|
||||
}
|
||||
|
||||
if (obj instanceof Closure<?>) {
|
||||
return new RenameAction() {
|
||||
|
||||
|
@ -542,7 +544,12 @@ public abstract class ScriptShellBaseClass extends Script {
|
|||
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
|
||||
return value instanceof File ? (File) value : to;
|
||||
return new File(value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRevert() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue