Compare commits

...

2 Commits

Author SHA1 Message Date
Connor Johnstone 7ece462f58 added the cleanup, which was missing. also artist lookup first rather than search on import 2026-03-25 14:04:24 -04:00
Connor Johnstone 72a5fd3d14 fixed up the featured artist thing 2026-03-24 11:38:07 -04:00
2 changed files with 9 additions and 6 deletions
+4 -1
View File
@@ -10,5 +10,8 @@ pub mod sanitize;
pub mod template;
pub use error::{OrgError, OrgResult};
pub use organizer::{OrgConfig, OrgStats, organize_from_db, organize_from_directory, organize_track};
pub use organizer::{
OrgConfig, OrgStats, cleanup_empty_dirs, organize_from_db, organize_from_directory,
organize_track,
};
pub use template::DEFAULT_FORMAT;
+5 -5
View File
@@ -105,10 +105,10 @@ fn move_or_copy(source: &Path, target: &Path, copy: bool) -> OrgResult<()> {
Ok(())
}
/// Remove empty directories starting from `dir` and walking up, stopping at `stop_at`.
fn cleanup_empty_dirs(dir: &Path, stop_at: &Path) {
/// Remove empty directories starting from `dir` and walking up, stopping before `stop_at`.
pub fn cleanup_empty_dirs(dir: &Path, stop_at: &Path) {
let mut current = dir.to_owned();
while current != stop_at && current.starts_with(stop_at) {
while current.starts_with(stop_at) && current != *stop_at {
match std::fs::read_dir(&current) {
Ok(mut entries) => {
if entries.next().is_none() {
@@ -181,11 +181,11 @@ pub async fn organize_track(
};
queries::tracks::update_metadata(conn, track.id, active).await?;
// Cleanup empty source directory
// Cleanup empty source directories up to the library root
if !config.copy
&& let Some(dir) = source_dir
{
cleanup_empty_dirs(&dir, &dir);
cleanup_empty_dirs(&dir, &config.target_dir);
}
Ok(true)