summaryrefslogtreecommitdiff
path: root/morphlib/bins.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-06-29 11:17:02 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-06-29 11:17:02 +0100
commitfee76889e3c5634bc759ed6c9b7056dc10b71a4c (patch)
tree40e7219a08956523be581e636619ac7a8a581ce9 /morphlib/bins.py
parentda6058c4dbfa23b045c67d27cac81308974d492a (diff)
downloadmorph-fee76889e3c5634bc759ed6c9b7056dc10b71a4c.tar.gz
Normalize timestamps without filesystem operations
This changes the timestamp in the Python tarfile.TarInfo data structure rather than setting the timestamp in the filesystem. Suggested by Richard Maw.
Diffstat (limited to 'morphlib/bins.py')
-rw-r--r--morphlib/bins.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py
index f1d841ef..ce17d0a1 100644
--- a/morphlib/bins.py
+++ b/morphlib/bins.py
@@ -47,7 +47,7 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None):
# chunk artifact. This is useful to avoid problems from smallish
# clock skew. It needs to be recent enough, however, that GNU tar
# does not complain about an implausibly old timestamp.
- normalized_timestamp = (683074800, 683074800)
+ normalized_timestamp = 683074800
def mkrel(filename):
assert filename.startswith(rootdir)
@@ -89,9 +89,14 @@ def create_chunk(rootdir, f, regexps, dump_memory_profile=None):
tar = tarfile.open(fileobj=f, mode='w:gz')
for filename in include:
# Normalize mtime for everything.
- if not os.path.islink(filename):
- os.utime(filename, normalized_timestamp)
- tar.add(filename, arcname=mkrel(filename), recursive=False)
+ tarinfo = tar.gettarinfo(filename, arcname=mkrel(filename))
+ tarinfo.ctime = normalized_timestamp
+ tarinfo.mtime = normalized_timestamp
+ if tarinfo.isreg():
+ with open(filename, 'rb') as f:
+ tar.addfile(tarinfo, fileobj=f)
+ else:
+ tar.addfile(tarinfo)
tar.close()
include.remove(rootdir)