Skip to content

Commit

Permalink
In clobber source step, if permissions prevent rm -rf from deleting all,
Browse files Browse the repository at this point in the history
run a recursive chmod and re-try the rm -rf.

This avoids failures that require manual fixup if a step leaves behind
subdirectories with chmod 0 permissions.

This fixes ticket#29 for Posix systems (previous fix is blocking, and only
used on Windows).
  • Loading branch information
knielsen committed Nov 24, 2009
1 parent 8d6d4b7 commit 71f8aa9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion buildbot/slave/commands.py
Expand Up @@ -1573,7 +1573,7 @@ def maybeDoVCRetry(self, res):
return d
return res

def doClobber(self, dummy, dirname):
def doClobber(self, dummy, dirname, chmodDone=False):
# TODO: remove the old tree in the background
## workdir = os.path.join(self.builder.basedir, self.workdir)
## deaddir = self.workdir + ".deleting"
Expand Down Expand Up @@ -1608,7 +1608,29 @@ def doClobber(self, dummy, dirname):
# master, but not the rc=0 when it finishes. That job is left to
# _sendRC
d = c.start()
# The rm -rf may fail if there is a left-over subdir with chmod 000
# permissions. So if we get a failure, we attempt to chmod suitable
# permissions and re-try the rm -rf.
if chmodDone:
d.addCallback(self._abandonOnFailure)
else:
d.addCallback(lambda rc: self.doClobberTryChmodIfFail(rc, dirname))
return d

def doClobberTryChmodIfFail(self, rc, dirname):
assert isinstance(rc, int)
if rc == 0:
return defer.succeed(0)
# Attempt a recursive chmod and re-try the rm -rf after.
command = ["chmod", "-R", "u+rwx", os.path.join(self.builder.basedir, dirname)]
c = ShellCommand(self.builder, command, self.builder.basedir,
sendRC=0, timeout=self.timeout, maxTime=self.maxTime,
usePTY=False)

self.command = c
d = c.start()
d.addCallback(self._abandonOnFailure)
d.addCallback(lambda dummy: self.doClobber(dummy, dirname, True))
return d

def doCopy(self, res):
Expand Down
3 changes: 3 additions & 0 deletions buildbot/test/test_vc.py
Expand Up @@ -567,6 +567,9 @@ def _do_vctest_clobber_1(self, bs):
self.failUnlessEqual(bs.getProperty("branch"), None)
self.checkGotRevisionIsLatest(bs)

# Check that we can handle unfriendly permissions.
os.chmod(os.path.join(self.workdir, "subdir"), 0)
# Check that clobber really clobbers any old stuff.
self.touch(self.workdir, "newfile")
self.shouldExist(self.workdir, "newfile")
d = self.doBuild() # rebuild clobbers workdir
Expand Down

0 comments on commit 71f8aa9

Please sign in to comment.