Skip to content

Commit

Permalink
~ refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Nov 22, 2024
1 parent fd6952a commit 412b411
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
13 changes: 6 additions & 7 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
collections::HashMap,
fs::{self, Permissions, ReadDir},
io::{self, ErrorKind},
iter,
os::unix::fs::PermissionsExt,
path::PathBuf,
rc::Rc,
Expand Down Expand Up @@ -155,7 +156,7 @@ impl Profile {

let templates = self.templates.iter().filter(|i| if_early(i.0));

let complete = CompleteProfile(vec![self]);
let complete = CompleteProfile::from_iter(iter::once(self));
let ctx = RencCtx::create(&complete);

let plain_map = RencBuilder::create(&complete)
Expand All @@ -178,8 +179,8 @@ impl Profile {
))
.inspect(|p| {
fs::set_permissions(p, Permissions::from_mode(0o751))
.wrap_err(eyre!("set permission"))
.expect("set permission");
.wrap_err(eyre!("set permission failed"))
.unwrap();
})?
};
macro_rules! generate_dst {
Expand Down Expand Up @@ -297,10 +298,8 @@ impl Profile {

match std::fs::remove_file(symlink_dst) {
Err(e) if e.kind() == io::ErrorKind::NotFound => {}
Err(e) => Err(eyre!("{}", e))?,
Ok(_) => {
debug!("old symlink removed");
}
e @ Err(_) => e?,
_ => debug!("old symlink removed"),
}

info!(
Expand Down
12 changes: 5 additions & 7 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ impl Args {
match &self.app {
SubCmd::Renc(RencSubCmd { identity, cache }) => {
debug!("start re-encrypt secrets");
let real_profile = profile()?;
let profile: Vec<&Profile> = real_profile.iter().collect();
CompleteProfile::from(profile).renc(
flake_root.clone(),
let profile = profile()?;
CompleteProfile::from_iter(&profile).renc(
flake_root,
identity.clone(),
cache.into(),
)
Expand All @@ -123,9 +122,8 @@ impl Args {
}
SubCmd::Check(_) => {
info!("start checking");
let real_profile = profile()?;
let profile = real_profile.iter().collect();
CompleteProfile(profile).check()?;
let profile = profile()?;
CompleteProfile::from_iter(&profile).check()?;
info!("check complete");
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/renc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::{fs, path::PathBuf};

pub struct CompleteProfile<'a>(pub Vec<&'a Profile>);

impl<'a> From<Vec<&'a Profile>> for CompleteProfile<'a> {
fn from(value: Vec<&'a Profile>) -> Self {
Self(value)
impl<'a> FromIterator<&'a Profile> for CompleteProfile<'a> {
fn from_iter<T: IntoIterator<Item = &'a Profile>>(iter: T) -> Self {
iter.into_iter().collect()
}
}

Expand Down

0 comments on commit 412b411

Please sign in to comment.