create: do not try to read parent dir of recursion root, fixes #7746

This commit is contained in:
Thomas Waldmann 2023-07-29 23:04:44 +02:00
parent 3e640a38c0
commit c99b849abe
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 23 additions and 34 deletions

View File

@ -24,7 +24,7 @@ from ..helpers import get_cache_dir, os_stat
from ..helpers import dir_is_tagged from ..helpers import dir_is_tagged
from ..helpers import log_multi from ..helpers import log_multi
from ..helpers import basic_json_data, json_print from ..helpers import basic_json_data, json_print
from ..helpers import flags_root, flags_dir, flags_special_follow, flags_special from ..helpers import flags_dir, flags_special_follow, flags_special
from ..helpers import sig_int, ignore_sigint from ..helpers import sig_int, ignore_sigint
from ..helpers import iter_separated from ..helpers import iter_separated
from ..helpers import MakePathSafeAction from ..helpers import MakePathSafeAction
@ -156,25 +156,14 @@ class CreateMixIn:
fso.stats.files_stats[status] += 1 fso.stats.files_stats[status] += 1
continue continue
path = os.path.normpath(path) path = os.path.normpath(path)
parent_dir = os.path.dirname(path) or "."
name = os.path.basename(path)
try: try:
# note: for path == '/': name == '' and parent_dir == '/'. with backup_io("stat"):
# the empty name will trigger a fall-back to path-based processing in os_stat and os_open. st = os_stat(path=path, parent_fd=None, name=None, follow_symlinks=False)
with OsOpen(path=parent_dir, flags=flags_root, noatime=True, op="open_root") as parent_fd: restrict_dev = st.st_dev if args.one_file_system else None
try:
st = os_stat(path=path, parent_fd=parent_fd, name=name, follow_symlinks=False)
except OSError as e:
self.print_warning("%s: %s", path, e)
continue
if args.one_file_system:
restrict_dev = st.st_dev
else:
restrict_dev = None
self._rec_walk( self._rec_walk(
path=path, path=path,
parent_fd=parent_fd, parent_fd=None,
name=name, name=None,
fso=fso, fso=fso,
cache=cache, cache=cache,
matcher=matcher, matcher=matcher,
@ -190,7 +179,7 @@ class CreateMixIn:
# we do not ever want to get back in there (even if path is given twice as recursion root) # we do not ever want to get back in there (even if path is given twice as recursion root)
skip_inodes.add((st.st_ino, st.st_dev)) skip_inodes.add((st.st_ino, st.st_dev))
except (BackupOSError, BackupError) as e: except (BackupOSError, BackupError) as e:
# this comes from OsOpen, self._rec_walk has own exception handler # this comes from os.stat, self._rec_walk has own exception handler
self.print_warning("%s: %s", path, e) self.print_warning("%s: %s", path, e)
continue continue
if not dry_run: if not dry_run: