From fa35525b5861697a3fce75000d69165b2b39d999 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 3 Nov 2015 19:52:49 +0100 Subject: [PATCH 1/2] create from stdin: also save atime, ctime cosmetic, just for completeness. --- borg/archive.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/borg/archive.py b/borg/archive.py index 2333a1029..86f671361 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -483,13 +483,14 @@ Number of files: {0.stats.nfiles}'''.format(self) for chunk in self.chunker.chunkify(fd): chunks.append(cache.add_chunk(self.key.id_hash(chunk), chunk, self.stats)) self.stats.nfiles += 1 + t = int_to_bigint(int(time.time()) * 1000000000) item = { b'path': path, b'chunks': chunks, b'mode': 0o100660, # regular file, ug=rw b'uid': uid, b'user': uid2user(uid), b'gid': gid, b'group': gid2group(gid), - b'mtime': int_to_bigint(int(time.time()) * 1000000000) + b'mtime': t, b'atime': t, b'ctime': t, } self.add_item(item) return 'i' # stdin From 12b5d07e559f1487d4e8de834b16f5210a4e7c5c Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 3 Nov 2015 20:21:52 +0100 Subject: [PATCH 2/2] fix RobustUnpacker, it missed some metadata keys. add check for unknown metadata keys. not just the new atime and ctime keys were missing, but also bsdflags. --- borg/archive.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/borg/archive.py b/borg/archive.py index 86f671361..a5db1d696 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -217,6 +217,9 @@ Number of files: {0.stats.nfiles}'''.format(self) yield item def add_item(self, item): + unknown_keys = set(item) - ITEM_KEYS + assert not unknown_keys, ('unknown item metadata keys detected, please update ITEM_KEYS: %s', + ','.join(k.decode('ascii') for k in unknown_keys)) if self.show_progress and time.time() - self.last_progress > 0.2: self.stats.show_progress(item=item) self.last_progress = time.time() @@ -589,10 +592,17 @@ Number of files: {0.stats.nfiles}'''.format(self) return Archive._open_rb(path, st) +# this set must be kept complete, otherwise the RobustUnpacker might malfunction: +ITEM_KEYS = set([b'path', b'source', b'rdev', b'chunks', + b'mode', b'user', b'group', b'uid', b'gid', b'mtime', b'atime', b'ctime', + b'xattrs', b'bsdflags', + ]) + + class RobustUnpacker: """A restartable/robust version of the streaming msgpack unpacker """ - item_keys = [msgpack.packb(name) for name in ('path', 'mode', 'source', 'chunks', 'rdev', 'xattrs', 'user', 'group', 'uid', 'gid', 'mtime')] + item_keys = [msgpack.packb(name) for name in ITEM_KEYS] def __init__(self, validator): super().__init__()