diff options
| -rw-r--r-- | dotup/src/depot.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/dotup/src/depot.rs b/dotup/src/depot.rs index 6f18738..9fb156f 100644 --- a/dotup/src/depot.rs +++ b/dotup/src/depot.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use slotmap::SlotMap; | 1 | use slotmap::SlotMap; |
| 2 | use std::{ | 2 | use std::{ |
| 3 | collections::HashMap, | ||
| 3 | fs::Metadata, | 4 | fs::Metadata, |
| 4 | path::{Path, PathBuf}, | 5 | path::{Path, PathBuf}, |
| 5 | sync::Arc, | 6 | sync::Arc, |
| @@ -121,6 +122,7 @@ pub struct Depot { | |||
| 121 | shared: Arc<DepotShared>, | 122 | shared: Arc<DepotShared>, |
| 122 | // Maps the origin to the link | 123 | // Maps the origin to the link |
| 123 | links: SlotMap<LinkID, Link>, | 124 | links: SlotMap<LinkID, Link>, |
| 125 | links_by_origin: HashMap<PathBuf, LinkID>, | ||
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | impl Depot { | 128 | impl Depot { |
| @@ -195,6 +197,7 @@ fn depot_create(config: DepotConfig) -> Result<Depot> { | |||
| 195 | let mut depot = Depot { | 197 | let mut depot = Depot { |
| 196 | shared: Arc::new(depot_shared), | 198 | shared: Arc::new(depot_shared), |
| 197 | links: Default::default(), | 199 | links: Default::default(), |
| 200 | links_by_origin: Default::default(), | ||
| 198 | }; | 201 | }; |
| 199 | 202 | ||
| 200 | for archive_link in config.archive.links { | 203 | for archive_link in config.archive.links { |
| @@ -346,10 +349,16 @@ fn depot_uninstall_link(_depot: &Depot, link: &Link, install_base: &Path) -> Res | |||
| 346 | } | 349 | } |
| 347 | 350 | ||
| 348 | fn depot_insert_link(depot: &mut Depot, mut link: Link) -> LinkID { | 351 | fn depot_insert_link(depot: &mut Depot, mut link: Link) -> LinkID { |
| 349 | depot.links.insert_with_key(move |k| { | 352 | let origin = link.origin().to_path_buf(); |
| 353 | if let Some(link_id) = depot.links_by_origin.remove(&origin) { | ||
| 354 | depot.links.remove(link_id); | ||
| 355 | } | ||
| 356 | let link_id = depot.links.insert_with_key(move |k| { | ||
| 350 | link.id = k; | 357 | link.id = k; |
| 351 | link | 358 | link |
| 352 | }) | 359 | }); |
| 360 | depot.links_by_origin.insert(origin, link_id); | ||
| 361 | link_id | ||
| 353 | } | 362 | } |
| 354 | 363 | ||
| 355 | fn depot_links(depot: &Depot) -> impl Iterator<Item = &Link> { | 364 | fn depot_links(depot: &Depot) -> impl Iterator<Item = &Link> { |
