last code review
This commit is contained in:
parent
aaf93df99d
commit
14c0573d1b
|
@ -45,7 +45,7 @@ public class FailedImportFixer {
|
|||
}
|
||||
|
||||
private List<Path> resolveTorrentFiles() throws IOException {
|
||||
return getVideoFilesFrom(Path.of(queueRecord.getOutputPath()));
|
||||
return getVideoFilesFrom(torrentPath);
|
||||
}
|
||||
|
||||
private List<Path> resolveSonarrFiles() throws IOException {
|
||||
|
|
|
@ -8,18 +8,24 @@ import java.util.stream.Collectors;
|
|||
public class MissingFilesDetector {
|
||||
|
||||
private Map<Long, List<Path>> sonarrFilesByLength;
|
||||
private Map<Long, List<Path>> torrentFileLengths;
|
||||
|
||||
List<Path> getMissingFilesAtDestination(List<Path> torrentFiles, List<Path> sonarrFiles) {
|
||||
System.out.printf("going to compare %d torrent files with %d sonar files%n",
|
||||
torrentFiles.size(), sonarrFiles.size());
|
||||
Map<Long, List<Path>> torrentFileLengths = getFileLengthsMapFrom(torrentFiles);
|
||||
if (hasFilesWithSameSize(torrentFileLengths))
|
||||
return torrentFiles;
|
||||
sonarrFilesByLength = getFileLengthsMapFrom(sonarrFiles);
|
||||
if (hasFilesWithSameSize(sonarrFilesByLength))
|
||||
return torrentFiles;
|
||||
digestTorrentFiles(torrentFiles);
|
||||
digestSonarrFiles(sonarrFiles);
|
||||
return resolveMissingFiles();
|
||||
}
|
||||
|
||||
return resolveMissingFiles(torrentFileLengths);
|
||||
private void digestTorrentFiles(List<Path> torrentFiles) {
|
||||
torrentFileLengths = getFileLengthsMapFrom(torrentFiles);
|
||||
throwIfDuplicatedSizes(torrentFileLengths);
|
||||
}
|
||||
|
||||
private void digestSonarrFiles(List<Path> sonarrFiles) {
|
||||
sonarrFilesByLength = getFileLengthsMapFrom(sonarrFiles);
|
||||
throwIfDuplicatedSizes(sonarrFilesByLength);
|
||||
}
|
||||
|
||||
Map<Long, List<Path>> getFileLengthsMapFrom(List<Path> files) {
|
||||
|
@ -27,6 +33,11 @@ public class MissingFilesDetector {
|
|||
.collect(Collectors.groupingBy(p -> p.toFile().length()));
|
||||
}
|
||||
|
||||
private void throwIfDuplicatedSizes(Map<Long, List<Path>> torrentFileLengths) {
|
||||
if (hasFilesWithSameSize(torrentFileLengths))
|
||||
throw new InsecureScenario();
|
||||
}
|
||||
|
||||
boolean hasFilesWithSameSize(Map<Long, List<Path>> torrentFileLengths) {
|
||||
return torrentFileLengths
|
||||
.values()
|
||||
|
@ -44,8 +55,8 @@ public class MissingFilesDetector {
|
|||
return false;
|
||||
}
|
||||
|
||||
private List<Path> resolveMissingFiles(Map<Long, List<Path>> torrentFilesByLength) {
|
||||
return torrentFilesByLength.entrySet()
|
||||
private List<Path> resolveMissingFiles() {
|
||||
return torrentFileLengths.entrySet()
|
||||
.stream()
|
||||
.filter(this::missingAtDestination)
|
||||
.map(Map.Entry::getValue)
|
||||
|
@ -57,4 +68,5 @@ public class MissingFilesDetector {
|
|||
return !sonarrFilesByLength.containsKey(torrentFileEntry.getKey());
|
||||
}
|
||||
|
||||
private static final class InsecureScenario extends RuntimeException {}
|
||||
}
|
|
@ -10,7 +10,6 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QueueFixer {
|
||||
final static String IMPORT_FAILURE_BECAUSE_MATCHED_BY_ID = "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.";
|
||||
|
@ -43,7 +42,7 @@ public class QueueFixer {
|
|||
private List<Record> filterFailedImportsOfIdProblem(Collection<Record> records) {
|
||||
return records.stream()
|
||||
.filter(this::recordsWithImportFailureBecauseIdMatching)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
}
|
||||
|
||||
private boolean recordsWithImportFailureBecauseIdMatching(Record record) {
|
||||
|
|
Loading…
Reference in New Issue