Package: pbuilder
Version: 0.160

Hi,

The attached patch adds support for unionfs snapshot in pbuilder. It's
based on a patch that I've made some time ago for version 0.128 [1],
but just recently I had some time to update it.

I've tested it on Ubuntu 6.10 (kernel 2.6.17). It would be nice if
someone could test it on Debian unstable (I believe it will not work
on sarge)

The patch is split in two parts: unionfs_harmless_changes.patch
contains changes that do not affect current functionality in any way
but are required by unionfs. The patch reorders some commands so that
BUILDPLACE is kept unchanged.

The second patch (unionfs.patch) adds unionfs support.

I've added some documentation in the man pages, but here is the basic
usage (assuming you already have a unpacked rootstrap in
/var/cache/pbuilder/build):

pbuilder login --unionfs-snap /var/cache/pbuilder/unionfs-snap # login
to the rootstrap
pbuilder build --unionfs-snap /var/cache/pbuilder/unionfs-snap # build a package
...

alternatively to the "--unionfs-snap" parameter, you can add this line
to .pbuilderrc:

UNIONFS_SNAP=/var/cache/pbuilder/unionfs-snap/

and just use:

pbuilder login
pbuilder build
...

To change the base rootstrap location, use "--buildplace <dir>" or
change BUILDPLACE=<dir> in .pbuilderrc.

KNOWN ISSUE:

- due to a limitation in unionfs, some packages that use
/proc/self/exe symlink to check for their full path (e.g. many perl
modules) may fail to build. This is fixed in recent unionfs releases,
but is disabled by default because it's experimental (look for
UNIONFS_MMAP in unionfs' INSTALL file).

[1] http://www.mail-archive.com/[email protected]/msg00553.html

Regards,
--
Anderson Lizardo
Index: pbuilder-0.160.1custom7/pbuilder-modules
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-modules	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-modules	2006-11-15 21:18:59.000000000 -0400
@@ -300,9 +300,8 @@
 	echo " -> creating local configuration"
 	hostname -f > "$BUILDPLACE/etc/mailname"
     fi
-    copy_local_configuration
     mountproc
-    mkdir -p "$BUILDPLACE/tmp/buildd"
+    copy_local_configuration
     
     if [ "$OVERRIDE_APTLINES" = "yes" ]; then
 	installaptlines
Index: pbuilder-0.160.1custom7/pbuilder
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder	2006-11-15 21:19:00.000000000 -0400
@@ -81,9 +81,9 @@
 	    else
 		echo " -> Saving the results, modifications to this session will persist"
 		unloadhooks
-		umountproc
 		trap cleanbuildplace exit
 		${CHROOTEXEC} /usr/bin/apt-get clean || true
+		umountproc
 		create_basetgz
 	    fi
 	fi
@@ -123,9 +123,9 @@
 	    else
 		echo " -> Saving the results, modifications to this session will persist"
 		unloadhooks
-		umountproc
 		trap cleanbuildplace exit
 		${CHROOTEXEC} /usr/bin/apt-get clean || true
+		umountproc
 		create_basetgz
 	    fi
 	fi
Index: pbuilder-0.160.1custom7/pbuilder-buildpackage
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-buildpackage	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-buildpackage	2006-11-15 21:18:59.000000000 -0400
@@ -53,6 +53,7 @@
 showbuildbanner '$Id: pbuilder-buildpackage,v 1.127 2006/08/15 13:14:25 dancer Exp $'
 echobacktime
 extractbuildplace 
+mkdir -p "${BUILDPLACE}"/tmp/buildd
 trap umountproc_cleanbuildplace exit
 loadhooks
 
@@ -154,9 +155,6 @@
 trap umountproc_cleanbuildplace exit
 executehooks "B"
 save_aptcache
