1 # Scan srcpkgs/*/template for hashes and distfiles to determine
2 # obsolete sources/by_sha256 files and their corresponding
3 # sources/<pkgname>-<version> files that can be purged
7 # Ignore msg_error calls when sourcing templates
11 if [ -z "$XBPS_SRCDISTDIR" ]; then
12 msg_error
"The variable \$XBPS_SRCDISTDIR is not set."
16 # Scan all templates for their current distfiles and checksums (hashes)
19 templates
=(srcpkgs
/*/template
)
22 if [ -z "$max" ]; then
23 msg_error
"No srcpkgs/*/template files found. Wrong working directory?"
27 for template
in ${templates[@]}; do
30 if [ ! -L "srcpkgs/$pkg" ]; then
32 source $template 2>/dev
/null
33 read -a _my_hashes
<<< ${checksum}
35 while [ -n "${_my_hashes[$i]}" ]; do
36 hash="${_my_hashes[$i]}"
37 [ -z "${my_hashes[$hash]}" ] && my_hashes
[$hash]=$template
42 pnew
=$
((100 * cur
/ max
))
43 if [ $pnew -ne $percent ]; then
45 printf "\rScanning templates : %3d%% (%d/%d)" $percent $cur $max
49 echo "Number of hashes : ${#my_hashes[@]}"
52 # Collect inodes of all distfiles in $XBPS_SRCDISTDIR
55 distfiles
=($XBPS_SRCDISTDIR/*/*)
57 if [ -z "$max" ]; then
58 msg_error
"No distfiles files found in '$XBPS_SRCDISTDIR'"
63 for distfile
in ${distfiles[@]}; do
64 inode
=$
(stat
"$distfile" --printf "%i")
65 if [ -z "${inodes[$inode]}" ]; then
66 inodes
[$inode]="$distfile"
68 inodes
[$inode]+="|$distfile"
71 pnew
=$
((100 * cur
/ max
))
72 if [ $pnew -ne $percent ]; then
74 printf "\rCollecting inodes : %3d%% (%d/%d)" $percent $cur $max
79 hashes
=($XBPS_SRCDISTDIR/by_sha256
/*)
81 for file in ${hashes[@]}; do
82 hash_distfile
=${file##*/}
83 hash=${hash_distfile:0:$HASHLEN}
84 [ -n "${my_hashes[$hash]}" ] && continue
85 inode
=$
(stat
"$file" --printf "%i")
86 echo "Obsolete $hash (inode: $inode)"
87 ( IFS
="|"; for f
in ${inodes[$inode]}; do rm -v "$f"; rmdir "${f%/*}" 2>/dev
/null
; done )