summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2015-06-30 14:08:01 -0400
committerJonathan Reams <jbreams@mongodb.com>2015-07-01 11:43:21 -0400
commit9a743c6fb3c143cc45ea89842243e480fdf229a3 (patch)
tree98fb2f8fc5a079c6114622499cf439d448dd65ec
parentc87142d4649e81c2de694b36a78115bfde5bf548 (diff)
downloadmongo-9a743c6fb3c143cc45ea89842243e480fdf229a3.tar.gz
SERVER-19229 Only open tar archives in append mode if actually appending
-rw-r--r--site_scons/site_tools/distsrc.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/site_scons/site_tools/distsrc.py b/site_scons/site_tools/distsrc.py
index d9e3f7f73eb..861f5d9e2e2 100644
--- a/site_scons/site_tools/distsrc.py
+++ b/site_scons/site_tools/distsrc.py
@@ -34,16 +34,31 @@ class DistSrcFile:
return self.name
class DistSrcArchive:
- def __init__(self, archive_type, archive_file):
+ def __init__(self, archive_type, archive_file, filename, mode):
self.archive_type = archive_type
self.archive_file = archive_file
+ self.archive_name = filename
+ self.archive_mode = mode
@staticmethod
def Open(filename):
if filename.endswith("tar"):
- return DistSrcTarArchive('tar', tarfile.open(filename, 'a'))
+ return DistSrcTarArchive(
+ 'tar',
+ tarfile.open(filename, 'r', format=tarfile.PAX_FORMAT),
+ filename,
+ 'r',
+ )
elif filename.endswith("zip"):
- return DistSrcZipArchive('zip', zipfile.ZipFile(filename, 'a'))
+ return DistSrcZipArchive(
+ 'zip',
+ zipfile.ZipFile(filename, 'a'),
+ filename,
+ 'a',
+ )
+
+ def close(self):
+ self.archive_file.close()
class DistSrcTarArchive(DistSrcArchive):
def __iter__(self):
@@ -77,6 +92,14 @@ class DistSrcTarArchive(DistSrcArchive):
file_metadata.gname = gname
file_metadata.size = len(file_contents)
file_buf = StringIO.StringIO(file_contents)
+ if self.archive_mode == 'r':
+ self.archive_file.close()
+ self.archive_file = tarfile.open(
+ self.archive_name,
+ 'a',
+ format=tarfile.PAX_FORMAT,
+ )
+ self.archive_mode = 'a'
self.archive_file.addfile(file_metadata, fileobj=file_buf)
def append_file(self, filename, localfile):
@@ -135,6 +158,7 @@ def distsrc_action_generator(source, target, env, for_signature):
archive_wrapper = DistSrcArchive.Open(str(target[0]))
for fn in __distsrc_callbacks:
fn(env, archive_wrapper)
+ archive_wrapper.close()
target_ext = str(target[0])[-3:]
if not target_ext in [ 'zip', 'tar' ]: