diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2011-12-06 19:44:20 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2011-12-06 19:44:20 +0000 |
commit | c33719699a5c473cc145702599ec215f0fd455c2 (patch) | |
tree | 4699d7a650f9af848524eac5701d500f994cbad4 /morphlib/bins.py | |
parent | 8b104b27691c2d6b717c80d56914295f2bdba74d (diff) | |
download | morph-c33719699a5c473cc145702599ec215f0fd455c2.tar.gz |
use external tar tool
This saves a bunch of memory use.
Diffstat (limited to 'morphlib/bins.py')
-rw-r--r-- | morphlib/bins.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py index aab684f5..d8cbf8e0 100644 --- a/morphlib/bins.py +++ b/morphlib/bins.py @@ -24,7 +24,7 @@ Binaries are chunks, strata, and system images. import logging import os import re -import tarfile +import tempfile import morphlib @@ -79,12 +79,16 @@ def create_chunk(rootdir, chunk_filename, regexps, dump_memory_profile=None): logging.debug('regexp MISMATCH: %s' % filename) dump_memory_profile('after walking') - include = sorted(include) - - tar = tarfile.open(name=chunk_filename, mode='w:gz') - for filename in include: - tar.add(filename, arcname=mkrel(filename), recursive=False) - tar.close() + include = sorted(include) # get dirs before contents + fd, include_filename = tempfile.mkstemp() + os.close(fd) + with open(include_filename, 'w') as f: + for name in include: + f.write('%s\0' % mkrel(name)) + ex = morphlib.execute.Execute('.', lambda msg: None) + ex.runv(['tar', '-C', rootdir, '-caf', chunk_filename, + '--null', '-T', include_filename, '--no-recursion']) + os.remove(include_filename) dump_memory_profile('after creating tarball') include.remove(rootdir) @@ -101,9 +105,8 @@ def create_stratum(rootdir, stratum_filename): '''Create a stratum from the contents of a directory.''' logging.debug('Creating stratum file %s from %s' % (stratum_filename, rootdir)) - tar = tarfile.open(name=stratum_filename, mode='w:gz') - tar.add(rootdir, arcname='.') - tar.close() + ex = morphlib.execute.Execute('.', lambda msg: None) + ex.runv(['tar', '-C', rootdir, '-caf', stratum_filename, '.']) def unpack_binary(filename, dirname): |