diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-02-22 16:04:42 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-02-27 15:26:55 +0000 |
commit | 42a9f54d191940dd1a155e91363fb5041ca63c05 (patch) | |
tree | 2efe04c8420a0ea02dfeabf1cc9ea168f1fbc7c4 /morphlib/bins.py | |
parent | 6cffb0dfb9a2be837bbb9b3b8de26806bfd0360f (diff) | |
download | morph-42a9f54d191940dd1a155e91363fb5041ca63c05.tar.gz |
Create chunks, strata in cache via temporary files
This avoids problems with files with the right names but partial
content, if morph is killed in the middle of writing the file.
Diffstat (limited to 'morphlib/bins.py')
-rw-r--r-- | morphlib/bins.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py index b4b5396e..0d704e49 100644 --- a/morphlib/bins.py +++ b/morphlib/bins.py @@ -27,8 +27,7 @@ import re import tarfile -def create_chunk(rootdir, chunk_filename, regexps, ex, - dump_memory_profile=None): +def create_chunk(rootdir, f, regexps, ex, dump_memory_profile=None): '''Create a chunk from the contents of a directory. Only files and directories that match at least one of the regular @@ -36,6 +35,8 @@ def create_chunk(rootdir, chunk_filename, regexps, ex, anchored to the beginning of the string, but not the end. The filenames are relative to rootdir. + ``f`` is an open file handle, to which the tar file is written. + ''' dump_memory_profile = dump_memory_profile or (lambda msg: None ) @@ -57,7 +58,7 @@ def create_chunk(rootdir, chunk_filename, regexps, ex, yield filename logging.debug('Creating chunk file %s from %s with regexps %s' % - (chunk_filename, rootdir, regexps)) + (f.name, rootdir, regexps)) dump_memory_profile('at beginning of create_chunk') compiled = [re.compile(x) for x in regexps] @@ -79,7 +80,7 @@ def create_chunk(rootdir, chunk_filename, regexps, ex, dump_memory_profile('after walking') include = sorted(include) # get dirs before contents - tar = tarfile.open(name=chunk_filename, mode='w:gz') + tar = tarfile.open(fileobj=f, mode='w:gz') for filename in include: tar.add(filename, arcname=mkrel(filename), recursive=False) tar.close() @@ -94,11 +95,12 @@ def create_chunk(rootdir, chunk_filename, regexps, ex, dump_memory_profile('after removing in create_chunks') -def create_stratum(rootdir, stratum_filename, ex): +def create_stratum(rootdir, f, ex): '''Create a stratum from the contents of a directory.''' - logging.debug('Creating stratum file %s from %s' % - (stratum_filename, rootdir)) - ex.runv(['tar', '-C', rootdir, '-caf', stratum_filename, '.']) + logging.debug('Creating stratum file %s from %s' % (f.name, rootdir)) + tar = tarfile.open(fileobj=f, mode='w:gz') + tar.add(rootdir, arcname='.') + tar.close() def unpack_binary(filename, dirname, ex): |