From d6e56aa8a6b122992ccbdc6a7cfc6f5ec2411de1 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 18 Apr 2019 13:06:59 +0200 Subject: [PATCH] TEMPLATE.sh: Die, if BUILD_TMPDIR can't be removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- TEMPLATE.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TEMPLATE.sh b/TEMPLATE.sh index 7d9dac2..b025955 100755 --- a/TEMPLATE.sh +++ b/TEMPLATE.sh @@ -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