Skip to content

Commit

Permalink
- optimize cache path return
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Nov 24, 2024
1 parent 24d6795 commit 80282b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 4 additions & 10 deletions src/cmd/renc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,10 @@ impl<'a> CompleteProfile<'a> {
.build_instance()
.makeup(&ctx, identity)?
.iter()
.try_for_each(|i| {
let host_cache = {
let mut root = flake_root.clone();
root.push(cache_path.clone());
root.push(i);
root
}
.canonicalize()?;
info!("storing cache: {}", host_cache.display());
let o = add_to_store(host_cache)?;
.try_for_each(|p| {
let cache = p.canonicalize()?;
info!("storing cache: {}", cache.display());
let o = add_to_store(cache)?;
if !o.status.success() {
error!("Command executed with failing error code");
// Another side, calculate with nix `builtins.path` and pass to when deploy as `storage`
Expand Down
15 changes: 9 additions & 6 deletions src/util/makeup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
collections::HashSet,
iter,
path::PathBuf,
rc::Rc,
str::FromStr,
sync::{Arc, Mutex},
Expand Down Expand Up @@ -32,7 +33,7 @@ impl<'a> RencInstance<'a> {
self,
ctx_agenc: &RencCtx<'a, AgeEnc>,
ident: Box<dyn Identity>,
) -> Result<HashSet<String>> {
) -> Result<HashSet<PathBuf>> {
let key: Rc<dyn Identity> = Rc::from(ident);

let material = &self.inner().into_read_only();
Expand All @@ -41,7 +42,7 @@ impl<'a> RencInstance<'a> {

use std::io::Write;

let res: Arc<Mutex<Vec<eyre::Result<&str>>>> = Arc::new(Mutex::new(Vec::new()));
let res: Arc<Mutex<Vec<eyre::Result<PathBuf>>>> = Arc::new(Mutex::new(Vec::new()));

debug!(
"total {} host(s) need to re-encrypt",
Expand Down Expand Up @@ -80,7 +81,7 @@ impl<'a> RencInstance<'a> {
e @ Err(_) => {
res.lock()
.expect("doesn't matter now")
.push(e.map(|_| h.id()));
.push(e.map(|_| PathBuf::default()));
return;
}
},
Expand Down Expand Up @@ -146,7 +147,7 @@ impl<'a> RencInstance<'a> {
e @ Err(_) => {
res.lock()
.expect("doesn't matter now")
.push(e.map(|_| h.id()));
.push(e.map(|_| PathBuf::default()));
return;
}
};
Expand All @@ -156,7 +157,9 @@ impl<'a> RencInstance<'a> {
.expect("doesn't matter now")
.push(Err(eyre!("write cache file failed")))
};
res.lock().expect("thread work end").push(Ok(h.id()));
res.lock()
.expect("thread work end")
.push(Ok(inrepo_path.path.clone()));
}
});
});
Expand All @@ -177,7 +180,7 @@ impl<'a> RencInstance<'a> {
.filter(|i| i.is_ok())
.map(|i| {
if let Ok(o) = i {
String::from(*o)
o.clone()
} else {
unreachable!()
}
Expand Down

0 comments on commit 80282b3

Please sign in to comment.