Skip to content

Commit

Permalink
fix(lib/pkg/root): don;t remove entire store dir; instead remove arti…
Browse files Browse the repository at this point in the history
…fact dirs
  • Loading branch information
comfysage committed Feb 8, 2024
1 parent 4e7b016 commit 369f811
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions saku-lib/pkg/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ impl Pkg {
exec::unlink(&entry)?;
}
let store_path = path::store_dir(&self.name);
debug!("removing artifact {}", msg::general::path_f(&store_path));
io::rmdir(&store_path)?;
let dirs = path::get_artifact_dirs(&self.name)?;
for entry in dirs {
debug!("removing artifact {}", msg::general::path_f(&entry));
io::rmdir(&entry)?;
}
io::mkdir(store_path)?;
}
exec::install(&self.name, &self.group)?;
Expand Down
26 changes: 26 additions & 0 deletions saku-lib/util/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ pub fn get_stored_files(name: &str) -> Result<Vec<String>> {
Ok(files)
}

pub fn get_stored_dirs(name: &str) -> Result<Vec<String>> {
let mut dirs = vec![];
for d in fs::read_dir(store_dir(name))? {
let d = d?;
let d_path_bind = d.path();
let d_path = match d_path_bind.to_str() {
Some(s) => Ok(s),
None => Err(Error::Unexpected),
}?;
dirs.push(d_path.to_string());
}
Ok(dirs)
}

pub fn get_artifact_dirs(name: &str) -> Result<Vec<String>> {
let mut dirs = get_stored_dirs(name)?;
for i in 0..dirs.len() {
let p = dirs[i].clone();
if filepath::base_name(&p)? == "bin" {
dirs.remove(i);
return Ok(dirs);
}
}
Ok(dirs)
}

pub fn get_stored_bin(name: &str) -> Result<Vec<String>> {
let mut files = vec![];
let store_path = store_dir(name);
Expand Down

0 comments on commit 369f811

Please sign in to comment.