[pacman-dev] [PATCH 1/2] Use `gzip -n' for compressing packages.

Nathan Jones nathanj at insightbb.com
Fri Feb 15 20:38:30 EST 2008


Without the -n flag, gzip stores the modification time inside the
header which can produce different md5sums for the same file contents.
By using this flag, it will be possible for the package to be generated
using a delta and have the same md5sum.

A new script, apply-delta, is created to apply a delta file and
recompress the resulting package. This will produce a package with the
correct md5sum.

Signed-off-by: Nathan Jones <nathanj at insightbb.com>
---
 lib/libalpm/sync.c        |    8 ++++----
 scripts/.gitignore        |    1 +
 scripts/Makefile.am       |    3 +++
 scripts/apply-delta.sh.in |   30 ++++++++++++++++++++++++++++++
 scripts/makepkg.sh.in     |   24 ++++++------------------
 5 files changed, 44 insertions(+), 22 deletions(-)
 create mode 100644 scripts/apply-delta.sh.in

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 4101158..e2e4ccb 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -738,14 +738,14 @@ static int apply_deltas(pmtrans_t *trans, alpm_list_t *patches)
 		}
 
 		/* an example of the patch command: (using /cache for cachedir)
-		 * xdelta patch /cache/pacman_3.0.0-1_to_3.0.1-1-i686.delta \
-		 *              /cache/pacman-3.0.0-1-i686.pkg.tar.gz       \
-		 *              /cache/pacman-3.0.1-1-i686.pkg.tar.gz
+		 * apply-delta /cache/pacman_3.0.0-1_to_3.0.1-1-i686.delta \
+		 *             /cache/pacman-3.0.0-1-i686.pkg.tar.gz       \
+		 *             /cache/pacman-3.0.1-1-i686.pkg.tar.gz
 		 */
 
 		/* build the patch command */
 		snprintf(command, PATH_MAX,
-				"xdelta patch"         /* the command */
+				"apply-delta"          /* the command */
 				" %s/%s"               /* the delta */
 				" %s/%s-%s-%s" PKGEXT  /* the 'from' package */
 				" %s/%s-%s-%s" PKGEXT, /* the 'to' package */
diff --git a/scripts/.gitignore b/scripts/.gitignore
index f2f19fd..214c23d 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -1,3 +1,4 @@
+apply-delta
 makepkg
 pacman-optimize
 rankmirrors
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 3185a47..ddcbd7f 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -2,6 +2,7 @@
 AUTOMAKE_OPTIONS = std-options
 
 bin_SCRIPTS = \
+	apply-delta \
 	makepkg \
 	pacman-optimize \
 	rankmirrors \
@@ -9,6 +10,7 @@ bin_SCRIPTS = \
 	repo-remove
 
 EXTRA_DIST = \
+	apply-delta.sh.in \
 	makepkg.sh.in \
 	pacman-optimize.sh.in \
 	rankmirrors.py.in \
@@ -44,6 +46,7 @@ $(bin_SCRIPTS): Makefile
 	chmod a-w $@.tmp
 	mv $@.tmp $@
 
+apply-delta: $(srcdir)/apply-delta.sh.in
 makepkg: $(srcdir)/makepkg.sh.in
 pacman-optimize: $(srcdir)/pacman-optimize.sh.in
 rankmirrors: $(srcdir)/rankmirrors.py.in
diff --git a/scripts/apply-delta.sh.in b/scripts/apply-delta.sh.in
new file mode 100644
index 0000000..9dca177
--- /dev/null
+++ b/scripts/apply-delta.sh.in
@@ -0,0 +1,30 @@
+#!/bin/bash -e
+#
+#   apply-delta - apply xdelta patch and then recompress using gzip
+#   @configure_input@
+#
+#   Copyright (c) 2008 by Judd Vinet <jvinet at zeroflux.org>
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+withoutgz="$(echo $3 | sed -e 's/.gz$//')"
+
+# patch
+xdelta patch "$1" "$2" "$3"
+
+# now re-gzip
+gzip -d "$3"
+gzip -f -n "$withoutgz"
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index cecda1d..b9b3ed7 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -869,7 +869,7 @@ create_package() {
 
 	local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}"
 
-	if ! bsdtar -czf "$pkg_file" $comp_files $(ls); then
+	if ! bsdtar -cf - $comp_files $(ls) | gzip -n > "$pkg_file"; then
 		error "$(gettext "Failed to create package file.")"
 		exit 1 # TODO: error code
 	fi
@@ -910,28 +910,16 @@ create_xdelta() {
 
 	if [ "$base_file" != "" ]; then
 		msg "$(gettext "Making delta from version %s...")" "$latest_version"
+		msg2 "$(gettext "NOTE: the delta should ONLY be distributed with this tarball")"
+
 		local delta_file="$PKGDEST/$pkgname-${latest_version}_to_$pkgver-$pkgrel-$CARCH.delta"
 		local ret=0
 
-		# xdelta will decompress base_file & pkg_file into TMP_DIR (or /tmp if
-		# TMP_DIR is unset) then perform the delta on the resulting tars
+		# xdelta will decompress base_file & pkg_file into TMPDIR (or /tmp if
+		# TMPDIR is unset) then perform the delta on the resulting tars
 		xdelta delta "$base_file" "$pkg_file" "$delta_file" || ret=$?
 
-		if [ $ret -eq 0 -o $ret -eq 1 ]; then
-			# Generate the final gz using xdelta for compression. xdelta will be our
-			# common denominator compression utility between the packager and the
-			# users. makepkg and pacman must use the same compression algorithm or
-			# the delta generated package may not match, producing md5 checksum
-			# errors.
-			msg2 "$(gettext "Recreating package tarball from delta to match md5 signatures")"
-			msg2 "$(gettext "NOTE: the delta should ONLY be distributed with this tarball")"
-			ret=0
-			xdelta patch "$delta_file" "$base_file" "$pkg_file" || ret=$?
-			if [ $ret -ne 0 ]; then
-				error "$(gettext "Could not generate the package from the delta.")"
-				exit 1
-			fi
-		else
+		if [ $ret -ne 0 -a $ret -ne 1 ]; then
 			warning "$(gettext "Delta was not able to be created.")"
 		fi
 	else
-- 
1.5.4




More information about the pacman-dev mailing list