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