diff --git a/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java b/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java index 0bb8185..b208096 100644 --- a/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java +++ b/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java @@ -12,30 +12,24 @@ public class CheckDiskFreeSpace extends CliCommandExecutor { @Override protected String getResultString(List lines, SmartJson rabbitMessage) { - log.debug(String.format("[CheckDiskFreeSpace] [%s]", String.join(", ", lines))); - StringBuilder sb = new StringBuilder("Вільного місця у сховищі:"); - - for (String line : lines) { - sb.append("\n").append(line); - } + log.debug(String.format("[CheckDiskFreeSpace] df -h result:\n[%s]", String.join("\n", lines))); + log.debug(String.format("[CheckDiskFreeSpace] folders:\n[%s]", String.join("\n", Constants.FOLDERS.keySet()))); + StringBuilder sb = new StringBuilder("Вільного місця у сховищі:"); for (val device : Constants.FOLDERS.entrySet()) { - boolean flag = false; - sb.append("\n").append(device.getKey()); + boolean storageIsFound = false; for (String line : lines) { if (line.matches(device.getKey() + ".*")) { - String size = line; - size = size.replaceAll("^\\S+\\s+\\S+\\s+\\S+\\s+", ""); - size = size.replaceAll("\\S+\\s+\\S+\\s*$", ""); - sb.append("\n").append(device.getKey()); - sb.append(": ").append(size); + sb.append(": ").append(getSize(line)); - flag = true; + log.debug(String.format("[CheckDiskFreeSpace] Folder [%s] is present in line [%s]", device.getKey(), line)); + storageIsFound = true; break; } + log.debug(String.format("[CheckDiskFreeSpace] Folder [%s] is NOT present in line [%s]", device.getKey(), line)); } - if (!flag) { + if (!storageIsFound) { sb.append("\n").append(device.getKey()).append(": не вказано Filesystem у налаштуваннях"); } } @@ -43,6 +37,13 @@ protected String getResultString(List lines, SmartJson rabbitMessage) { return sb.toString(); } + private static String getSize(String line) { + String size = line; + size = size.replaceAll("^\\S+\\s+\\S+\\s+\\S+\\s+", ""); + size = size.replaceAll("\\S+\\s+\\S+\\s*$", ""); + return size; + } + @Override protected String getQueue() { return Queues.File.SHOW_FREE_SPACE;