executor: prevent restart error on bad build log

This change prevents permission denied errors from blocking
executor service restart when a job build contains a directory
with non writable mode bit.

  $ mkdir test-dir && touch test-dir/test-file && chmod 0500 test-dir
  $ rm -Rf test-dir
  rm: cannot remove 'test-dir/test-file': Permission denied

Change-Id: If5c0b05e875e50c118ebdedb59f3feba23fd0268
This commit is contained in:
Tristan Cacqueray 2020-07-08 12:34:48 +00:00
parent 18026465d6
commit d82ff8a755
1 changed files with 8 additions and 0 deletions

View File

@ -2605,6 +2605,14 @@ class ExecutorServer(BaseMergeServer):
# We use rm here instead of shutil because of
# https://bugs.python.org/issue22040
jobdir = os.path.join(self.jobdir_root, fn)
# First we need to ensure all directories are
# writable to avoid permission denied error
subprocess.Popen([
"find", jobdir,
# Filter non writable perms
"-type", "d", "!", "-perm", "/u+w",
# Replace by writable perms
"-exec", "chmod", "0700", "{}", "+"]).wait()
if subprocess.Popen(["rm", "-Rf", jobdir]).wait():
raise RuntimeError("Couldn't delete: " + jobdir)