Calculate the total size of a directory in bytes
(path: &std::path::Path)
| 33 | |
| 34 | /// Calculate the total size of a directory in bytes |
| 35 | async fn calculate_folder_size(path: &std::path::Path) -> Result<u64> { |
| 36 | let mut total_size = 0u64; |
| 37 | let mut dirs_to_process = vec![path.to_path_buf()]; |
| 38 | |
| 39 | while let Some(current_dir) = dirs_to_process.pop() { |
| 40 | let mut entries = tokio::fs::read_dir(¤t_dir).await?; |
| 41 | |
| 42 | while let Some(entry) = entries.next_entry().await? { |
| 43 | let metadata = entry.metadata().await?; |
| 44 | if metadata.is_file() { |
| 45 | total_size += metadata.len(); |
| 46 | } else if metadata.is_dir() { |
| 47 | dirs_to_process.push(entry.path()); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | Ok(total_size) |
| 53 | } |
| 54 | |
| 55 | /// Create a profile archive from the profile folder and return its md5 hash encoded in base64 |
| 56 | /// |
no test coverage detected