Index: pacman-optimize =================================================================== RCS file: /home/cvs-pacman/pacman-lib/scripts/pacman-optimize,v retrieving revision 1.4 diff -u -r1.4 pacman-optimize --- pacman-optimize 28 Dec 2006 18:19:25 -0000 1.4 +++ pacman-optimize 31 Dec 2006 17:16:41 -0000 @@ -64,6 +64,49 @@ die "Pacman lockfile was found. Cannot run while pacman is running." fi +# check if $dbroot is a mounted partition +# fix flyspray #5009 bug +mounted=`cat /etc/mtab | grep $dbroot` +if [ -n "$mounted" ]; then + # step 1: sum the old db + echo "==> md5sum'ing the old database..." + find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.old + + # step 2: backup the old db and copy the entire db directory to a new one + echo "==> copying $dbroot..." + cp -a $dbroot/ $dbroot.new + + # step 3: sum the new one + echo "==> md5sum'ing the new database..." + find $dbroot.new -type f | sort | xargs md5sum | sed 's/pacman\.new/pacman/g' >/tmp/pacsums.new + + # step 4: compare the sums + echo "==> checking integrity..." + diff /tmp/pacsums.old /tmp/pacsums.new >/dev/null 2>&1 + if [ $? -ne 0 ]; then + # failed, restore everything + rm -rf $dbroot.new + rm -f /tmp/pacsums.old /tmp/pacsums.new + die_r "integrity check FAILED, reverting to old database" + fi + + # step 5: remove the backup + echo "==> removing old database..." + rm -rf $dbroot/* + mv $dbroot.new/* $dbroot/ + rm -rf $dbroot.new + + # remove the lock and sum files + rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new + + echo + echo "Finished. Your pacman database has been optimized." + echo + + exit 0 +fi + + if [ ! -d $dbroot ]; then die "$dbroot does not exist or is not a directory" fi