diff options
author | Stefan Metzmacher <metze@samba.org> | 2020-11-20 09:20:14 +0000 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2021-03-03 08:11:09 +0000 |
commit | 6d93064e1881f749d4b0a08e0c09eb58cab477c6 (patch) | |
tree | 72ea14f64a72bdeb1547b924b1e5551325be5a0c | |
parent | 35dc71bbc19a7f6e36af6bad74f990cfe38db59a (diff) | |
download | samba-6d93064e1881f749d4b0a08e0c09eb58cab477c6.tar.gz |
script/autobuild.py: split out a rmdir_force() helper function
That also tries to re-add write permissions before removing.
In future we'll have jobs changing there directory to read-only.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14628
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 7a5df2deaaf62a7edd7c64251f75ab15abe94c07)
(cherry picked from commit c933135969be29072971f96481b05f499fd48b57)
-rwxr-xr-x | script/autobuild.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/script/autobuild.py b/script/autobuild.py index 0ab04eb7c26..7811ff8a7b0 100755 --- a/script/autobuild.py +++ b/script/autobuild.py @@ -4,7 +4,7 @@ # released under GNU GPL v3 or later from __future__ import print_function -from subprocess import call, check_call, check_output, Popen, PIPE +from subprocess import call, check_call, check_output, Popen, PIPE, CalledProcessError import os import tarfile import sys @@ -860,6 +860,17 @@ def run_cmd(cmd, dir=".", show=None, output=False, checkfail=True): else: return call(cmd, shell=True, cwd=dir) +def rmdir_force(dirname, re_raise=True): + try: + run_cmd("test -d %s && chmod -R +w %s; rm -rf %s" % ( + dirname, dirname, dirname), output=True, show=True) + except CalledProcessError as e: + do_print("Failed: '%s'" % (str(e))) + run_cmd("tree %s" % dirname, output=True, show=True) + if re_raise: + raise + return False + return True class builder(object): '''handle build of one directory''' @@ -882,8 +893,8 @@ class builder(object): self.test_source_dir = "%s/%s" % (testbase, self.tag) self.cwd = "%s/%s" % (self.test_source_dir, self.dir) self.prefix = "%s/%s" % (test_prefix, self.tag) - run_cmd("rm -rf %s" % self.test_source_dir) - run_cmd("rm -rf %s" % self.prefix) + rmdir_force(self.test_source_dir) + rmdir_force(self.prefix) if cp: run_cmd("cp -R -a -l %s %s" % (test_master, self.test_source_dir), dir=test_master, show=True) else: @@ -893,8 +904,8 @@ class builder(object): def start_next(self): if self.next == len(self.sequence): if not options.nocleanup: - run_cmd("rm -rf %s" % self.test_source_dir) - run_cmd("rm -rf %s" % self.prefix) + rmdir_force(self.test_source_dir) + rmdir_force(self.prefix) do_print('%s: Completed OK' % self.name) self.done = True return @@ -1018,7 +1029,7 @@ class buildlist(object): 'df -m %s' % testbase]: try: out = run_cmd(cmd, output=True, checkfail=False) - except subprocess.CalledProcessError as e: + except CalledProcessError as e: out = "<failed: %s>" % str(e) print('### %s' % cmd, file=f) print(out, file=f) @@ -1055,7 +1066,7 @@ def cleanup(): run_cmd("stat %s" % testbase, show=True) do_print("Cleaning up %r" % cleanup_list) for d in cleanup_list: - run_cmd("rm -rf %s" % d) + rmdir_force(d) def daemonize(logfile): |