diff --git a/master/buildbot/newsfragments/make-slavedirectoryuploadcommand-robust.bugfix b/master/buildbot/newsfragments/make-slavedirectoryuploadcommand-robust.bugfix new file mode 100644 index 000000000000..541fad4bae03 --- /dev/null +++ b/master/buildbot/newsfragments/make-slavedirectoryuploadcommand-robust.bugfix @@ -0,0 +1 @@ +:py:class: `~buildbot_worker.commands.transfer.SlaveDirectoryUploadCommand` no longer throws exceptions because the file "is used by another process" under Windows diff --git a/worker/buildbot_worker/commands/transfer.py b/worker/buildbot_worker/commands/transfer.py index 49773eefba76..81e17d6e8b85 100644 --- a/worker/buildbot_worker/commands/transfer.py +++ b/worker/buildbot_worker/commands/transfer.py @@ -214,20 +214,22 @@ def start(self): # Create temporary archive fd, self.tarname = tempfile.mkstemp() - fileobj = os.fdopen(fd, 'wb') + self.fp = os.fdopen(fd, "rb+") + if self.compress == 'bz2': mode = 'w|bz2' elif self.compress == 'gz': mode = 'w|gz' else: mode = 'w' - archive = tarfile.open(name=self.tarname, mode=mode, fileobj=fileobj) + # TODO: Use 'with' when depending on Python 2.7 + # Not possible with older versions: exceptions.AttributeError: 'TarFile' object has no attribute '__exit__' + archive = tarfile.open(mode=mode, fileobj=self.fp) archive.add(self.path, '') archive.close() - fileobj.close() # Transfer it - self.fp = open(self.tarname, 'rb') + self.fp.seek(0) self.sendStatus({'header': "sending %s" % self.path})