Skip to content

Commit

Permalink
[Issue #178] Check that a directory has entries before searching it.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Mar 14, 2020
1 parent 9c6e380 commit cfb7507
Showing 1 changed file with 18 additions and 16 deletions.
Expand Up @@ -101,22 +101,24 @@ public List<FileDetails> getAllComicsUnder(final String rootDirectory) throws IO
private void loadFilesUnder(final List<FileDetails> files, final File directory)
throws IOException {
this.logger.debug("Loading files in directory: {}", directory);
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
this.loadFilesUnder(files, file);
} else {
if (ComicFileUtils.isComicFile(file)) {
final String filePath = file.getCanonicalPath();
final long fileSize = file.length();

final Comic comic = this.comicRepository.findByFilename(filePath);

if (comic != null) {
this.logger.debug("File already in the library: id={}", comic.getId());
} else {
this.logger.debug("Adding file: {} ({} bytes)", filePath, fileSize);

files.add(new FileDetails(filePath, fileSize));
if (directory.listFiles() != null) {
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
this.loadFilesUnder(files, file);
} else {
if (ComicFileUtils.isComicFile(file)) {
final String filePath = file.getCanonicalPath();
final long fileSize = file.length();

final Comic comic = this.comicRepository.findByFilename(filePath);

if (comic != null) {
this.logger.debug("File already in the library: id={}", comic.getId());
} else {
this.logger.debug("Adding file: {} ({} bytes)", filePath, fileSize);

files.add(new FileDetails(filePath, fileSize));
}
}
}
}
Expand Down

0 comments on commit cfb7507

Please sign in to comment.