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<()> {
31
     // Find max score for normalization
31
     // Find max score for normalization
32
     let max_score = entries.iter().map(|(_, s)| *s).fold(0.0f64, f64::max);
32
     let max_score = entries.iter().map(|(_, s)| *s).fold(0.0f64, f64::max);
33
 
33
 
34
+    let total_found = entries.len();
35
+
34
     // Normalize and import
36
     // Normalize and import
37
+    let mut skipped = 0;
35
     for (path, score) in entries {
38
     for (path, score) in entries {
36
         // Scale score to 0-MAX_IMPORT_SCORE range
39
         // Scale score to 0-MAX_IMPORT_SCORE range
37
         let normalized = if max_score > 0.0 {
40
         let normalized = if max_score > 0.0 {
@@ -40,14 +43,20 @@ pub fn run() -> Result<()> {
40
             1.0
43
             1.0
41
         };
44
         };
42
 
45
 
43
-        if db.import_entry(&path, normalized.max(1.0)).is_ok() {
46
+        match db.import_entry(&path, normalized.max(1.0)) {
44
-            total_imported += 1;
47
+            Ok(()) => total_imported += 1,
48
+            Err(_) => skipped += 1,
45
         }
49
         }
46
     }
50
     }
47
 
51
 
48
     if total_imported > 0 {
52
     if total_imported > 0 {
49
         db.save()?;
53
         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);
51
     }
60
     }
52
 
61
 
53
     Ok(())
62
     Ok(())
src/db/store.rsmodified
@@ -159,7 +159,7 @@ impl Database {
159
 
159
 
160
     /// Import an entry with a specific score (for importing from zoxide).
160
     /// Import an entry with a specific score (for importing from zoxide).
161
     pub fn import_entry<P: AsRef<Path>>(&mut self, path: P, score: f64) -> Result<(), DatabaseError> {
161
     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)?;
163
 
163
 
164
         // Skip if excluded
164
         // Skip if excluded
165
         if self.is_excluded(&path) {
165
         if self.is_excluded(&path) {