1
0
Fork 0

slight improves

This commit is contained in:
Xavier Fontanet 2024-05-25 16:47:20 +02:00
parent 7241986b99
commit d093e0cc35
6 changed files with 15 additions and 6 deletions

View File

@ -21,8 +21,8 @@ public class ConfigLoader extends CommonConfigFileLoader<ConfigLoader.ProjectCon
return getLoader().getConfig(configParam); return getLoader().getConfig(configParam);
} }
public static boolean isDisabled(ProjectConfiguration configParam) { public static boolean isEnabled(ProjectConfiguration configParam) {
return !"true".equals(get(configParam)); return get(configParam).equals("true");
} }
public enum ProjectConfiguration { public enum ProjectConfiguration {

View File

@ -59,7 +59,7 @@ class FailedImportFixer {
private List<Path> getVideoFilesFrom(Path path) throws IOException { private List<Path> getVideoFilesFrom(Path path) throws IOException {
if (!Files.exists(path)) { if (!Files.exists(path)) {
System.out.printf("path %s doesn't exist on the filesystem", path); System.out.printf("path %s doesn't exist on the filesystem%n", path);
return List.of(); return List.of();
} }
System.out.println("going to explore "+path); System.out.println("going to explore "+path);

View File

@ -14,7 +14,7 @@ class FileCopier {
try { try {
createDestinationFolderIfApply(destination); createDestinationFolderIfApply(destination);
if (ConfigLoader.isDisabled(TEST_MODE)) if (!ConfigLoader.isEnabled(TEST_MODE))
Files.createLink(destination, source); Files.createLink(destination, source);
} catch (IOException e) { } catch (IOException e) {
System.out.printf("error when creating hardlink with destination %s, error: %s%n", System.out.printf("error when creating hardlink with destination %s, error: %s%n",
@ -27,7 +27,7 @@ class FileCopier {
var destinationFolder = destinationFile.getParent(); var destinationFolder = destinationFile.getParent();
if (isTemporaryDestination(destinationFolder) && !Files.exists(destinationFolder)) { if (isTemporaryDestination(destinationFolder) && !Files.exists(destinationFolder)) {
System.out.printf("destination folder %s will be created", destinationFolder); System.out.printf("destination folder %s will be created", destinationFolder);
if (ConfigLoader.isDisabled(TEST_MODE)) if (!ConfigLoader.isEnabled(TEST_MODE))
Files.createDirectories(destinationFile); Files.createDirectories(destinationFile);
} }
} }

View File

@ -4,6 +4,8 @@ import tv.mangrana.config.ConfigLoader;
import tv.mangrana.exception.IncorrectWorkingReferencesException; import tv.mangrana.exception.IncorrectWorkingReferencesException;
import tv.mangrana.sonarr.Sonarr; import tv.mangrana.sonarr.Sonarr;
import static tv.mangrana.config.ConfigLoader.ProjectConfiguration.TEST_MODE;
public class MainWorker { public class MainWorker {
private final QueueFixer queueFixer; private final QueueFixer queueFixer;
@ -15,6 +17,9 @@ public class MainWorker {
private MainWorker() throws IncorrectWorkingReferencesException { private MainWorker() throws IncorrectWorkingReferencesException {
var configLoader = ConfigLoader.getLoader(); var configLoader = ConfigLoader.getLoader();
if (ConfigLoader.isEnabled(TEST_MODE))
System.out.println("ATTENTION! TEST MODE ENABLED. No folders will be created nor files copied.");
Sonarr.initService(configLoader); Sonarr.initService(configLoader);
queueFixer = new QueueFixer(); queueFixer = new QueueFixer();
} }

View File

@ -11,6 +11,10 @@ class MissingFilesDetector {
private Map<Long, List<Path>> torrentFilesByLength; private Map<Long, List<Path>> torrentFilesByLength;
List<Path> getMissingFilesAtDestination(List<Path> torrentFiles, List<Path> sonarrFiles) { List<Path> getMissingFilesAtDestination(List<Path> torrentFiles, List<Path> sonarrFiles) {
if (sonarrFiles.size() == 0) {
System.out.println("All files are missing at destination");
return torrentFiles;
}
System.out.printf("going to compare %d torrent files with %d sonar files%n", System.out.printf("going to compare %d torrent files with %d sonar files%n",
torrentFiles.size(), sonarrFiles.size()); torrentFiles.size(), sonarrFiles.size());
digestTorrentFiles(torrentFiles); digestTorrentFiles(torrentFiles);

View File

@ -67,7 +67,7 @@ public class QueueFixer {
private void cleanWorkedElementsFromQueue(List<Record> sonarQueue, List<Record> recordsToFix) { private void cleanWorkedElementsFromQueue(List<Record> sonarQueue, List<Record> recordsToFix) {
List<String> workedTitles = mapRecord2Title(recordsToFix); List<String> workedTitles = mapRecord2Title(recordsToFix);
List<Integer> recordIds2Delete = filterPresentTitlesFromQueue(sonarQueue, workedTitles); List<Integer> recordIds2Delete = filterPresentTitlesFromQueue(sonarQueue, workedTitles);
if (ConfigLoader.isDisabled(TEST_MODE)) if (!ConfigLoader.isEnabled(TEST_MODE))
sonarrApiGateway.deleteQueueElements(recordIds2Delete); sonarrApiGateway.deleteQueueElements(recordIds2Delete);
} }