mirror of https://github.com/borgbackup/borg.git
create: handle BackupOSError on a per-path level in one spot
This commit is contained in:
parent
22464295cf
commit
73990b878f
|
@ -29,7 +29,7 @@ import borg
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from . import helpers
|
from . import helpers
|
||||||
from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
|
from .archive import Archive, ArchiveChecker, ArchiveRecreater, Statistics, is_special
|
||||||
from .archive import BackupOSError
|
from .archive import BackupOSError, backup_io
|
||||||
from .cache import Cache
|
from .cache import Cache
|
||||||
from .constants import * # NOQA
|
from .constants import * # NOQA
|
||||||
from .crc32 import crc32
|
from .crc32 import crc32
|
||||||
|
@ -396,101 +396,98 @@ class Archiver:
|
||||||
def _process(self, archive, cache, matcher, exclude_caches, exclude_if_present,
|
def _process(self, archive, cache, matcher, exclude_caches, exclude_if_present,
|
||||||
keep_exclude_tags, skip_inodes, path, restrict_dev,
|
keep_exclude_tags, skip_inodes, path, restrict_dev,
|
||||||
read_special=False, dry_run=False, st=None):
|
read_special=False, dry_run=False, st=None):
|
||||||
|
"""
|
||||||
|
Process *path* recursively according to the various parameters.
|
||||||
|
|
||||||
|
*st* (if given) is a *os.stat_result* object for *path*.
|
||||||
|
|
||||||
|
This should only raise on critical errors. Per-item errors must be handled within this method.
|
||||||
|
"""
|
||||||
if not matcher.match(path):
|
if not matcher.match(path):
|
||||||
self.print_file_status('x', path)
|
self.print_file_status('x', path)
|
||||||
return
|
return
|
||||||
if st is None:
|
|
||||||
try:
|
|
||||||
st = os.lstat(path)
|
|
||||||
except OSError as e:
|
|
||||||
self.print_warning('%s: stat: %s', path, e)
|
|
||||||
return
|
|
||||||
if (st.st_ino, st.st_dev) in skip_inodes:
|
|
||||||
return
|
|
||||||
# if restrict_dev is given, we do not want to recurse into a new filesystem,
|
|
||||||
# but we WILL save the mountpoint directory (or more precise: the root
|
|
||||||
# directory of the mounted filesystem that shadows the mountpoint dir).
|
|
||||||
recurse = restrict_dev is None or st.st_dev == restrict_dev
|
|
||||||
status = None
|
|
||||||
# Ignore if nodump flag is set
|
|
||||||
try:
|
try:
|
||||||
if get_flags(path, st) & stat.UF_NODUMP:
|
if st is None:
|
||||||
self.print_file_status('x', path)
|
with backup_io('stat'):
|
||||||
|
st = os.lstat(path)
|
||||||
|
if (st.st_ino, st.st_dev) in skip_inodes:
|
||||||
return
|
return
|
||||||
except OSError as e:
|
# if restrict_dev is given, we do not want to recurse into a new filesystem,
|
||||||
self.print_warning('%s: flags: %s', path, e)
|
# but we WILL save the mountpoint directory (or more precise: the root
|
||||||
return
|
# directory of the mounted filesystem that shadows the mountpoint dir).
|
||||||
if stat.S_ISREG(st.st_mode):
|
recurse = restrict_dev is None or st.st_dev == restrict_dev
|
||||||
if not dry_run:
|
status = None
|
||||||
try:
|
# Ignore if nodump flag is set
|
||||||
status = archive.process_file(path, st, cache, self.ignore_inode)
|
with backup_io('flags'):
|
||||||
except BackupOSError as e:
|
if get_flags(path, st) & stat.UF_NODUMP:
|
||||||
status = 'E'
|
self.print_file_status('x', path)
|
||||||
self.print_warning('%s: %s', path, e)
|
|
||||||
elif stat.S_ISDIR(st.st_mode):
|
|
||||||
if recurse:
|
|
||||||
tag_paths = dir_is_tagged(path, exclude_caches, exclude_if_present)
|
|
||||||
if tag_paths:
|
|
||||||
if keep_exclude_tags and not dry_run:
|
|
||||||
archive.process_dir(path, st)
|
|
||||||
for tag_path in tag_paths:
|
|
||||||
self._process(archive, cache, matcher, exclude_caches, exclude_if_present,
|
|
||||||
keep_exclude_tags, skip_inodes, tag_path, restrict_dev,
|
|
||||||
read_special=read_special, dry_run=dry_run)
|
|
||||||
return
|
return
|
||||||
if not dry_run:
|
if stat.S_ISREG(st.st_mode):
|
||||||
status = archive.process_dir(path, st)
|
if not dry_run:
|
||||||
if recurse:
|
status = archive.process_file(path, st, cache, self.ignore_inode)
|
||||||
try:
|
elif stat.S_ISDIR(st.st_mode):
|
||||||
entries = helpers.scandir_inorder(path)
|
if recurse:
|
||||||
except OSError as e:
|
tag_paths = dir_is_tagged(path, exclude_caches, exclude_if_present)
|
||||||
status = 'E'
|
if tag_paths:
|
||||||
self.print_warning('%s: scandir: %s', path, e)
|
if keep_exclude_tags and not dry_run:
|
||||||
else:
|
archive.process_dir(path, st)
|
||||||
|
for tag_path in tag_paths:
|
||||||
|
self._process(archive, cache, matcher, exclude_caches, exclude_if_present,
|
||||||
|
keep_exclude_tags, skip_inodes, tag_path, restrict_dev,
|
||||||
|
read_special=read_special, dry_run=dry_run)
|
||||||
|
return
|
||||||
|
if not dry_run:
|
||||||
|
status = archive.process_dir(path, st)
|
||||||
|
if recurse:
|
||||||
|
with backup_io('scandir'):
|
||||||
|
entries = helpers.scandir_inorder(path)
|
||||||
for dirent in entries:
|
for dirent in entries:
|
||||||
normpath = os.path.normpath(dirent.path)
|
normpath = os.path.normpath(dirent.path)
|
||||||
self._process(archive, cache, matcher, exclude_caches, exclude_if_present,
|
self._process(archive, cache, matcher, exclude_caches, exclude_if_present,
|
||||||
keep_exclude_tags, skip_inodes, normpath, restrict_dev,
|
keep_exclude_tags, skip_inodes, normpath, restrict_dev,
|
||||||
read_special=read_special, dry_run=dry_run)
|
read_special=read_special, dry_run=dry_run)
|
||||||
elif stat.S_ISLNK(st.st_mode):
|
elif stat.S_ISLNK(st.st_mode):
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
if not read_special:
|
if not read_special:
|
||||||
status = archive.process_symlink(path, st)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
st_target = os.stat(path)
|
|
||||||
except OSError:
|
|
||||||
special = False
|
|
||||||
else:
|
|
||||||
special = is_special(st_target.st_mode)
|
|
||||||
if special:
|
|
||||||
status = archive.process_file(path, st_target, cache)
|
|
||||||
else:
|
|
||||||
status = archive.process_symlink(path, st)
|
status = archive.process_symlink(path, st)
|
||||||
elif stat.S_ISFIFO(st.st_mode):
|
else:
|
||||||
if not dry_run:
|
try:
|
||||||
if not read_special:
|
st_target = os.stat(path)
|
||||||
status = archive.process_fifo(path, st)
|
except OSError:
|
||||||
else:
|
special = False
|
||||||
status = archive.process_file(path, st, cache)
|
else:
|
||||||
elif stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode):
|
special = is_special(st_target.st_mode)
|
||||||
if not dry_run:
|
if special:
|
||||||
if not read_special:
|
status = archive.process_file(path, st_target, cache)
|
||||||
status = archive.process_dev(path, st)
|
else:
|
||||||
else:
|
status = archive.process_symlink(path, st)
|
||||||
status = archive.process_file(path, st, cache)
|
elif stat.S_ISFIFO(st.st_mode):
|
||||||
elif stat.S_ISSOCK(st.st_mode):
|
if not dry_run:
|
||||||
# Ignore unix sockets
|
if not read_special:
|
||||||
return
|
status = archive.process_fifo(path, st)
|
||||||
elif stat.S_ISDOOR(st.st_mode):
|
else:
|
||||||
# Ignore Solaris doors
|
status = archive.process_file(path, st, cache)
|
||||||
return
|
elif stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode):
|
||||||
elif stat.S_ISPORT(st.st_mode):
|
if not dry_run:
|
||||||
# Ignore Solaris event ports
|
if not read_special:
|
||||||
return
|
status = archive.process_dev(path, st)
|
||||||
else:
|
else:
|
||||||
self.print_warning('Unknown file type: %s', path)
|
status = archive.process_file(path, st, cache)
|
||||||
return
|
elif stat.S_ISSOCK(st.st_mode):
|
||||||
|
# Ignore unix sockets
|
||||||
|
return
|
||||||
|
elif stat.S_ISDOOR(st.st_mode):
|
||||||
|
# Ignore Solaris doors
|
||||||
|
return
|
||||||
|
elif stat.S_ISPORT(st.st_mode):
|
||||||
|
# Ignore Solaris event ports
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.print_warning('Unknown file type: %s', path)
|
||||||
|
return
|
||||||
|
except BackupOSError as e:
|
||||||
|
self.print_warning('%s: %s', path, e)
|
||||||
|
status = 'E'
|
||||||
# Status output
|
# Status output
|
||||||
if status is None:
|
if status is None:
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
|
|
Loading…
Reference in New Issue