[pacman-dev] pacman-optimize updates

James Rosten seinfeld90 at gmail.com
Sun Dec 31 12:17:34 EST 2006


Ok, after testing it, some changes needed to be made and so they were
made.  Now it works (at least for me it worked).

This is just an idea, but wouldn't it be interesting if we used the
stat_busy, stat_done, and stat_fail stuff from /etc/rc.d/functions for
the messages in pacman-optimize?

Anyway, here is the patch for FS #5009 (woops, just caught another
bug.........it wouldn't be able to work after a successful one but it
would work after the failure ('cause pacman.new was still haning
around.........fixed).  It is below as usual.

~ Jamie / yankees26
-------------- next part --------------
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


More information about the pacman-dev mailing list