FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 03-09-2012, 06:59 AM
Allan McRae
 
Default makepkg: safely change directories

In preparation for the removal of the global error trap we need a
way to ensure changing directories succeeds. Add a "cd_safe"
wrapper that performs the necessary check.

Signed-off-by: Allan McRae <allan@archlinux.org>
---
scripts/makepkg.sh.in | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 534f6f8..f21c638 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -874,6 +874,14 @@ error_function() {
exit 2 # $E_BUILD_FAILED
}

+cd_safe() {
+ if ! cd "$1"; then
+ error "$(gettext "Failed to change to directory %s")" "$1"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+}
+
run_function() {
if [[ -z $1 ]]; then
return 1
@@ -891,7 +899,7 @@ run_function() {
fi

msg "$(gettext "Starting %s()...")" "$pkgfunc"
- cd "$srcdir"
+ cd_safe "$srcdir"

# ensure all necessary build variables are exported
export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
@@ -969,7 +977,7 @@ run_package() {
}

tidy_install() {
- cd "$pkgdir"
+ cd_safe "$pkgdir"
msg "$(gettext "Tidying install...")"

if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
@@ -1219,7 +1227,7 @@ write_pkginfo() {
}

check_package() {
- cd "$pkgdir"
+ cd_safe "$pkgdir"

# check existence of backup files
local file
@@ -1248,7 +1256,7 @@ create_package() {

check_package

- cd "$pkgdir"
+ cd_safe "$pkgdir"
msg "$(gettext "Creating package...")"

local nameofpkg
@@ -1407,7 +1415,7 @@ create_srcpackage() {

# tar it up
msg2 "$(gettext "Compressing source package...")"
- cd "${srclinks}"
+ cd_safe "${srclinks}"
if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
error "$(gettext "Failed to create source package file.")"
exit 1 # TODO: error code
@@ -1423,7 +1431,7 @@ create_srcpackage() {
warning "$(gettext "Failed to create symlink to source package file.")"
fi

- cd "${startdir}"
+ cd_safe "${startdir}"
rm -rf "${srclinks}"
}

@@ -1757,7 +1765,7 @@ devel_check() {
fi
msg "$(gettext "Determining latest %s revision...")" 'hg'
if [[ -d ./src/$_hgrepo ]] ; then
- cd ./src/$_hgrepo
+ cd_safe ./src/$_hgrepo
local ret=0
hg pull || ret=$?
if (( ! ret )); then
@@ -1768,10 +1776,10 @@ devel_check() {
else
[[ ! -d ./src/ ]] && mkdir ./src/
hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
- cd ./src/$_hgrepo
+ cd_safe ./src/$_hgrepo
fi
newpkgver=$(hg tip --template "{rev}")
- cd ../../
+ cd_safe ../../
fi

if [[ -n $newpkgver ]]; then
@@ -1847,7 +1855,7 @@ canonicalize_path() {

if [[ -d $path ]]; then
(
- cd "$path"
+ cd_safe "$path"
pwd -P
)
else
@@ -2171,7 +2179,7 @@ fi
if (( GENINTEG )); then
mkdir -p "$srcdir"
chmod a-s "$srcdir"
- cd "$srcdir"
+ cd_safe "$srcdir"
download_sources
generate_checksums
exit 0 # $E_OK
@@ -2321,14 +2329,14 @@ if (( SOURCEONLY )); then
# Get back to our src directory so we can begin with sources.
mkdir -p "$srcdir"
chmod a-s "$srcdir"
- cd "$srcdir"
+ cd_safe "$srcdir"
if ( (( ! SKIPCHECKSUMS )) ||
( (( ! SKIPPGPCHECK )) && source_has_signatures ) ) ||
(( SOURCEONLY == 2 )); then
download_sources
fi
check_source_integrity
- cd "$startdir"
+ cd_safe "$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
@@ -2384,7 +2392,7 @@ umask 0022
# get back to our src directory so we can begin with sources
mkdir -p "$srcdir"
chmod a-s "$srcdir"
-cd "$srcdir"
+cd_safe "$srcdir"

if (( NOEXTRACT )); then
warning "$(gettext "Skipping source retrieval -- using existing %s tree")" "src/"
@@ -2420,7 +2428,7 @@ else
fi
mkdir -p "$pkgdir"
chmod a-s "$pkgdir"
- cd "$startdir"
+ cd_safe "$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
@@ -2450,7 +2458,7 @@ else
devel_update
(( BUILDFUNC )) && run_build
(( CHECKFUNC )) && run_check
- cd "$startdir"
+ cd_safe "$startdir"
fi

enter_fakeroot
--
1.7.9.3
 
Old 03-09-2012, 02:23 PM
Dave Reisner
 
Default makepkg: safely change directories

On Fri, Mar 09, 2012 at 05:59:09PM +1000, Allan McRae wrote:
> In preparation for the removal of the global error trap we need a
> way to ensure changing directories succeeds. Add a "cd_safe"
> wrapper that performs the necessary check.
>
> Signed-off-by: Allan McRae <allan@archlinux.org>
> ---
> scripts/makepkg.sh.in | 40 ++++++++++++++++++++++++----------------
> 1 file changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index 534f6f8..f21c638 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -874,6 +874,14 @@ error_function() {
> exit 2 # $E_BUILD_FAILED
> }
>
> +cd_safe() {
> + if ! cd "$1"; then

Do we want to write stdout to /dev/null here? It _should_ be quiet since
we unset CDPATH early on...

> + error "$(gettext "Failed to change to directory %s")" "$1"
> + plain "$(gettext "Aborting...")"
> + exit 1
> + fi
> +}
> +
> run_function() {
> if [[ -z $1 ]]; then
> return 1
> @@ -891,7 +899,7 @@ run_function() {
> fi
>
> msg "$(gettext "Starting %s()...")" "$pkgfunc"
> - cd "$srcdir"
> + cd_safe "$srcdir"
>
> # ensure all necessary build variables are exported
> export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
> @@ -969,7 +977,7 @@ run_package() {
> }
>
> tidy_install() {
> - cd "$pkgdir"
> + cd_safe "$pkgdir"
> msg "$(gettext "Tidying install...")"
>
> if [[ $(check_option docs) = "n" && -n ${DOC_DIRS[*]} ]]; then
> @@ -1219,7 +1227,7 @@ write_pkginfo() {
> }
>
> check_package() {
> - cd "$pkgdir"
> + cd_safe "$pkgdir"
>
> # check existence of backup files
> local file
> @@ -1248,7 +1256,7 @@ create_package() {
>
> check_package
>
> - cd "$pkgdir"
> + cd_safe "$pkgdir"
> msg "$(gettext "Creating package...")"
>
> local nameofpkg
> @@ -1407,7 +1415,7 @@ create_srcpackage() {
>
> # tar it up
> msg2 "$(gettext "Compressing source package...")"
> - cd "${srclinks}"
> + cd_safe "${srclinks}"
> if ! bsdtar -c${TAR_OPT}Lf "$pkg_file" ${pkgbase}; then
> error "$(gettext "Failed to create source package file.")"
> exit 1 # TODO: error code
> @@ -1423,7 +1431,7 @@ create_srcpackage() {
> warning "$(gettext "Failed to create symlink to source package file.")"
> fi
>
> - cd "${startdir}"
> + cd_safe "${startdir}"
> rm -rf "${srclinks}"
> }
>
> @@ -1757,7 +1765,7 @@ devel_check() {
> fi
> msg "$(gettext "Determining latest %s revision...")" 'hg'
> if [[ -d ./src/$_hgrepo ]] ; then
> - cd ./src/$_hgrepo
> + cd_safe ./src/$_hgrepo
> local ret=0
> hg pull || ret=$?
> if (( ! ret )); then
> @@ -1768,10 +1776,10 @@ devel_check() {
> else
> [[ ! -d ./src/ ]] && mkdir ./src/
> hg clone $_hgroot/$_hgrepo ./src/$_hgrepo
> - cd ./src/$_hgrepo
> + cd_safe ./src/$_hgrepo
> fi
> newpkgver=$(hg tip --template "{rev}")
> - cd ../../
> + cd_safe ../../
> fi
>
> if [[ -n $newpkgver ]]; then
> @@ -1847,7 +1855,7 @@ canonicalize_path() {
>
> if [[ -d $path ]]; then
> (
> - cd "$path"
> + cd_safe "$path"
> pwd -P
> )
> else
> @@ -2171,7 +2179,7 @@ fi
> if (( GENINTEG )); then
> mkdir -p "$srcdir"
> chmod a-s "$srcdir"
> - cd "$srcdir"
> + cd_safe "$srcdir"
> download_sources
> generate_checksums
> exit 0 # $E_OK
> @@ -2321,14 +2329,14 @@ if (( SOURCEONLY )); then
> # Get back to our src directory so we can begin with sources.
> mkdir -p "$srcdir"
> chmod a-s "$srcdir"
> - cd "$srcdir"
> + cd_safe "$srcdir"
> if ( (( ! SKIPCHECKSUMS )) ||
> ( (( ! SKIPPGPCHECK )) && source_has_signatures ) ) ||
> (( SOURCEONLY == 2 )); then
> download_sources
> fi
> check_source_integrity
> - cd "$startdir"
> + cd_safe "$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
> @@ -2384,7 +2392,7 @@ umask 0022
> # get back to our src directory so we can begin with sources
> mkdir -p "$srcdir"
> chmod a-s "$srcdir"
> -cd "$srcdir"
> +cd_safe "$srcdir"
>
> if (( NOEXTRACT )); then
> warning "$(gettext "Skipping source retrieval -- using existing %s tree")" "src/"
> @@ -2420,7 +2428,7 @@ else
> fi
> mkdir -p "$pkgdir"
> chmod a-s "$pkgdir"
> - cd "$startdir"
> + cd_safe "$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
> @@ -2450,7 +2458,7 @@ else
> devel_update
> (( BUILDFUNC )) && run_build
> (( CHECKFUNC )) && run_check
> - cd "$startdir"
> + cd_safe "$startdir"
> fi
>
> enter_fakeroot
> --
> 1.7.9.3
>
>
 
Old 03-09-2012, 10:36 PM
Allan McRae
 
Default makepkg: safely change directories

On 10/03/12 01:23, Dave Reisner wrote:
> On Fri, Mar 09, 2012 at 05:59:09PM +1000, Allan McRae wrote:
>> In preparation for the removal of the global error trap we need a
>> way to ensure changing directories succeeds. Add a "cd_safe"
>> wrapper that performs the necessary check.
>>
>> Signed-off-by: Allan McRae <allan@archlinux.org>
>> ---
>> scripts/makepkg.sh.in | 40 ++++++++++++++++++++++++----------------
>> 1 file changed, 24 insertions(+), 16 deletions(-)
>>
>> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
>> index 534f6f8..f21c638 100644
>> --- a/scripts/makepkg.sh.in
>> +++ b/scripts/makepkg.sh.in
>> @@ -874,6 +874,14 @@ error_function() {
>> exit 2 # $E_BUILD_FAILED
>> }
>>
>> +cd_safe() {
>> + if ! cd "$1"; then
>
> Do we want to write stdout to /dev/null here? It _should_ be quiet since
> we unset CDPATH early on...

I am happy not doing that at the moment, mainly because it was never
there before and I would like to know if something breaks our assumption
that it should be quiet...
 

Thread Tools




All times are GMT. The time now is 12:40 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org