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 {
|
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue