diff --git a/lib/default.fl b/lib/default.fl index dc3546c..b060607 100644 --- a/lib/default.fl +++ b/lib/default.fl @@ -2,9 +2,7 @@ name="$(basename $2)" sakudir="${SAKUPATH:-"$HOME/.saku"}" flaskfile="$sakudir/flask/$1/$2.fl" srcdir="$sakudir/repo/$name" -root="$sakudir/root" store="$sakudir/store" -rootdir="$root/$name" storedir="$store/$name" pkgname="" diff --git a/lib/install.fl b/lib/install.fl index a41d4ca..d30ff01 100644 --- a/lib/install.fl +++ b/lib/install.fl @@ -1,29 +1,18 @@ -install_file() { - type="$1" - file="$2" +store() { + src="$srcdir/$1" + dst="$storedir/$2" - file_exists "$file" + [[ -f "$src" || -d "$src" ]] || die "src does not exist [$src]" - dst="$storedir/$type/$(basename $file)" mkdir -p "$(dirname $dst)" - echo "$file --> $dst" + echo "$src --> $dst" case $type in bin) - install -Dm 0755 $file $dst - ;; - *) - ;; - esac - - case $type in - bin|share) - lnk="$root/$type/$(basename $file)" - mkdir -p "$(dirname $lnk)" - echo "$lnk <-- $dst" - ln -sfT "$dst" "$lnk" + install -Dm 0755 "$src" "$dst" ;; *) + install -Dm 0644 "$src" "$dst" ;; esac } diff --git a/saku-lib/pkg/root.rs b/saku-lib/pkg/root.rs index 2513126..6bf15ab 100644 --- a/saku-lib/pkg/root.rs +++ b/saku-lib/pkg/root.rs @@ -3,11 +3,53 @@ use std::fs; use crate::prelude::*; use crate::exec; use crate::pkg::pkg::Pkg; +use crate::util::constants; +use crate::util::io; +use crate::util::msg; use crate::util::{filepath, path}; impl Pkg { pub fn install_root(&self) -> Result<()> { - exec::install(&self.name, &self.group) + self.store()?; + self.link_root()?; + Ok(()) + } + pub fn store(&self) -> Result<()> { + trace!("storing files"); + let has_artifacts = io::mkdir(path::store_dir(&self.name))?; + if has_artifacts { + debug!("cleaning up artifacts in store"); + std::fs::remove_dir_all(&path::store_dir(&self.name))?; + io::mkdir(path::store_dir(&self.name))?; + } + exec::install(&self.name, &self.group)?; + Ok(()) + } + pub fn link_root(&self) -> Result<()> { + trace!("linking root"); + let files = path::get_stored_files(&self.name)?; + debug!("{:?}", files); + for entry in &files { + self.link_entry(entry)?; + } + Ok(()) + } + pub fn link_entry(&self, path: &str) -> Result<()> { + if filepath::is_dir(&path) { + debug!("skipping dir {path}"); + return Ok(()); + } + let rel = filepath::get_relative(&path::store_dir(&self.name), path)?; + debug!("found {}", rel); + let root_path = filepath::join(&*constants::ROOT_DIR, &rel); + if filepath::exists(&root_path) { + debug!("root file already exists {root_path}. cleaning up"); + std::fs::remove_file(&root_path)?; + } + io::mkdir(filepath::parent_dir(&root_path)?)?; + msg::link(&path, &root_path); + io::link(&path, &root_path)?; + Ok(()) } pub fn uninstall_root(&self) -> Result<()> { for d in fs::read_dir(path::root_dir(&format!("{}/bin", self.name)))? {