Skip to content

Commit

Permalink
Fix DirectoryUpload
Browse files Browse the repository at this point in the history
3f3edec broke DirectoryUpload by switching FileUpload to use a
temporary file and doing a rename to move it in place. This
commit updates DirectoryUpload to cope with the new behaviour.
  • Loading branch information
John Carr committed Aug 29, 2010
1 parent e2ceec8 commit b016692
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions master/buildbot/steps/transfer.py
Expand Up @@ -107,37 +107,41 @@ def _extractall(self, path=".", members=None):
class _DirectoryWriter(_FileWriter):
"""
A DirectoryWriter is implemented as a FileWriter, with an added post-processing
step to unpack the archive, once the transfer has completed. Note that the close()
method is not called!
step to unpack the archive, once the transfer has completed.
"""

def __init__(self, destroot, maxsize, compress, mode):
self.destroot = destroot
self.compress = compress

self.fd, self.tarname = tempfile.mkstemp()
self.compress = compress
os.close(self.fd)

_FileWriter.__init__(self, self.tarname, maxsize, mode)

def remote_unpack(self):
"""
Called by remote slave to state that no more data will be transfered
"""
if self.fp:
self.fp.close()
self.fp = None
fileobj = os.fdopen(self.fd, 'rb')
# Make sure remote_close is called, otherwise atomic rename wont happen
self.remote_close()

# Map configured compression to a TarFile setting
if self.compress == 'bz2':
mode='r|bz2'
elif self.compress == 'gz':
mode='r|gz'
else:
mode = 'r'

# Support old python
if not hasattr(tarfile.TarFile, 'extractall'):
tarfile.TarFile.extractall = _extractall
archive = tarfile.open(name=self.tarname, mode=mode, fileobj=fileobj)

# Unpack archive and clean up after self
archive = tarfile.open(name=self.tarname, mode=mode)
archive.extractall(path=self.destroot)
archive.close()
fileobj.close()
os.remove(self.tarname)


Expand Down

0 comments on commit b016692

Please sign in to comment.