Skip to content

Commit

Permalink
TEMPLATE.sh: Die, if BUILD_TMPDIR can't be removed
Browse files Browse the repository at this point in the history
If we don't have the permissions to remove BUILD_TMPDIR (which is quite
likely, when we switch from a test build with a personal user to one
via tools/build.sh with the build user), the current code would ignore
the fact, that the directory can't be removed and continue with a
nonempty directory, possible running into permission problems later.

We could just change

   chmod ... && rm -r ...

to

   ( chmod ... ; rm -r ... )

and the shell would terminate when chmod fails due to permissions.
However, the error message of chmod is different than that of rm:

    buczek@afk:~$ chmod u+w /root
    chmod: changing permissions of ‘/root’: Operation not permitted
    buczek@afk:~$ ls /root/
    ls: cannot open directory /root/: Permission denied

I think "Permission denied" is a bit clearer than "Operation not
permitted".

Ignore errors form `chmod` and try `rm` in any case, which either
succeeds or aborts the script with an appropriate error message. Remove
-c flag from chmod because we are not really interested if something has
been changed or not.
  • Loading branch information
donald committed Apr 18, 2019
1 parent 463aa8f commit d6e56aa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion TEMPLATE.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -xe
umask 022

BUILD_TMPDIR=/dev/shm/$PKG-$VERSION-$BUILD.build.tmp
test -d $BUILD_TMPDIR && chmod -c -R u+rwx $BUILD_TMPDIR && rm -rf $BUILD_TMPDIR
test -d $BUILD_TMPDIR && ( chmod -R u+rwx $BUILD_TMPDIR || true ; rm -rf $BUILD_TMPDIR )
mkdir -p $BUILD_TMPDIR/home
export TMPDIR=$BUILD_TMPDIR
export HOME=$BUILD_TMPDIR/home
Expand Down

0 comments on commit d6e56aa

Please sign in to comment.