ExecutableRenameAction: relativize destination path (i.e. to make scp/sftp calls easier)
This commit is contained in:
parent
020f045fc1
commit
9b31ebfab8
|
@ -205,7 +205,7 @@ public class ArgumentBean {
|
||||||
public RenameAction getRenameAction() {
|
public RenameAction getRenameAction() {
|
||||||
// support custom executables (via absolute path)
|
// support custom executables (via absolute path)
|
||||||
if (action.startsWith("/")) {
|
if (action.startsWith("/")) {
|
||||||
return new ExecutableRenameAction(action);
|
return new ExecutableRenameAction(action, getOutputPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// support custom groovy scripts (via closures)
|
// support custom groovy scripts (via closures)
|
||||||
|
|
|
@ -8,15 +8,17 @@ import net.filebot.RenameAction;
|
||||||
public class ExecutableRenameAction implements RenameAction {
|
public class ExecutableRenameAction implements RenameAction {
|
||||||
|
|
||||||
private final String executable;
|
private final String executable;
|
||||||
|
private final File directory;
|
||||||
|
|
||||||
public ExecutableRenameAction(String executable) {
|
public ExecutableRenameAction(String executable, File directory) {
|
||||||
this.executable = executable;
|
this.executable = executable;
|
||||||
|
this.directory = directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File rename(File from, File to) throws Exception {
|
public File rename(File from, File to) throws Exception {
|
||||||
ProcessBuilder process = new ProcessBuilder(executable, from.getPath(), to.getPath());
|
ProcessBuilder process = new ProcessBuilder(executable, from.getCanonicalPath(), getRelativePath(directory, to));
|
||||||
process.directory(from.getParentFile());
|
process.directory(directory);
|
||||||
process.inheritIO();
|
process.inheritIO();
|
||||||
|
|
||||||
int exitCode = process.start().waitFor();
|
int exitCode = process.start().waitFor();
|
||||||
|
@ -27,6 +29,10 @@ public class ExecutableRenameAction implements RenameAction {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getRelativePath(File dir, File f) {
|
||||||
|
return dir == null ? f.toString() : dir.toPath().relativize(f.toPath()).toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRevert() {
|
public boolean canRevert() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -514,7 +514,7 @@ public abstract class ScriptShellBaseClass extends Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj instanceof File) {
|
if (obj instanceof File) {
|
||||||
return new ExecutableRenameAction(obj.toString());
|
return new ExecutableRenameAction(obj.toString(), getArgumentBean().getOutputPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj instanceof Closure) {
|
if (obj instanceof Closure) {
|
||||||
|
|
Loading…
Reference in New Issue