-trap cleanbuildplace exit
-umountproc
-
 
 if [ -d "${BUILDRESULT}" ]; then
     chown "${BUILDRESULTUID}:${BUILDRESULTGID}" "${BUILDPLACE}"/tmp/buildd/*
Index: pbuilder-0.160.1custom7/pbuilder-createbuildenv
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-createbuildenv	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-createbuildenv	2006-11-15 21:19:00.000000000 -0400
@@ -70,9 +70,6 @@
 echo " -> debootstrap finished"
 loadhooks
 
-
-mkdir -p "$BUILDPLACE/tmp/buildd"
-
 copy_local_configuration
 installaptlines
 
@@ -93,8 +90,8 @@
 
 executehooks "E"
 unloadhooks
-umountproc
 $CHROOTEXEC /usr/bin/apt-get clean || true
+umountproc
 
 $TRAP cleanbuildplace exit
 
Index: pbuilder-0.160.1custom7/pbuilder-updatebuildenv
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-updatebuildenv	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-updatebuildenv	2006-11-15 21:19:00.000000000 -0400
@@ -66,8 +66,8 @@
 executehooks "E"
 unloadhooks
 
-umountproc
 $CHROOTEXEC /usr/bin/apt-get clean || true
+umountproc
 
 $TRAP cleanbuildplace exit
 if [ ! "${INTERNAL_BUILD_UML}" = "yes" ]; then
Index: pbuilder-0.160.1custom7/pbuilder-modules
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-modules	2006-11-15 21:18:47.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-modules	2006-11-15 21:18:58.000000000 -0400
@@ -50,6 +50,7 @@
 pbuilder-options:
  --basetgz [base.tgz location]
  --buildplace [location of build]
+ --unionfs-snap [location to put modified files]
  --mirror [mirror location]
  --othermirror [other mirror location in apt deb-line format, delimited with | signs]
  --http-proxy [proxy]
@@ -138,12 +139,26 @@
     for mnt in $reversed; do
 	umount_one "$mnt"
     done
+    if [ -n "$UNIONFS_SNAP" -a "$SAVE_AFTER_LOGIN" != "yes" ]; then
+	umount_one "/"
+	clean_subdirectories "$UNIONFS_SNAP"
+    fi
 }
 
 
-# Mount /proc /dev/pts /dev and bind-mount points
+# Mount unionfs /proc /dev/pts /dev and bind-mount points
 # Also create a policy-rc.d script if it doesn't already exist.
 function mountproc () {
+    if [ -n "$UNIONFS_SNAP" -a "$SAVE_AFTER_LOGIN" != "yes" ]; then
+	echo " -> mounting unionfs filesystem"
+	test ! -d "$UNIONFS_SNAP" || clean_subdirectories "$UNIONFS_SNAP"
+	if ! mkdir -p "$UNIONFS_SNAP"; then
+	    echo "E: failed to build unionfs snapshot directory"
+	    exit 1
+	fi
+	mkdir -p $BUILDPLACE
+	mount -t unionfs -o dirs=$UNIONFS_SNAP=rw:$BUILDPLACE=ro none $BUILDPLACE
+    fi
     if [ "$USEPROC" = "yes" ]; then
 	echo " -> mounting /proc filesystem"
 	mkdir -p $BUILDPLACE/proc
Index: pbuilder-0.160.1custom7/pbuilderrc
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilderrc	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilderrc	2006-11-15 21:18:58.000000000 -0400
@@ -14,6 +14,8 @@
 USEPROC=yes
 USEDEVPTS=yes
 USEDEVFS=no
+# uncomment this line to enable unionfs mode
+#UNIONFS_SNAP=/var/cache/pbuilder/unionfs-snap/
 BUILDRESULT=/var/cache/pbuilder/result/
 
 # specifying the distribution forces the distribution on "pbuilder update"
Index: pbuilder-0.160.1custom7/pbuilder
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder	2006-11-15 21:18:47.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder	2006-11-15 21:18:47.000000000 -0400
@@ -76,7 +76,7 @@
 
 	# saving the place afterwards
 	if [ "${SAVE_AFTER_LOGIN}" = "yes" ]; then
-	    if [ "${INTERNAL_BUILD_UML}" = "yes" ]; then
+	    if [ "${INTERNAL_BUILD_UML}" = "yes" -a -z "$UNIONFS_SNAP" ]; then
 		echo "E: Invalid combination of internal-build-uml and save-after-login flags"
 	    else
 		echo " -> Saving the results, modifications to this session will persist"
@@ -84,7 +84,9 @@
 		trap cleanbuildplace exit
 		${CHROOTEXEC} /usr/bin/apt-get clean || true
 		umountproc
-		create_basetgz
+		if [ -z "$UNIONFS_SNAP" ]; then
+		    create_basetgz
+		fi
 	    fi
 	fi
 	;;
@@ -118,7 +120,7 @@
 
 	# saving the place afterwards
 	if [ "${SAVE_AFTER_LOGIN}" = "yes" ]; then
-	    if [ "${INTERNAL_BUILD_UML}" = "yes" ]; then
+	    if [ "${INTERNAL_BUILD_UML}" = "yes" -a -z "$UNIONFS_SNAP" ]; then
 		echo "E: Invalid combination of internal-build-uml and save-after-login flags"
 	    else
 		echo " -> Saving the results, modifications to this session will persist"
@@ -126,7 +128,9 @@
 		trap cleanbuildplace exit
 		${CHROOTEXEC} /usr/bin/apt-get clean || true
 		umountproc
-		create_basetgz
+		if [ -z "$UNIONFS_SNAP" ]; then
+		    create_basetgz
+		fi
 	    fi
 	fi
 	;;
Index: pbuilder-0.160.1custom7/pbuilder-createbuildenv
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-createbuildenv	2006-11-15 21:18:47.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-createbuildenv	2006-11-15 21:18:47.000000000 -0400
@@ -23,6 +23,8 @@
 . /usr/lib/pbuilder/pbuilder-checkparams
 . /usr/lib/pbuilder/pbuilder-runhooks
 
+UNIONFS_SNAP=""
+
 if [ -z "$DISTRIBUTION" ]; then
     DISTRIBUTION=sid
 fi
Index: pbuilder-0.160.1custom7/pbuilder-updatebuildenv
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-updatebuildenv	2006-11-15 21:18:47.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-updatebuildenv	2006-11-15 21:18:47.000000000 -0400
@@ -21,6 +21,7 @@
 . /usr/lib/pbuilder/pbuilder-checkparams
 . /usr/lib/pbuilder/pbuilder-runhooks
 
+UNIONFS_SNAP=""
 
 if [ -n "$DISTRIBUTION" ]; then
     echo "Upgrading for distribution $DISTRIBUTION" 
Index: pbuilder-0.160.1custom7/pbuilder-checkparams
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder-checkparams	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder-checkparams	2006-11-15 21:18:47.000000000 -0400
@@ -59,6 +59,14 @@
 	    BUILDPLACE=$(readlink -f "$2");
 	    shift; shift;
 	    ;;
+	--unionfs-snap)
+	    if [ -n "$2" ]; then
+		UNIONFS_SNAP=$(readlink -f "$2")
+	    else
+		UNIONFS_SNAP=
+	    fi
+	    shift; shift;
+	    ;;
 	--mirror)
 	    MIRRORSITE="$2";
 	    shift; shift;
@@ -226,6 +234,11 @@
   esac
 done
 
+# unionfs mode is useless without no-targz mode, so force it
+if [ -n "$UNIONFS_SNAP" ]; then
+    INTERNAL_BUILD_UML="yes"
+fi
+
 BUILDPLACE=${BUILDPLACE?"Build root directory is not defined"}
 
 # the default is to add a PID in the buildplace specified in the config file.
Index: pbuilder-0.160.1custom7/pbuilder.8
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilder.8	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilder.8	2006-11-15 21:18:47.000000000 -0400
@@ -139,6 +139,14 @@
 the newly generated ones.
 
 .TP
+.BI "\-\-unionfs-snap [" "location to put modified files" "]"
+Specifies the location to put the files modified or created during
+build. A unionfs layer filesystem will be used to protect the
+buildplace from being modified. Note that the files created on this
+directory will be removed after building. By default, unionfs is
+not used.
+
+.TP
 .BI "\-\-mirror [" "mirror location" "]"
 Specifies the URL of Debian mirror to be 
 specified in 
Index: pbuilder-0.160.1custom7/pbuilderrc.5
===================================================================
--- pbuilder-0.160.1custom7.orig/pbuilderrc.5	2006-11-15 21:18:46.000000000 -0400
+++ pbuilder-0.160.1custom7/pbuilderrc.5	2006-11-15 21:18:47.000000000 -0400
@@ -49,6 +49,15 @@
 
 .B "pbuilder clean"
 cleans up this directory.
+
+.TP
+.BI "UNIONFS_SNAP=" "/var/cache/pbuilder/unionfs-snap/"
+The default place where the unionfs snapshot is kept. If non-empty,
+a unionfs layer will be mounted over
+.B BUILDPLACE,
+protecting it from being modified. This directory is cleaned up
+after building.
+
 .TP
 .BI "MIRRORSITE=" "http://www.jp.debian.org/debian";
 Specify the mirror site which contains the

Reply via email to