2015-07-06 09:47:52 +02:00
|
|
|
# Scan srcpkgs/*/template for hashes and distfiles to determine
|
|
|
|
# obsolete sources/by_sha256 files and their corresponding
|
|
|
|
# sources/<pkgname>-<version> files that can be purged
|
|
|
|
|
|
|
|
|
|
|
|
purge_distfiles() {
|
2018-06-23 16:28:04 +02:00
|
|
|
readonly HASHLEN=64
|
2015-07-06 09:47:52 +02:00
|
|
|
if [ -z "$XBPS_SRCDISTDIR" ]; then
|
|
|
|
msg_error "The variable \$XBPS_SRCDISTDIR is not set."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
#
|
2015-12-03 18:23:15 +01:00
|
|
|
# Scan all templates for their current distfiles and checksums (hashes)
|
2015-07-06 09:47:52 +02:00
|
|
|
#
|
|
|
|
declare -A my_hashes
|
|
|
|
templates=(srcpkgs/*/template)
|
|
|
|
max=${#templates[@]}
|
|
|
|
cur=0
|
|
|
|
if [ -z "$max" ]; then
|
|
|
|
msg_error "No srcpkgs/*/template files found. Wrong working directory?"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-07-20 15:25:21 +02:00
|
|
|
percent=-1
|
2015-07-06 09:47:52 +02:00
|
|
|
for template in ${templates[@]}; do
|
2015-09-05 07:41:58 +02:00
|
|
|
pkg=${template#*/}
|
|
|
|
pkg=${pkg%/*}
|
2015-07-06 09:47:52 +02:00
|
|
|
if [ ! -L "srcpkgs/$pkg" ]; then
|
2018-06-23 16:28:04 +02:00
|
|
|
checksum="$(grep -Ehrow [0-9a-f]{$HASHLEN} ${template}|sort|uniq)"
|
2015-07-06 09:47:52 +02:00
|
|
|
read -a _my_hashes <<< ${checksum}
|
|
|
|
i=0
|
|
|
|
while [ -n "${_my_hashes[$i]}" ]; do
|
|
|
|
hash="${_my_hashes[$i]}"
|
|
|
|
[ -z "${my_hashes[$hash]}" ] && my_hashes[$hash]=$template
|
|
|
|
i=$((i + 1))
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
cur=$((cur + 1))
|
2015-07-20 15:25:21 +02:00
|
|
|
pnew=$((100 * cur / max))
|
|
|
|
if [ $pnew -ne $percent ]; then
|
|
|
|
percent=$pnew
|
|
|
|
printf "\rScanning templates : %3d%% (%d/%d)" $percent $cur $max
|
|
|
|
fi
|
2015-07-06 09:47:52 +02:00
|
|
|
done
|
|
|
|
echo
|
|
|
|
echo "Number of hashes : ${#my_hashes[@]}"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Collect inodes of all distfiles in $XBPS_SRCDISTDIR
|
|
|
|
#
|
|
|
|
declare -A inodes
|
|
|
|
distfiles=($XBPS_SRCDISTDIR/*/*)
|
|
|
|
max=${#distfiles[@]}
|
2015-12-03 18:23:15 +01:00
|
|
|
if [ -z "$max" ]; then
|
|
|
|
msg_error "No distfiles files found in '$XBPS_SRCDISTDIR'"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-07-06 09:47:52 +02:00
|
|
|
cur=0
|
2015-07-20 15:25:21 +02:00
|
|
|
percent=-1
|
2015-07-06 09:47:52 +02:00
|
|
|
for distfile in ${distfiles[@]}; do
|
|
|
|
inode=$(stat "$distfile" --printf "%i")
|
|
|
|
if [ -z "${inodes[$inode]}" ]; then
|
|
|
|
inodes[$inode]="$distfile"
|
|
|
|
else
|
|
|
|
inodes[$inode]+="|$distfile"
|
|
|
|
fi
|
|
|
|
cur=$((cur + 1))
|
2015-07-20 15:25:21 +02:00
|
|
|
pnew=$((100 * cur / max))
|
|
|
|
if [ $pnew -ne $percent ]; then
|
|
|
|
percent=$pnew
|
|
|
|
printf "\rCollecting inodes : %3d%% (%d/%d)" $percent $cur $max
|
|
|
|
fi
|
2015-07-06 09:47:52 +02:00
|
|
|
done
|
|
|
|
echo
|
|
|
|
|
|
|
|
hashes=($XBPS_SRCDISTDIR/by_sha256/*)
|
|
|
|
for file in ${hashes[@]}; do
|
2015-09-11 07:55:40 +02:00
|
|
|
hash_distfile=${file##*/}
|
2015-07-06 09:47:52 +02:00
|
|
|
hash=${hash_distfile:0:$HASHLEN}
|
|
|
|
[ -n "${my_hashes[$hash]}" ] && continue
|
|
|
|
inode=$(stat "$file" --printf "%i")
|
|
|
|
echo "Obsolete $hash (inode: $inode)"
|
2019-04-09 09:12:24 +02:00
|
|
|
( IFS="|"; for f in ${inodes[$inode]}; do rm -vf "$f"; rmdir "${f%/*}" 2>/dev/null; done )
|
2015-07-06 09:47:52 +02:00
|
|
|
done
|
|
|
|
echo "Done."
|
|
|
|
}
|