Reuse _detect_user() and _expand_home() in simple_backup()
The entry point repeated both, and its copy of the '~' expansion missed a bare '~'.
This commit is contained in:
@@ -1081,26 +1081,14 @@ def simple_backup() -> int:
|
|||||||
|
|
||||||
args = _parse_arguments()
|
args = _parse_arguments()
|
||||||
|
|
||||||
if args.user:
|
user: str | None = args.user or _detect_user()
|
||||||
user = args.user
|
|
||||||
homedir = os.path.expanduser(f'~{user}')
|
|
||||||
else:
|
|
||||||
euid = os.geteuid()
|
|
||||||
|
|
||||||
if euid == 0:
|
if not args.user and os.geteuid() != 0:
|
||||||
user = _detect_user()
|
homedir = os.getenv('HOME', '')
|
||||||
|
elif user is not None:
|
||||||
if user is not None:
|
homedir = _expand_home('~', user)
|
||||||
homedir = os.path.expanduser(f'~{user}')
|
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning('Failed to detect user. You can use -u/--user parameter to manually specify it')
|
||||||
'Failed to detect user. You can use -u/--user parameter to manually specify it')
|
|
||||||
homedir = None
|
|
||||||
else:
|
|
||||||
user = os.getenv('USER')
|
|
||||||
homedir = os.getenv('HOME')
|
|
||||||
|
|
||||||
if homedir is None:
|
|
||||||
homedir = ''
|
homedir = ''
|
||||||
|
|
||||||
if args.no_syslog:
|
if args.no_syslog:
|
||||||
@@ -1109,13 +1097,8 @@ def simple_backup() -> int:
|
|||||||
except NameError:
|
except NameError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
config_file = args.config
|
|
||||||
|
|
||||||
# Expand '~' to the home of the user running the backup, not root's
|
# Expand '~' to the home of the user running the backup, not root's
|
||||||
if config_file.startswith('~/') and user is not None:
|
config_file = _expand_home(args.config, user) if user is not None else os.path.expanduser(args.config)
|
||||||
config_file = f'~{user}{config_file[1:]}'
|
|
||||||
|
|
||||||
config_file = os.path.expanduser(config_file)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config_args = _read_config(config_file, user)
|
config_args = _read_config(config_file, user)
|
||||||
|
|||||||
Reference in New Issue
Block a user