diff options
Diffstat (limited to 'feed/sse_tar.py')
-rwxr-xr-x | feed/sse_tar.py | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/feed/sse_tar.py b/feed/sse_tar.py index b326d97..1b0ff05 100755 --- a/feed/sse_tar.py +++ b/feed/sse_tar.py @@ -5,22 +5,38 @@ import sse_feed, sse_db from sse_config import * from sse_defs import * -import tarfile, zipfile, sys, os, time, zlib +import tarfile, zipfile, sys, os, time, zlib, tempfile from md5 import new as message_digest tar_suffixes = [ ".tar.gz", ".tar.bz2", ".tgz", ".tbz2", ".tar" ] -def uncompress_tar(archive, root, package_id, meta = {}, fo = None, descend = True, subarchive = None): +def copy_file_to(dst, x): + + if type(dst) is str: + o = file(dst, "w") + else: + o = dst + + while True: + data = x.read(SSE_BLOCK_SIZE) + + if len(data) <= 0: + break + + o.write(data) + o.close() + +def uncompress_tar(archive, root, package_id, meta = {}, tmp = None, descend = True, subarchive = None): global n_depth n = 0 - if fo is None: + if tmp is None: f = tarfile.open(archive, "r") print "Processing TAR file %s." % archive else: - f = tarfile.open(subarchive, "r", fo) - print "Processing subarchive TAR file %s." % subarchive + f = tarfile.open(tmp, "r") + print "Processing temporary TAR file %s." % tmp while True: @@ -51,7 +67,14 @@ def uncompress_tar(archive, root, package_id, meta = {}, fo = None, descend = Tr except: pass - n += uncompress_tar(archive, root, package_id, meta, f.extractfile(i), False, i.name) + o, tmp_archive = tempfile.mkstemp() + copy_file_to(o, f.extractfile(i)) + + try: + n += uncompress_tar(archive, root, package_id, meta, tmp_archive, False, i.name) + finally: + unlink(tmp_archive) + print "Subarchive ended, continuing with top level archive..." continue @@ -63,16 +86,7 @@ def uncompress_tar(archive, root, package_id, meta = {}, fo = None, descend = Tr except: pass - x = f.extractfile(i) - o = file(dst, "w") - while True: - data = x.read(SSE_BLOCK_SIZE) - - if len(data) <= 0: - break - - o.write(data) - o.close() + copy_file_to(dst, f.extractfile(i)) os.utime(dst, (i.mtime, i.mtime)) |