1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 02:08:54 +00:00

Merge pull request #2115 from textshell/fix/manifest-timestamp

Manifest: Make sure manifest timestamp is strictly monotonically increasing.
This commit is contained in:
textshell 2017-02-04 16:17:45 +01:00 committed by GitHub
commit 5479ef469d

View file

@ -110,6 +110,7 @@ def __init__(self, key, repository, item_keys=None):
self.repository = repository
self.item_keys = frozenset(item_keys) if item_keys is not None else ITEM_KEYS
self.tam_verified = False
self.timestamp = None
@classmethod
def load(cls, repository, key=None, force_tam_not_required=False):
@ -151,7 +152,13 @@ def load(cls, repository, key=None, force_tam_not_required=False):
def write(self):
if self.key.tam_required:
self.config[b'tam_required'] = True
self.timestamp = datetime.utcnow().isoformat()
# self.timestamp needs to be strictly monotonically increasing. Clocks often are not set correctly
if self.timestamp is None:
self.timestamp = datetime.utcnow().isoformat()
else:
prev_ts = datetime.strptime(self.timestamp, "%Y-%m-%dT%H:%M:%S.%f")
incremented = (prev_ts + timedelta(microseconds=1)).isoformat()
self.timestamp = max(incremented, datetime.utcnow().isoformat())
m = {
'version': 1,
'archives': StableDict((name, StableDict(archive)) for name, archive in self.archives.items()),