ExecutableRenameAction: relativize destination path (i.e. to make scp/sftp calls easier)

This commit is contained in:
Reinhard Pointner 2017-04-07 00:20:57 +08:00
parent 020f045fc1
commit 9b31ebfab8
3 changed files with 11 additions and 5 deletions

View File

@ -205,7 +205,7 @@ public class ArgumentBean {
public RenameAction getRenameAction() {
// support custom executables (via absolute path)
if (action.startsWith("/")) {
return new ExecutableRenameAction(action);
return new ExecutableRenameAction(action, getOutputPath());
}
// support custom groovy scripts (via closures)

View File

@ -8,15 +8,17 @@ import net.filebot.RenameAction;
public class ExecutableRenameAction implements RenameAction {
private final String executable;
private final File directory;
public ExecutableRenameAction(String executable) {
public ExecutableRenameAction(String executable, File directory) {
this.executable = executable;
this.directory = directory;
}
@Override
public File rename(File from, File to) throws Exception {
ProcessBuilder process = new ProcessBuilder(executable, from.getPath(), to.getPath());
process.directory(from.getParentFile());
ProcessBuilder process = new ProcessBuilder(executable, from.getCanonicalPath(), getRelativePath(directory, to));
process.directory(directory);
process.inheritIO();
int exitCode = process.start().waitFor();
@ -27,6 +29,10 @@ public class ExecutableRenameAction implements RenameAction {
return null;
}
private String getRelativePath(File dir, File f) {
return dir == null ? f.toString() : dir.toPath().relativize(f.toPath()).toString();
}
@Override
public boolean canRevert() {
return false;

View File

@ -514,7 +514,7 @@ public abstract class ScriptShellBaseClass extends Script {
}
if (obj instanceof File) {
return new ExecutableRenameAction(obj.toString());
return new ExecutableRenameAction(obj.toString(), getArgumentBean().getOutputPath());
}
if (obj instanceof Closure) {