[pacman-dev] [PATCH] makepkg: create source package inside fakeroot

Allan McRae allan at archlinux.org
Wed Jun 15 05:13:27 EDT 2011


Create source package files inside the fakeroot environment to
ensure reasonable ownership of files within the archive.

Fixes FS#24330.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 scripts/makepkg.sh.in |   65 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index ce8f008..60be765 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -186,6 +186,16 @@ trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
 # 1) "filename::http://path/to/file"
 # 2) "http://path/to/file"
 
+enter_fakeroot() {
+	msg "$(gettext "Entering fakeroot environment...")"
+
+	if [[ -n $newpkgver ]]; then
+		fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
+	else
+		fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
+	fi
+}
+
 # Return the absolute filename of a source entry
 #
 # This function accepts a source entry or the already extracted filename of a
@@ -1143,23 +1153,6 @@ create_signature() {
 }
 
 create_srcpackage() {
-	cd "$startdir"
-
-	# Get back to our src directory so we can begin with sources.
-	mkdir -p "$srcdir"
-	chmod a-s "$srcdir"
-	cd "$srcdir"
-	if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
-		download_sources
-	fi
-	if (( ! SKIPINTEG )); then
-		# We can only check checksums if we have all files.
-		check_checksums
-	else
-		warning "$(gettext "Skipping integrity checks.")"
-	fi
-	cd "$startdir"
-
 	msg "$(gettext "Creating source package...")"
 	local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
 	mkdir "${srclinks}"/${pkgbase}
@@ -1951,6 +1944,12 @@ fi
 
 # Run the bare minimum in fakeroot
 if (( INFAKEROOT )); then
+	if (( SOURCEONLY )); then
+		create_srcpackage
+		msg "$(gettext "Leaving fakeroot environment.")"
+		exit 0 # $E_OK
+	fi
+
 	if (( ! SPLITPKG )); then
 		if (( ! PKGFUNC )); then
 			if (( ! REPKG )); then
@@ -1986,7 +1985,29 @@ if (( SOURCEONLY )); then
 		error "$(gettext "A source package has already been built. (use -f to overwrite)")"
 		exit 1
 	fi
-	create_srcpackage
+
+	# Get back to our src directory so we can begin with sources.
+	mkdir -p "$srcdir"
+	chmod a-s "$srcdir"
+	cd "$srcdir"
+	if (( ! SKIPINTEG || SOURCEONLY == 2 )); then
+		download_sources
+	fi
+	if (( ! SKIPINTEG )); then
+		# We can only check checksums if we have all files.
+		check_checksums
+	else
+		warning "$(gettext "Skipping integrity checks.")"
+	fi
+	cd "$startdir"
+
+	# if we are root or if fakeroot is not enabled, then we don't use it
+	if [[ $(check_buildenv fakeroot) != "y" ]] || (( EUID == 0 )); then
+		create_srcpackage
+	else
+		enter_fakeroot
+	fi
+
 	msg "$(gettext "Source package created: %s")" "$pkgbase ($(date))"
 	exit 0
 fi
@@ -2103,13 +2124,7 @@ else
 			cd "$startdir"
 		fi
 
-		msg "$(gettext "Entering fakeroot environment...")"
-
-		if [[ -n $newpkgver ]]; then
-			fakeroot -- $0 --forcever $newpkgver -F "${ARGLIST[@]}" || exit $?
-		else
-			fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
-		fi
+		enter_fakeroot
 	fi
 fi
 
-- 
1.7.5.4



More information about the pacman-dev mailing list