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

Use --timestamp for {utcnow} and {now} if given (fixes #5189)

This commit is contained in:
Milkey Mouse 2020-11-02 15:07:41 -08:00
parent 47e96bc261
commit 16c49d177b
No known key found for this signature in database
GPG key ID: C6EF5A02F5647987
2 changed files with 14 additions and 5 deletions

View file

@ -4496,6 +4496,8 @@ def parse_args(self, args=None):
self.do_list, self.do_mount, self.do_umount}
if func not in bypass_allowed:
raise Error('Not allowed to bypass locking mechanism for chosen command')
if getattr(args, 'timestamp', None):
args.location = args.location.with_timestamp(args.timestamp)
return args
def prerun_checks(self, logger, is_serve):

View file

@ -203,7 +203,7 @@ def format_line(format, data):
raise PlaceholderError(format, data, e.__class__.__name__, str(e))
def replace_placeholders(text):
def replace_placeholders(text, overrides={}):
"""Replace placeholders in text with their values."""
from ..platform import fqdn, hostname, getosusername
current_time = datetime.now(timezone.utc)
@ -220,6 +220,7 @@ def replace_placeholders(text):
'borgmajor': '%d' % borg_version_tuple[:1],
'borgminor': '%d.%d' % borg_version_tuple[:2],
'borgpatch': '%d.%d.%d' % borg_version_tuple[:3],
**overrides,
}
return format_line(text, data)
@ -387,13 +388,13 @@ class Location:
)
""" + optional_archive_re, re.VERBOSE) # archive name (optional, may be empty)
def __init__(self, text=''):
if not self.parse(text):
def __init__(self, text='', overrides={}):
if not self.parse(text, overrides):
raise ValueError('Invalid location format: "%s"' % self.orig)
def parse(self, text):
def parse(self, text, overrides={}):
self.orig = text
text = replace_placeholders(text)
text = replace_placeholders(text, overrides)
valid = self._parse(text)
if valid:
return True
@ -497,6 +498,12 @@ def canonical_path(self):
':{}'.format(self.port) if self.port else '',
path)
def with_timestamp(self, timestamp):
return Location(self.orig, overrides={
'now': DatetimeWrapper(timestamp.astimezone(None)),
'utcnow': DatetimeWrapper(timestamp),
})
def location_validator(archive=None, proto=None):
def validator(text):