mirror of https://github.com/borgbackup/borg.git
Manifest: Make sure manifest timestamp is strictly monotonically increasing.
Computer clocks are often not set very accurately set, but borg assumes manifest timestamps are never going back in time. Ensure that this is actually the case.
This commit is contained in:
parent
d23dbb47ba
commit
6b8cf0aa8c
|
@ -110,6 +110,7 @@ class Manifest:
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
self.item_keys = frozenset(item_keys) if item_keys is not None else ITEM_KEYS
|
self.item_keys = frozenset(item_keys) if item_keys is not None else ITEM_KEYS
|
||||||
self.tam_verified = False
|
self.tam_verified = False
|
||||||
|
self.timestamp = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, repository, key=None, force_tam_not_required=False):
|
def load(cls, repository, key=None, force_tam_not_required=False):
|
||||||
|
@ -151,7 +152,13 @@ class Manifest:
|
||||||
def write(self):
|
def write(self):
|
||||||
if self.key.tam_required:
|
if self.key.tam_required:
|
||||||
self.config[b'tam_required'] = True
|
self.config[b'tam_required'] = True
|
||||||
|
# self.timestamp needs to be strictly monotonically increasing. Clocks often are not set correctly
|
||||||
|
if self.timestamp is None:
|
||||||
self.timestamp = datetime.utcnow().isoformat()
|
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 = {
|
m = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'archives': StableDict((name, StableDict(archive)) for name, archive in self.archives.items()),
|
'archives': StableDict((name, StableDict(archive)) for name, archive in self.archives.items()),
|
||||||
|
|
Loading…
Reference in New Issue