This patch changes the way that sed inplace is run in makepkg when
running in versionpkg mode. Previous, sed would run with no backup
file, called in the GNU way. It seems there is no cross platform
method of calling sed inplace with no backup (BSD/sed uses sed -i '',
GNU/sed uses sed -i'' or simply sed -i).

Instead, this patch creates a backup file (from an mktemp extension) and
removes it after the successful completetion of the sed operation.
This means the user should not see the backup file, unless something went wrong
(Full partition for example) in which case they don't lose the previous PKGBUILD
as they would in previous versions.

Further information about GNU/sed versus BSD/sed:

On Mac OS X (Man page is from FreeBSD, so I believe it would be the same there):
sed -i -e 's/foo/bar/' filename
will create a backup file named filename-e

sed -i -e 's/foo/bar/' -e 's/asd/dsa/' filename
will give an error message because of the second -e

sed -i 's/foo/bar/' filename
will give an error message

sed -i '' 's/foo/bar/' filename
will work without creating a backup, but fails on GNU/sed

sed -i'' 's/foo/bar/' filename
sed -i 's/foo/bar/' filename
Work only on GNU/sed

Signed-off-by: Kevin Barry <barryk gmail com>
---
 scripts/makepkg.sh.in |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index e10c345..5af4add 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1199,8 +1199,13 @@ devel_update() {
        if [ -n "$newpkgver" ]; then
                if [ "$newpkgver" != "$pkgver" ]; then
                        if [ -f "./$BUILDSCRIPT" ]; then
-                               sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" 
"./$BUILDSCRIPT"
-                               sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" 
"./$BUILDSCRIPT"
+                               # Create temporary filename for sed backup.
+                               # Needed for BSD/GNU cross-platform 
compatibility
+                               TEMP_NAME=$(mktemp -u "./${BUILDSCRIPT}.XXXXXX")
+                               TEMP_NAME=${TEMP_NAME#"./${BUILDSCRIPT}."}
+                               sed -i".${TEMP_NAME}" -e "s/^pkgver=[^ 
]*/pkgver=$newpkgver/" \
+                                       -e "s/^pkgrel=[^ ]*/pkgrel=1/" 
"./$BUILDSCRIPT" &&
+                                       rm -f "./${BUILDSCRIPT}.${TEMP_NAME}"
                                source "$BUILDSCRIPT"
                        fi
                fi
-- 
1.6.1.2
_______________________________________________
pacman-dev mailing list
[email protected]
http://www.archlinux.org/mailman/listinfo/pacman-dev

Reply via email to