Skip to content

Commit

Permalink
Merge pull request #538 from kagemomiji/issue527-update-album-path
Browse files Browse the repository at this point in the history
#527 fix: Bug related to deletion of non-existent media files
  • Loading branch information
kagemomiji authored Jul 23, 2024
2 parents 9aac72a + e6d8249 commit b3b0dd5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion airsonic-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>4.0.3</version>
<version>4.0.4</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public List<MediaFile> findByFolderInAndMediaTypeAndYearBetweenAndPresentTrue(Li

public List<MediaFile> findByFolderAndParentPath(MusicFolder folder, String parentPath, Sort sort);

public List<MediaFile> findByFolderAndParentPathAndPresentTrue(MusicFolder folder, String parentPath);

public List<MediaFile> findByFolderAndParentPathAndPresentTrue(MusicFolder folder, String parentPath, Sort sort);

public List<MediaFile> findByFolderInAndMediaTypeAndArtistAndPresentTrue(List<MusicFolder> folders, MediaType mediaType, String artist);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,12 @@ public MediaFile delete(MediaFile file) {
file.setChildrenLastUpdated(Instant.ofEpochMilli(1));
mediaFileRepository.save(file);
coverArtService.delete(EntityType.MEDIA_FILE, file.getId());

// delete children recursively
if (file.isDirectory()) {
List<MediaFile> children = mediaFileRepository.findByFolderAndParentPathAndPresentTrue(file.getFolder(), file.getPath());
children.forEach(this::delete);
}
return file;
}

Expand Down Expand Up @@ -1705,5 +1711,4 @@ public String calcAlbumThirdCaption(HomeController.Album album, Locale locale) {
public void expunge() {
mediaFileRepository.deleteAllByPresentFalse();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ private void doScanLibrary(ForkJoinPool pool, MediaLibraryStatistics statistics)
}, pool)
.thenRunAsync(() -> LOG.info("Artist persistence complete"), pool);

LOG.info("Persisting media files");
CompletableFuture<Void> mediaFilePersistence = CompletableFuture
.runAsync(() -> {
LOG.info("Marking non-present media files.");
mediaFileService.markNonPresent(statistics.getScanDate());
}, pool)
.thenRunAsync(() -> LOG.info("Media file persistence complete"), pool);

LOG.info("Persisting genres");
CompletableFuture<Void> genrePersistence = CompletableFuture
.runAsync(() -> {
Expand All @@ -310,7 +318,7 @@ private void doScanLibrary(ForkJoinPool pool, MediaLibraryStatistics statistics)
LOG.info("Genre persistence successfully complete: {}", genresSuccessful);
}, pool);

CompletableFuture.allOf(albumPersistence, artistPersistence, genrePersistence).join();
CompletableFuture.allOf(albumPersistence, artistPersistence, mediaFilePersistence, genrePersistence).join();
LOG.info("Completed media library scan.");

} catch (Throwable x) {
Expand Down Expand Up @@ -430,6 +438,9 @@ private void updateAlbum(MediaFile parent, MediaFile file, MusicFolder musicFold
albumsInDb.add(dbAlbum.getId());
dbAlbum.setDuration(0);
dbAlbum.setSongCount(0);
if (dbAlbum.getPath() != file.getParentPath()) {
dbAlbum.setPath(file.getParentPath());
}
}
return dbAlbum;
}).orElse(null);
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<version>3.3.2</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<version>3.15.0</version>
</dependency>
<dependency>
<groupId>org.seamless</groupId>
Expand Down

0 comments on commit b3b0dd5

Please sign in to comment.