diff --git a/core/src/main/java/com/halushko/kinocat/core/handlers/input/CliCommandExecutor.java b/core/src/main/java/com/halushko/kinocat/core/handlers/input/CliCommandExecutor.java index cbb528c..f020eba 100644 --- a/core/src/main/java/com/halushko/kinocat/core/handlers/input/CliCommandExecutor.java +++ b/core/src/main/java/com/halushko/kinocat/core/handlers/input/CliCommandExecutor.java @@ -2,6 +2,7 @@ import com.halushko.kinocat.core.rabbit.SmartJson; import lombok.extern.slf4j.Slf4j; +import lombok.val; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -14,7 +15,7 @@ public abstract class CliCommandExecutor extends InputMessageHandler { @Override protected String getDeliverCallbackPrivate(SmartJson rabbitMessage) { long userId = rabbitMessage.getUserId(); - String script = getScript(rabbitMessage); + val script = getScript(rabbitMessage); log.debug("[ExternalCliCommandExecutor] userId:{}, script:{}", userId, script); try { @@ -32,9 +33,9 @@ protected String getResultString(List lines, SmartJson rabbitMessage) { return lines == null ? "" : String.join("\n", lines); } - protected List executeViaCLI(String script) { + protected List executeViaCLI(String[] script) { // String command = String.format("sh %s%s", "/home/app/", script); - log.debug("[executeViaCLI] Execute script: {}", script); + log.debug("[executeViaCLI] Execute script: [{}]", String.join(", ", script)); List result = new ArrayList<>(); ProcessBuilder processBuilder = new ProcessBuilder(script); @@ -60,7 +61,7 @@ protected List executeViaCLI(String script) { return result; } - protected String getScript(SmartJson rabbitMessage){ - return rabbitMessage.getText(); + protected String[] getScript(SmartJson rabbitMessage){ + return new String[] {rabbitMessage.getText()}; } } diff --git a/file/src/main/java/com/halushko/kinocat/file/MoveToDestinationFolder.java b/file/src/main/java/com/halushko/kinocat/file/MoveToDestinationFolder.java index 2a8a70e..1239484 100644 --- a/file/src/main/java/com/halushko/kinocat/file/MoveToDestinationFolder.java +++ b/file/src/main/java/com/halushko/kinocat/file/MoveToDestinationFolder.java @@ -17,16 +17,19 @@ protected String getQueue() { } @Override - protected String getScript(SmartJson rabbitMessage) { + protected String[] getScript(SmartJson rabbitMessage) { List arguments = rabbitMessage.getSubMessage(SmartJsonKeys.COMMAND_ARGUMENTS).convertToList(); String folder = (String) arguments.get(0); String file = (String) arguments.get(1); - - return String.format("bash -c \"mv -f %s/%s.torrent %s/%s.torrent\"", - Constants.PATH_TO_UNAPPROVED_FOLDER, - file, - Constants.FOLDERS.get(folder), - UUID.randomUUID() - ); + return new String[]{ + "/bin/bash", + "-c", + String.format("\"mv -f %s/%s.torrent %s/%s.torrent\"", + Constants.PATH_TO_UNAPPROVED_FOLDER.replaceAll("\\s+", "\\\\ "), + file.replaceAll("\\s+", "\\\\ "), + Constants.FOLDERS.get(folder).replaceAll("\\s+", "\\\\ "), + UUID.randomUUID() + ) + }; } } \ No newline at end of file diff --git a/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java b/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java index 5efc225..88616a0 100644 --- a/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java +++ b/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java @@ -51,7 +51,11 @@ protected String getQueue() { } @Override - protected String getScript(SmartJson rabbitMessage) { - return String.format("bash -c \"/usr/bin/transmission-show %s\"", rabbitMessage.getValue(SmartJsonKeys.FILE_PATH)); + protected String[] getScript(SmartJson rabbitMessage) { + return new String[]{ + "/bin/bash", + "-c", + String.format("\"/usr/bin/transmission-show %s\"", rabbitMessage.getValue(SmartJsonKeys.FILE_PATH).replaceAll("\\s+", "\\\\ ")) + }; } } \ No newline at end of file