1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-14 16:11:43 +00:00

get rid of datetime.isoformat to avoid bugs like #2994

(cherry picked from commit 928bde8676)
This commit is contained in:
Thomas Waldmann 2017-09-05 06:13:47 +02:00
parent a9aa3c5f34
commit da2f8dbe81
4 changed files with 10 additions and 9 deletions

View file

@ -461,8 +461,8 @@ Utilization of max. archive size: {csize_max:.0%}
'cmdline': sys.argv,
'hostname': socket.gethostname(),
'username': getuser(),
'time': start.isoformat(),
'time_end': end.isoformat(),
'time': start.strftime(ISO_FORMAT),
'time_end': end.strftime(ISO_FORMAT),
'chunker_params': self.chunker_params,
}
metadata.update(additional_metadata or {})

View file

@ -216,7 +216,7 @@ class Archives(abc.MutableMapping):
id, ts = info
assert isinstance(id, bytes)
if isinstance(ts, datetime):
ts = ts.replace(tzinfo=None).isoformat()
ts = ts.replace(tzinfo=None).strftime(ISO_FORMAT)
assert isinstance(ts, str)
ts = ts.encode()
self._archives[name] = {b'id': id, b'time': ts}
@ -388,11 +388,11 @@ class Manifest:
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().strftime(ISO_FORMAT)
else:
prev_ts = self.last_timestamp
incremented = (prev_ts + timedelta(microseconds=1)).isoformat()
self.timestamp = max(incremented, datetime.utcnow().isoformat())
incremented = (prev_ts + timedelta(microseconds=1)).strftime(ISO_FORMAT)
self.timestamp = max(incremented, datetime.utcnow().strftime(ISO_FORMAT))
# include checks for limits as enforced by limited unpacker (used by load())
assert len(self.archives) <= MAX_ARCHIVES
assert all(len(name) <= 255 for name in self.archives)

View file

@ -540,7 +540,8 @@ class Repository:
# Log transaction in append-only mode
if self.append_only:
with open(os.path.join(self.path, 'transactions'), 'a') as log:
print('transaction %d, UTC time %s' % (transaction_id, datetime.utcnow().isoformat()), file=log)
print('transaction %d, UTC time %s' % (
transaction_id, datetime.utcnow().strftime(ISO_FORMAT)), file=log)
# Write hints file
hints_name = 'hints.%d' % transaction_id

View file

@ -3035,7 +3035,7 @@ class ManifestAuthenticationTest(ArchiverTestCaseBase):
'version': 1,
'archives': {},
'config': {},
'timestamp': (datetime.utcnow() + timedelta(days=1)).isoformat(),
'timestamp': (datetime.utcnow() + timedelta(days=1)).strftime(ISO_FORMAT),
})))
repository.commit()
@ -3047,7 +3047,7 @@ class ManifestAuthenticationTest(ArchiverTestCaseBase):
repository.put(Manifest.MANIFEST_ID, key.encrypt(msgpack.packb({
'version': 1,
'archives': {},
'timestamp': (datetime.utcnow() + timedelta(days=1)).isoformat(),
'timestamp': (datetime.utcnow() + timedelta(days=1)).strftime(ISO_FORMAT),
})))
repository.commit()