I devoted some time to the issue, and produced my version, called untcz.
tcz-unload is not very error-tolerant: just pass it the argument
$package/ (trailing slash) and it umounts extension without unlinking.
tcztools is even worse, I don't like its approach at all.
Plus, lsof complexity can be avoided.
In my script, this is done by directly umounting, and giving up on umount error.
To do this, I have to postpone unlinking after umounting.
This requires saving a list of to-do unlinks somewhere.
The drawback is that I need temp space on filesystem, and it can go up to megs
for biggest extensions (texlive.tcz, a custom extension I took as testbench for its size).
The highligts are:
- more robust fault tolerance: you shouldn't get umount without
unlinking done
- no relevant speed loss with this approach: taking my texlive.tcz as a testbench,
I got 1m30s with tcz-unload, and 1m36s with untcz
- the user can decide to remove all directories emptied in the process.
For some private-directories-rich extensions, like texlive, this is important.
In this case untcz-ing time increases.
- less complexity (smaller than tcz-unload, and it can be reduced pruning
comments and debug lines)
- corrected umount -d bug reported above
Anyway, from a time complexity point of view, the problem seems hard
if confined to scripting.
I have another approach in mind, if I have time I will give it a shot.
Performance aside, the following issues remain:
- - While tinycore provides the /usr/local/tce.installed/script to do load management tasks, there is no mechanism to do the symmetrical tasks when unloading.
- - No check if there are extensions depending on the one being unloaded.
This is would be best done via an external wrapper, in my opinion.
Hoping it helps, here is my untcz, comments and reports welcome:
#!/bin/sh
# Copyright 2011 Marco Caminati. Released under GPLv3.
# Pass any content to $keepdir to prevent deleting the directories emptied in the process
set -e
set -u
set -x
b=busybox
name=`$b echo "$1" | $b sed -e 's_/*$__' | $b egrep -o "[^/]*$"`
tmpd=/tmp/untcz
mntdir=/tmp/tcloop/$name
keepdir="${keepdir:-}"
cd $tmpd 2>/dev/null && exit 1
$b mkdir -p "$tmpd"
cd "$tmpd"
find "${mntdir}" ! -type d | while read i
do
i=/${i#*$mntdir}
readlink "$i" | egrep -q "^/*${mntdir}/" && echo "$i" >> ${tmpd}/links
done || exit 4
[ "$keepdir" ] || find "${mntdir}" -type d | sed = | sed 'N;s/\n/ /' | sort -nr | cut -f 2- -d " " > dirs
#sort -nr is due to the way rmdir -p works
$b umount -d $mntdir || exit 5
#starting with umount, it is safer to fallback to busybox to avoid using what we are untczing
$b cat links | while read i do
do
sudo $b rm "$i"
done || exit 6
$b rm links
$b cat dirs | while read i
do
i=/${i#*$mntdir}
sudo $b rmdir -p "$i" || true
done || exit 8
$b rm dirs || true
cd /usr/local/tce.installed || exit 2
$b find -maxdepth 1 -size +0c | $b egrep -q "${name}" && exit 7
# Debugline for inner consistency check
$b rm "${name}" || true
$b rmdir "${tmpd}"
$b rmdir "${mntdir}"
Please note that this is an alpha version. Try it at your risk.