Fixed bugs with previous commit and further improved performance.
-- It actually works this time. "-links +1" parameter was removed in find, since we're no longer looking for hardlinks specifically. duh -- Link cache reordered. -- Miscellaneous refactoring.
This commit is contained in:
parent
77315a9782
commit
91a4cb9173
2 changed files with 57 additions and 71 deletions
7
sbcreate
7
sbcreate
|
@ -127,8 +127,7 @@ init_struct () {
|
||||||
$INSTANCE_ROOT/etc \
|
$INSTANCE_ROOT/etc \
|
||||||
$INSTANCE_ROOT/var/lib/pacman \
|
$INSTANCE_ROOT/var/lib/pacman \
|
||||||
$INSTANCE_ROOT/etc/pacman.d/ \
|
$INSTANCE_ROOT/etc/pacman.d/ \
|
||||||
$INSTANCE_ROOT/etc/fonts/conf.d \
|
$INSTANCE_ROOT/etc/fonts/conf.d
|
||||||
$SANDBOX_BASE/etc/db/$SANDBOX
|
|
||||||
|
|
||||||
cp $SANDBOX_BASE/etc/pacman.conf $INSTANCE_ROOT/etc/pacman.conf
|
cp $SANDBOX_BASE/etc/pacman.conf $INSTANCE_ROOT/etc/pacman.conf
|
||||||
cp $SANDBOX_BASE/etc/pacman.conf $SANDBOX_BASE/etc/pacman.d/pacman.$SANDBOX.conf
|
cp $SANDBOX_BASE/etc/pacman.conf $SANDBOX_BASE/etc/pacman.d/pacman.$SANDBOX.conf
|
||||||
|
@ -154,7 +153,7 @@ init_struct () {
|
||||||
|
|
||||||
if [[ $ISDEP ]]; then
|
if [[ $ISDEP ]]; then
|
||||||
cp $SANDBOX_BASE/etc/pacman.tpl.conf $SANDBOX_BASE/etc/pacman.d/tpl/pacman.$SANDBOX.conf
|
cp $SANDBOX_BASE/etc/pacman.tpl.conf $SANDBOX_BASE/etc/pacman.d/tpl/pacman.$SANDBOX.conf
|
||||||
mkdir -p
|
mkdir -p $SANDBOX_BASE/etc/db/$SANDBOX
|
||||||
touch $INSTANCE_ROOT/.dep
|
touch $INSTANCE_ROOT/.dep
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -167,7 +166,7 @@ init_chroot () {
|
||||||
--config $INSTANCE_ROOT/etc/$PACMAN_CONFIG \
|
--config $INSTANCE_ROOT/etc/$PACMAN_CONFIG \
|
||||||
--cache /var/lib/cache/pacman/pkg \
|
--cache /var/lib/cache/pacman/pkg \
|
||||||
base lib32-glibc --noconfirm 2>/dev/null
|
base lib32-glibc --noconfirm 2>/dev/null
|
||||||
sbupdate -fbns $SANDBOX
|
sbupdate -fbns
|
||||||
}
|
}
|
||||||
|
|
||||||
finalise () {
|
finalise () {
|
||||||
|
|
121
sbupdate
121
sbupdate
|
@ -60,35 +60,35 @@ main () {
|
||||||
|
|
||||||
local roots=
|
local roots=
|
||||||
local rootdeps=
|
local rootdeps=
|
||||||
|
local baserootdeps=
|
||||||
|
|
||||||
init_vars
|
init_vars
|
||||||
|
|
||||||
if [[ $SWITCH == *g* ]] && [[ $SWITCH == *b* ]]; then
|
if [[ $SWITCH == *v* ]]; then
|
||||||
generate_pacman_conf $roots
|
log "$BOLD$(basename $BASH_SOURCE)$RESET version 0.8 beta. Copyright 2023 Xavier M."
|
||||||
fi
|
log "Licensed under (to be specified) license, see LICENSE file for details."
|
||||||
|
exit
|
||||||
if [[ $SWITCH != *b* ]]; then
|
|
||||||
log $BAR "Update on sandbox dependencies \n\n$rootdeps\n"
|
|
||||||
if [[ "$(query_confirm "Proceed with update?")" ]]; then
|
|
||||||
generate_pacman_conf $rootdeps
|
|
||||||
update $rootdeps
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $SWITCH == *f* ]]; then
|
if [[ $SWITCH == *g* ]] && [[ $SWITCH == *b* ]]; then
|
||||||
log $BAR "Synchronizing for the first time..."
|
generate_pacman_conf ${ARGS[@]}
|
||||||
update_links $roots
|
|
||||||
update_link_lists $roots
|
|
||||||
update_link_lists $roots
|
|
||||||
log $BAR_GREEN "Synchronization complete!"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $SWITCH != *b* ]]; then
|
||||||
|
log $BAR "Update dependencies \n\n$baserootdeps$rootdeps\n"
|
||||||
|
|
||||||
|
if [[ "$(query_confirm "Proceed with update?")" ]]; then
|
||||||
|
generate_pacman_conf $baserootdeps$rootdeps
|
||||||
|
update $baserootdeps$rootdeps
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $SWITCH == *s* ]] || [[ $SYNCREQ == 1 ]]; then
|
if [[ $SWITCH == *s* ]] || [[ $SYNCREQ == 1 ]]; then
|
||||||
log $BAR "Synchronization event triggered..."
|
log $BAR "Synchronization event triggered..."
|
||||||
update_link_lists $rootdeps$roots
|
generate_cache $baserootdeps
|
||||||
update_links $rootdeps$roots
|
update_links $rootdeps$roots
|
||||||
update_link_lists $rootdeps$roots
|
cleanup_cache $rootdeps$baserootdeps
|
||||||
log $BAR_GREEN "Synchronization complete!"
|
log $BAR_GREEN "Synchronization complete!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -102,12 +102,8 @@ main () {
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_args () {
|
parse_args () {
|
||||||
ARGS=()
|
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
case $var in
|
case $var in
|
||||||
--first-time|-f)
|
|
||||||
SWITCH=f$SWITCH
|
|
||||||
;;
|
|
||||||
--generate-config|-g)
|
--generate-config|-g)
|
||||||
SWITCH=g$SWITCH
|
SWITCH=g$SWITCH
|
||||||
;;
|
;;
|
||||||
|
@ -119,7 +115,7 @@ parse_args () {
|
||||||
;;
|
;;
|
||||||
--sync|-s)
|
--sync|-s)
|
||||||
SWITCH=s$SWITCH
|
SWITCH=s$SWITCH
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
SWITCH=$(echo $var | cut -c 2-)
|
SWITCH=$(echo $var | cut -c 2-)
|
||||||
;;
|
;;
|
||||||
|
@ -132,71 +128,67 @@ parse_args () {
|
||||||
|
|
||||||
init_vars() {
|
init_vars() {
|
||||||
local rootlist=$(ls -U -1F $INSTANCE_ROOT | grep -i "/" | tr -d "/")
|
local rootlist=$(ls -U -1F $INSTANCE_ROOT | grep -i "/" | tr -d "/")
|
||||||
local list=${ARGS[@]}
|
|
||||||
|
|
||||||
|
|
||||||
if [[ $list ]]; then
|
|
||||||
roots=$list
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
for f in $rootlist; do
|
for f in $rootlist; do
|
||||||
if [[ -f $INSTANCE_ROOT/$f/.dep ]] || [[ -f $INSTANCE_ROOT/$f/.root ]]; then
|
if [[ -f $INSTANCE_ROOT/$f/.root ]]; then
|
||||||
|
baserootdeps+="$f "
|
||||||
|
elif [[ -f $INSTANCE_ROOT/$f/.dep ]]; then
|
||||||
rootdeps+="$f "
|
rootdeps+="$f "
|
||||||
else
|
else
|
||||||
roots+="$f "
|
roots+="$f "
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
invoke_link_deletion() {
|
invoke_link_deletion() {
|
||||||
local pwd=$PWD
|
local pwd=$PWD
|
||||||
local file_old=$link/$item.zst
|
local file_old=$link/$item.old.zst
|
||||||
local file_new=$link/$item.new.zst
|
local file_new=$link/$item.zst
|
||||||
local delfiles=$(diff --unchanged-group-format= --new-line-format='%L' \
|
|
||||||
-biw <(echo "$(zstd -fd < $file_new)") <(echo "$(zstd -fd < $file_old)"))
|
([[ ! -f $file_new ]] || [[ ! -f $file_old ]]) && return
|
||||||
|
|
||||||
cd $root/usr
|
cd $root/usr
|
||||||
echo $delfiles | xargs rm -f
|
diff --unchanged-group-format= --new-line-format='%L' \
|
||||||
|
-biw <(echo "$(zstd -fd < $file_new)") <(echo "$(zstd -fd < $file_old)") | xargs rm -f
|
||||||
cd $pwd
|
cd $pwd
|
||||||
}
|
}
|
||||||
|
|
||||||
invoke_update_link() {
|
invoke_update_link() {
|
||||||
local sandbox=$1
|
local sandbox=$1
|
||||||
local root=$INSTANCE_ROOT/$sandbox
|
|
||||||
|
|
||||||
if [[ ${synced[$sandbox]} ]]; then
|
if [[ ${synced[$sandbox]} ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [[ -f $root/.root ]]; then
|
if [[ -f $INSTANCE_ROOT/$sandbox/.root ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local dep=$(return_dependency)
|
|
||||||
local linkfiles=${LINKFILES[@]}
|
local linkfiles=${LINKFILES[@]}
|
||||||
|
|
||||||
log $ARROW "Synchronizing links for dependency $BOLD$dep$RESET in $BOLD$sandbox$RESET...$RESET"
|
log $ARROW "Synchronizing links for dependency $BOLD$dep$RESET in $BOLD$sandbox$RESET...$RESET"
|
||||||
|
|
||||||
|
local dep=$(return_dependency)
|
||||||
|
|
||||||
if [[ $SWITCH != *f* ]]; then
|
if [[ $SWITCH != *f* ]]; then
|
||||||
for item in ${linkfiles[@]}; do
|
for item in ${linkfiles[@]}; do
|
||||||
local root=$INSTANCE_ROOT/$sandbox
|
local root=$INSTANCE_ROOT/$sandbox
|
||||||
local link=$INSTANCE_DB_ROOT/$sandbox
|
local link=$INSTANCE_DB_ROOT/$dep
|
||||||
invoke_link_deletion
|
invoke_link_deletion
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for item in ${linkfiles[@]}; do
|
for item in ${linkfiles[@]}; do
|
||||||
local link=$INSTANCE_DB_ROOT/$dep
|
|
||||||
local root=$INSTANCE_ROOT/$sandbox
|
local root=$INSTANCE_ROOT/$sandbox
|
||||||
local source=$INSTANCE_ROOT/$dep
|
local source=$INSTANCE_ROOT/$dep
|
||||||
local target=$item
|
local src=$source/usr/$item
|
||||||
local src=$source/usr/$target
|
|
||||||
local dest=$root/usr/
|
local dest=$root/usr/
|
||||||
|
|
||||||
cp -flR $src $dest 2>/dev/null
|
cp -flR $src $dest 2>/dev/null
|
||||||
log " Synchronization complete for $BOLD$item$RESET in $BOLD$sandbox$RESET!"
|
log " Synchronization complete for $BOLD$item$RESET in $BOLD$sandbox$RESET!"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ -f $INSTANCE_ROOT/$sandbox/.dep ]]; then
|
||||||
|
generate_cache $sandbox
|
||||||
|
fi
|
||||||
synced[$sandbox]=1
|
synced[$sandbox]=1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,47 +206,42 @@ update_links() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
invoke_place_link_list() {
|
cleanup_cache() {
|
||||||
local dep=$sandbox
|
for sandbox in "$@"; do
|
||||||
local linkfiles=${LINKFILES[@]}
|
check_root "cache file operation"
|
||||||
|
[[ $? == 1 ]] && continue
|
||||||
|
|
||||||
for item in ${linkfiles[@]}; do
|
local linkfiles=${LINKFILES[@]}
|
||||||
local link=$INSTANCE_DB_ROOT/$sandbox
|
|
||||||
local target=$item
|
for item in ${linkfiles[@]}; do
|
||||||
|
rm $INSTANCE_DB_ROOT/$sandbox/$item.old.zst
|
||||||
rm $link/$target.zst
|
done
|
||||||
mv $link/$target.new.zst $link/$target.zst
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
invoke_update_link_list() {
|
invoke_generate_cache() {
|
||||||
local dep=$sandbox
|
local dep=$sandbox
|
||||||
local linkfiles=${LINKFILES[@]}
|
local linkfiles=${LINKFILES[@]}
|
||||||
|
|
||||||
for item in ${linkfiles[@]}; do
|
for item in ${linkfiles[@]}; do
|
||||||
local root=$INSTANCE_ROOT/$sandbox
|
local root=$INSTANCE_ROOT/$sandbox
|
||||||
local link=$INSTANCE_DB_ROOT/$sandbox
|
local link=$INSTANCE_DB_ROOT/$sandbox
|
||||||
local target=$item
|
|
||||||
local rdir=$root/usr/
|
local rdir=$root/usr/
|
||||||
local tdir=$root/usr/$target
|
local tdir=$root/usr/$item
|
||||||
|
|
||||||
find $tdir -type f,l -links +1 | sed -z "s,$rdir,,g" | zstd -fq -o $link/$target.new.zst
|
mv $link/$item.zst $link/$item.old.zst
|
||||||
|
find $tdir -type f,l | sed -z "s,$rdir,,g" | zstd -fq -o $link/$item.zst
|
||||||
done
|
done
|
||||||
log $ARROW_GREEN "Link Cache generated for $BOLD$sandbox$RESET!"
|
log $ARROW_GREEN "Generated link cache for $BOLD$sandbox$RESET!"
|
||||||
}
|
}
|
||||||
|
|
||||||
update_link_lists() {
|
generate_cache() {
|
||||||
for sandbox in "$@"; do
|
for sandbox in "$@"; do
|
||||||
check_root "cache"
|
check_root "cache"
|
||||||
[[ $? == 1 ]] && continue
|
[[ $? == 1 ]] && continue
|
||||||
|
|
||||||
if [[ $PLACE ]]; then
|
invoke_generate_cache
|
||||||
invoke_place_link_list
|
|
||||||
else
|
|
||||||
invoke_update_link_list
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
PLACE=1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_root() {
|
check_root() {
|
||||||
|
|
Loading…
Reference in a new issue