tenseleyflow/gump / eaa264b

Browse files

canonicalize paths in import_entry, improve import diagnostics

Authored by espadonne
SHA
eaa264b241f7577be55ea7cb6097ecff84354699
Parents
1d3a347
Tree
cb21997

2 changed files

StatusFile+-
M src/cmd/import.rs 12 3
M src/db/store.rs 1 1
src/cmd/import.rsmodified
@@ -31,7 +31,10 @@ pub fn run() -> Result<()> {
3131
     // Find max score for normalization
3232
     let max_score = entries.iter().map(|(_, s)| *s).fold(0.0f64, f64::max);
3333
 
34
+    let total_found = entries.len();
35
+
3436
     // Normalize and import
37
+    let mut skipped = 0;
3538
     for (path, score) in entries {
3639
         // Scale score to 0-MAX_IMPORT_SCORE range
3740
         let normalized = if max_score > 0.0 {
@@ -40,14 +43,20 @@ pub fn run() -> Result<()> {
4043
             1.0
4144
         };
4245
 
43
-        if db.import_entry(&path, normalized.max(1.0)).is_ok() {
44
-            total_imported += 1;
46
+        match db.import_entry(&path, normalized.max(1.0)) {
47
+            Ok(()) => total_imported += 1,
48
+            Err(_) => skipped += 1,
4549
         }
4650
     }
4751
 
4852
     if total_imported > 0 {
4953
         db.save()?;
50
-        println!("Imported {} entries (scores normalized to 1-{})", total_imported, MAX_IMPORT_SCORE as u32);
54
+    }
55
+
56
+    println!("Found {} entries, imported {} (scores normalized to 1-{})",
57
+        total_found, total_imported, MAX_IMPORT_SCORE as u32);
58
+    if skipped > 0 {
59
+        println!("Skipped {} entries (excluded or unresolvable paths)", skipped);
5160
     }
5261
 
5362
     Ok(())
src/db/store.rsmodified
@@ -159,7 +159,7 @@ impl Database {
159159
 
160160
     /// Import an entry with a specific score (for importing from zoxide).
161161
     pub fn import_entry<P: AsRef<Path>>(&mut self, path: P, score: f64) -> Result<(), DatabaseError> {
162
-        let path = PathBuf::from(path.as_ref());
162
+        let path = self.canonicalize_path(path)?;
163163
 
164164
         // Skip if excluded
165165
         if self.is_excluded(&path) {