feat: Exclude .sync, .softlan_first_start_done, and local directories from root size calculation.
This commit is contained in:
@@ -1240,7 +1240,7 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
||||
None
|
||||
};
|
||||
|
||||
let size = calculate_directory_size(&path).await?;
|
||||
let size = calculate_directory_size(&path, true).await?;
|
||||
let game = Game {
|
||||
id: game_id.to_string(),
|
||||
name: game_id.to_string(),
|
||||
@@ -1288,16 +1288,28 @@ async fn local_dir_has_content(path: &Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
async fn calculate_directory_size(dir: &Path) -> eyre::Result<u64> {
|
||||
async fn calculate_directory_size(dir: &Path, is_root: bool) -> eyre::Result<u64> {
|
||||
let mut total_size = 0u64;
|
||||
let mut entries = tokio::fs::read_dir(dir).await?;
|
||||
|
||||
while let Some(entry) = entries.next_entry().await? {
|
||||
let path = entry.path();
|
||||
let name = entry.file_name();
|
||||
let name_str = name.to_string_lossy();
|
||||
|
||||
if is_root {
|
||||
if name_str == ".sync" || name_str == ".softlan_first_start_done" {
|
||||
continue;
|
||||
}
|
||||
if entry.file_type().await?.is_dir() && is_local_dir_name(&name_str) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let metadata = tokio::fs::metadata(&path).await?;
|
||||
|
||||
if metadata.is_dir() {
|
||||
total_size += Box::pin(calculate_directory_size(&path)).await?;
|
||||
total_size += Box::pin(calculate_directory_size(&path, false)).await?;
|
||||
} else {
|
||||
total_size += metadata.len();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user