diff --git a/mediarepo-daemon/Cargo.lock b/mediarepo-daemon/Cargo.lock index 1f4f5e0..fda4ce2 100644 --- a/mediarepo-daemon/Cargo.lock +++ b/mediarepo-daemon/Cargo.lock @@ -1219,7 +1219,7 @@ dependencies = [ [[package]] name = "mediarepo-daemon" -version = "0.12.0" +version = "0.13.0" dependencies = [ "console-subscriber", "glob", diff --git a/mediarepo-daemon/mediarepo-core/src/utils.rs b/mediarepo-daemon/mediarepo-core/src/utils.rs index 6217037..609f7c2 100644 --- a/mediarepo-daemon/mediarepo-core/src/utils.rs +++ b/mediarepo-daemon/mediarepo-core/src/utils.rs @@ -33,15 +33,14 @@ pub async fn get_folder_size(path: PathBuf) -> RepoResult { while !unchecked_dirs.is_empty() { let dir = unchecked_dirs.remove(0); - let mut read_dir = fs::read_dir(dir).await?; - while let Some(entry) = read_dir.next_entry().await? { - let file_type = entry.file_type().await?; - - if file_type.is_file() { - all_files.push(entry.path()); - } else if file_type.is_dir() { - unchecked_dirs.push(entry.path()) + match get_files_and_dirs_for_dir(&dir).await { + Ok((mut files, mut dirs)) => { + all_files.append(&mut files); + unchecked_dirs.append(&mut dirs); + } + Err(e) => { + tracing::warn!("failed to read entries for directory {:?}: {}", dir, e); } } } @@ -56,6 +55,25 @@ pub async fn get_folder_size(path: PathBuf) -> RepoResult { Ok(size) } +async fn get_files_and_dirs_for_dir(dir: &PathBuf) -> RepoResult<(Vec, Vec)> { + let mut files = Vec::new(); + let mut directories = Vec::new(); + + let mut read_dir = fs::read_dir(dir).await?; + + while let Some(entry) = read_dir.next_entry().await? { + let file_type = entry.file_type().await?; + + if file_type.is_file() { + files.push(entry.path()); + } else if file_type.is_dir() { + directories.push(entry.path()) + } + } + + Ok((files, directories)) +} + async fn read_file_size(path: PathBuf) -> RepoResult { let metadata = fs::metadata(path).await?;