summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-12-09 12:30:42 +0800
committer魏曹先生 <1992414357@qq.com>2025-12-09 12:30:42 +0800
commitc740e28bd851221f32dc3f48cd94ee78352bba93 (patch)
tree2c8f8d068c39375e56d7621b47e115e1ee5096c4 /src/bin
parent1d1a1009ba795d70c0c06a2ffcc607c5704bf675 (diff)
Fix `jvv here` display for vault size calculation
Add timeout handling and proper file counting for virtual files Display progress message when calculation takes too long Add error message for size calculation failures
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/jvv.rs60
1 files changed, 51 insertions, 9 deletions
diff --git a/src/bin/jvv.rs b/src/bin/jvv.rs
index 3e32fa7..644a576 100644
--- a/src/bin/jvv.rs
+++ b/src/bin/jvv.rs
@@ -373,22 +373,64 @@ async fn jvv_here(_args: HereArgs) {
};
// Get sheet count
- let num_sheets = vault.sheets().await.iter().len();
+ let num_sheets = vault.sheet_names().unwrap().iter().len();
- // Get virtual file count
+ // Get virtual file count and total size recursively
let virtual_file_root = vault.virtual_file_storage_dir();
let mut num_vf = 0;
let mut total_size = 0;
- if let Ok(mut entries) = fs::read_dir(&virtual_file_root).await {
- while let Ok(Some(entry)) = entries.next_entry().await {
- if let Ok(metadata) = entry.metadata().await
- && metadata.is_file()
- {
- num_vf += 1;
- total_size += metadata.len();
+ // Recursive function to calculate total size and count files with specific name
+ async fn calculate_total_size_and_vf_count(
+ path: std::path::PathBuf,
+ file_count: &mut u64,
+ total_size: &mut u64,
+ ) -> std::io::Result<()> {
+ let mut entries = fs::read_dir(&path).await?;
+ while let Some(entry) = entries.next_entry().await? {
+ let metadata = entry.metadata().await?;
+ if metadata.is_file() {
+ *total_size += metadata.len();
+ // Check if file name matches SERVER_NAME_VF_META
+ if entry.file_name() == just_enough_vcs::vcs::constants::SERVER_NAME_VF_META {
+ *file_count += 1;
+ }
+ } else if metadata.is_dir() {
+ Box::pin(calculate_total_size_and_vf_count(
+ entry.path(),
+ file_count,
+ total_size,
+ ))
+ .await?;
}
}
+ Ok(())
+ }
+
+ // Calculate with timeout
+ let timeout_duration = std::time::Duration::from_millis(1200);
+ let size_result = tokio::time::timeout(timeout_duration, async {
+ calculate_total_size_and_vf_count(virtual_file_root.clone(), &mut num_vf, &mut total_size)
+ .await
+ })
+ .await;
+
+ match size_result {
+ Ok(Ok(_)) => {
+ // Calculation completed within timeout
+ }
+ Ok(Err(e)) => {
+ eprintln!(
+ "{}",
+ t!("jvv.fail.here.size_calc_error", error = e.to_string()).trim()
+ );
+ return;
+ }
+ Err(_) => {
+ // Timeout occurred
+ println!("{}", t!("jvv.info.here.analyzing_size").trim());
+ // Continue with partial calculation (num_vf and total_size as calculated so far)
+ }
}
// Get member count