Compare commits
2 Commits
0a0fa18bfa
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ece462f58 | |||
| 72a5fd3d14 |
+4
-1
@@ -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
@@ -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(¤t) {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user