mirror of
https://github.com/borgbackup/borg.git
synced 2026-07-16 23:12:21 -04:00
Merge pull request #2382 from ThomasWaldmann/backports2
1.0-maint backports
This commit is contained in:
commit
bb7d4bac13
3 changed files with 17 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ import argparse
|
|||
import faulthandler
|
||||
import functools
|
||||
import inspect
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
|
|
@ -2060,6 +2061,9 @@ class Archiver:
|
|||
if cmd is not None and result.func == self.do_serve:
|
||||
forced_result = result
|
||||
argv = shlex.split(cmd)
|
||||
# Drop environment variables (do *not* interpret them) before trying to parse
|
||||
# the borg command line.
|
||||
argv = list(itertools.dropwhile(lambda arg: '=' in arg, argv))
|
||||
result = self.parse_args(argv[1:])
|
||||
if result.func != forced_result.func:
|
||||
# someone is trying to execute a different borg subcommand, don't do that!
|
||||
|
|
@ -2075,10 +2079,11 @@ class Archiver:
|
|||
args = self.preprocess_args(args)
|
||||
parser = self.build_parser(args)
|
||||
args = parser.parse_args(args or ['-h'])
|
||||
if args.func == self.do_create:
|
||||
# This works around http://bugs.python.org/issue9351
|
||||
func = getattr(args, 'func', None) or getattr(args, 'fallback_func')
|
||||
if func == self.do_create and not args.paths:
|
||||
# need at least 1 path but args.paths may also be populated from patterns
|
||||
if not args.paths:
|
||||
parser.error('Need at least one PATH argument.')
|
||||
parser.error('Need at least one PATH argument.')
|
||||
return args
|
||||
|
||||
def run(self, args):
|
||||
|
|
|
|||
|
|
@ -216,9 +216,9 @@ def prune_within(archives, within):
|
|||
hours = int(within[:-1]) * multiplier[within[-1]]
|
||||
except (KeyError, ValueError):
|
||||
# I don't like how this displays the original exception too:
|
||||
raise argparse.ArgumentTypeError('Unable to parse --within option: "%s"' % within)
|
||||
raise argparse.ArgumentTypeError('Unable to parse --keep-within option: "%s"' % within)
|
||||
if hours <= 0:
|
||||
raise argparse.ArgumentTypeError('Number specified using --within option must be positive')
|
||||
raise argparse.ArgumentTypeError('Number specified using --keep-within option must be positive')
|
||||
target = datetime.now(timezone.utc) - timedelta(seconds=hours * 3600)
|
||||
return [a for a in archives if a.ts > target]
|
||||
|
||||
|
|
|
|||
|
|
@ -1800,6 +1800,13 @@ def test_get_args():
|
|||
'borg init /')
|
||||
assert args.func == archiver.do_serve
|
||||
|
||||
# Check that environment variables in the forced command don't cause issues. If the command
|
||||
# were not forced, environment variables would be interpreted by the shell, but this does not
|
||||
# happen for forced commands - we get the verbatim command line and need to deal with env vars.
|
||||
args = archiver.get_args(['borg', 'serve', ],
|
||||
'BORG_HOSTNAME_IS_UNIQUE=yes borg serve --info')
|
||||
assert args.func == archiver.do_serve
|
||||
|
||||
|
||||
class TestBuildFilter:
|
||||
def test_basic(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue