From 86852c7d1d491d73ae9ecc64ee5a8c3dcece4ca0 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Mon, 21 Oct 2013 14:10:12 -0700 Subject: [PATCH] Include timestamps in reconstructed segment metadata. --- python/cumulus/rebuild_database.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/python/cumulus/rebuild_database.py b/python/cumulus/rebuild_database.py index 10513ba..07f0542 100755 --- a/python/cumulus/rebuild_database.py +++ b/python/cumulus/rebuild_database.py @@ -35,13 +35,16 @@ import struct import subprocess import sys import tarfile +import time import cumulus CHECKSUM_ALGORITHM = "sha224" - CHUNKER_PROGRAM = "cumulus-chunker-standalone" +# TODO: Move to somewhere common +SQLITE_TIMESTAMP = "%Y-%m-%d %H:%M:%S" + class Chunker(object): """Compute sub-file chunk boundaries using a sliding Rabin fingerprint. @@ -363,6 +366,11 @@ class SegmentStateRebuilder(object): if extension not in self.filters: return filter_cmd = self.filters[extension] + # File attributes. + st_buf = os.stat(path) + timestamp = time.strftime(SQLITE_TIMESTAMP, + time.gmtime(st_buf.st_mtime)) + # Compute attributes of the compressed segment data. BLOCK_SIZE = 4096 with open(path) as segment: @@ -385,11 +393,12 @@ class SegmentStateRebuilder(object): data_size += tarinfo.size object_count += 1 - return {"segment": segment_name, - "path": relative_path, + return {"segment": cumulus.uri_encode(segment_name), + "path": cumulus.uri_encode(relative_path), "checksum": checksum, "data_size": data_size, - "disk_size": disk_size} + "disk_size": disk_size, + "timestamp": timestamp} if __name__ == "__main__": if False: @@ -406,7 +415,7 @@ if __name__ == "__main__": os.path.relpath(f, topdir)) if metadata: for (k, v) in sorted(metadata.items()): - print "%s: %s" % (k, cumulus.uri_encode(str(v))) + print "%s: %s" % (k, v) print sys.exit(0) -- 2.20.1