aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2021-07-09 02:43:59 -0400
committerdiogo464 <[email protected]>2021-07-09 02:43:59 -0400
commit29a6a6a836e5966ab2a57a5ea97e455a27a11acf (patch)
tree43b7c815ae0b40928dfb091e2ba265c810f734e4
parentc0ef13ca78390fe5176eeb8fca3b35e4bf1f64a2 (diff)
Made links unique by origin.
Inserting a new link with a new link with an with an origin that already exists will replace the old link with that same origin.
-rw-r--r--dotup/src/depot.rs13
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 @@
1use slotmap::SlotMap; 1use slotmap::SlotMap;
2use std::{ 2use 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
126impl Depot { 128impl 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
348fn depot_insert_link(depot: &mut Depot, mut link: Link) -> LinkID { 351fn 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
355fn depot_links(depot: &Depot) -> impl Iterator<Item = &Link> { 364fn depot_links(depot: &Depot) -> impl Iterator<Item = &Link> {