Skip to content

Commit

Permalink
rework(install): rework root and store dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
comfysage committed Feb 5, 2024
1 parent ebc7314 commit d4406bf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
2 changes: 0 additions & 2 deletions lib/default.fl
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
25 changes: 7 additions & 18 deletions lib/install.fl
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
44 changes: 43 additions & 1 deletion saku-lib/pkg/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))? {
Expand Down

0 comments on commit d4406bf

Please sign in to comment.