[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

X Strike Force SVN commit: rev 384 - trunk/debian



Author: branden
Date: 2003-08-10 23:30:12 -0500 (Sun, 10 Aug 2003)
New Revision: 384

Modified:
   trunk/debian/xserver-common.postinst.in
   trunk/debian/xserver-common.postrm.in
Log:
Add technique for deciding when to purge non-conffile configuration files;
maintain a roster file corresponding to the config file, for which each
interested package adds its name on package configuration, and removes it
on package purge.

debian/xserver-common.postinst.in:
  - define the location of the X server wrapper config file's roster in a
    variable
  - if the roster file doesn't already list this package on configuration,
    add it to the roster
  - (cosmetic) minor edit to a comment

debian/xserver-common.postrm.in:
  - define the location of the X server wrapper config file's roster in a
    variable
  - on purge, remove this package's name from the roster file (if that
    leaves no packages managing the config file, look for a stored MD5
    checksum of the config file; if that matches the current config file,
    remove the config file; finally, remove the checksum file)


Modified: trunk/debian/xserver-common.postinst.in
==============================================================================
--- trunk/debian/xserver-common.postinst.in	2003-08-11 04:17:18 UTC (rev 383)
+++ trunk/debian/xserver-common.postinst.in	2003-08-11 04:30:12 UTC (rev 384)
@@ -17,6 +17,7 @@
 XWRAPPER_CONFIG=/etc/X11/Xwrapper.config
 CHECKSUM_DIR=/var/lib/xfree86
 XWRAPPER_CONFIG_CHECKSUM="$CHECKSUM_DIR/$(basename "$XWRAPPER_CONFIG").md5sum"
+XWRAPPER_CONFIG_ROSTER="$CHECKSUM_DIR/$(basename "$XWRAPPER_CONFIG").roster"
 
 # source debconf library
 . /usr/share/debconf/confmodule
@@ -30,14 +31,20 @@
 
 #DEBHELPER#
 
+# register this file as a (potential) handler of the X server wrapper config
+# file
+if ! fgrep -qsx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" ]; then
+  echo "$THIS_PACKAGE" >> "$XWRAPPER_CONFIG_ROSTER"
+fi
+
 # only mess with config file if it exists; if it does not, assume that's the
 # way the user wants it
 if [ -e "$XWRAPPER_CONFIG" ]; then
   # similarly, check for the existence of the checksum file; if it doesn't
   # exist, assume that's the way the user wants it
   if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
-    # compare the current and stored checksums; if they do not match, assume
-    # that's the way the user wants it
+    # next, compare the current and stored checksums; if they do not match,
+    # assume that's the way the user wants it
     CURRENT_MD5SUM=$(md5sum "$XWRAPPER_CONFIG")
     if [ "$CURRENT_MD5SUM" = "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
       # they match; prepare a new version of the config file

Modified: trunk/debian/xserver-common.postrm.in
==============================================================================
--- trunk/debian/xserver-common.postrm.in	2003-08-11 04:17:18 UTC (rev 383)
+++ trunk/debian/xserver-common.postrm.in	2003-08-11 04:30:12 UTC (rev 384)
@@ -17,6 +17,7 @@
 XWRAPPER_CONFIG=/etc/X11/Xwrapper.config
 CHECKSUM_DIR=/var/lib/xfree86
 XWRAPPER_CONFIG_CHECKSUM="$CHECKSUM_DIR/$(basename "$XWRAPPER_CONFIG").md5sum"
+XWRAPPER_CONFIG_ROSTER="$CHECKSUM_DIR/$(basename "$XWRAPPER_CONFIG").roster"
 
 if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ]; then
   if [ -d /usr/X11R6/lib/X11/xserver.moved-by-preinst -a -L /usr/X11R6/lib/X11/xserver ]; then
@@ -27,16 +28,38 @@
 
 # clean up non-conffile configuration files and related materials on purge
 if [ "$1" = "purge" ]; then
-  # remove Xwrapper.config if it was still managed by the package, and remove
-  # the checksum file in any case
-  if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
-    if [ -e "$XWRAPPER_CONFIG" ]; then
-      if [ "$(md5sum "$XWRAPPER_CONFIG")" \
-           = "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
-        rm -f "$XWRAPPER_CONFIG"
+  # de-register this file as a handler of the X server wrapper config file
+  if [ -e "$XWRAPPER_CONFIG_ROSTER" ]; then
+    # check existing roster file for our package name
+    if fgrep -qx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER"; then
+      # construct temporary roster file with our package name removed
+      fgrep -vx "$THIS_PACKAGE" > "$XRAPPER_CONFIG_ROSTER.dpkg-tmp"
+      # is there anything left?
+      if [ -n "$(cat "$XRAPPER_CONFIG_ROSTER.dpkg-tmp")" ]; then
+        # yes, replace the roster file
+        mv "$XRAPPER_CONFIG_ROSTER.dpkg-tmp" "$XRAPPER_CONFIG_ROSTER"
+      else
+        # no; remove both the roster and our temporary copy
+        rm -f "$XRAPPER_CONFIG_ROSTER" "$XRAPPER_CONFIG_ROSTER.dpkg-tmp"
+        # remove X server wrapper config file if it was still managed by the
+        # package
+        if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
+          # does it exist?
+          if [ -e "$XWRAPPER_CONFIG" ]; then
+            # does the current MD5 checksum match the stored checksum?
+            if [ "$(md5sum "$XWRAPPER_CONFIG")" \
+                 = "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
+              # yes; remove the config file
+              rm -f "$XWRAPPER_CONFIG"
+            fi
+          fi
+          # remove the checksum file; any remaining X server wrapper config file
+          # still on the system at this point is no longer being managed (local
+          # user customization)
+          rm -f "$XWRAPPER_CONFIG_CHECKSUM"
+        fi
       fi
     fi
-    rm -f "$XWRAPPER_CONFIG_CHECKSUM"
   fi
 
   # we can take /etc/X11/xserver out of this list one day when dpkg fixes



Reply to: