Compare commits
1 Commits
72a5fd3d14
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ece462f58 |
+2
-1
@@ -11,6 +11,7 @@ pub mod template;
|
|||||||
|
|
||||||
pub use error::{OrgError, OrgResult};
|
pub use error::{OrgError, OrgResult};
|
||||||
pub use organizer::{
|
pub use organizer::{
|
||||||
OrgConfig, OrgStats, organize_from_db, organize_from_directory, organize_track,
|
OrgConfig, OrgStats, cleanup_empty_dirs, organize_from_db, organize_from_directory,
|
||||||
|
organize_track,
|
||||||
};
|
};
|
||||||
pub use template::DEFAULT_FORMAT;
|
pub use template::DEFAULT_FORMAT;
|
||||||
|
|||||||
+5
-5
@@ -105,10 +105,10 @@ fn move_or_copy(source: &Path, target: &Path, copy: bool) -> OrgResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove empty directories starting from `dir` and walking up, stopping at `stop_at`.
|
/// Remove empty directories starting from `dir` and walking up, stopping before `stop_at`.
|
||||||
fn cleanup_empty_dirs(dir: &Path, stop_at: &Path) {
|
pub fn cleanup_empty_dirs(dir: &Path, stop_at: &Path) {
|
||||||
let mut current = dir.to_owned();
|
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) {
|
match std::fs::read_dir(¤t) {
|
||||||
Ok(mut entries) => {
|
Ok(mut entries) => {
|
||||||
if entries.next().is_none() {
|
if entries.next().is_none() {
|
||||||
@@ -181,11 +181,11 @@ pub async fn organize_track(
|
|||||||
};
|
};
|
||||||
queries::tracks::update_metadata(conn, track.id, active).await?;
|
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
|
if !config.copy
|
||||||
&& let Some(dir) = source_dir
|
&& let Some(dir) = source_dir
|
||||||
{
|
{
|
||||||
cleanup_empty_dirs(&dir, &dir);
|
cleanup_empty_dirs(&dir, &config.target_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user