Skip to content

Commit

Permalink
Merge pull request #5583 from ThomasWaldmann/extract-xattr-eperm-1.1
Browse files Browse the repository at this point in the history
extract: catch EPERM when setting xattrs, fixes #5092
  • Loading branch information
ThomasWaldmann authored Dec 24, 2020
2 parents 5cc9d03 + 120de38 commit 7db3cc0
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,28 +770,23 @@ def restore_attrs(self, path, item, symlink=False, fd=None):
try:
xattr.setxattr(fd or path, k, v, follow_symlinks=False)
except OSError as e:
msg_format = '%s: when setting extended attribute %s: %%s' % (path, k.decode())
if e.errno == errno.E2BIG:
# xattr is too big
logger.warning('%s: Value or key of extended attribute %s is too big for this filesystem' %
(path, k.decode()))
set_ec(EXIT_WARNING)
err_str = 'too big for this filesystem'
elif e.errno == errno.ENOTSUP:
# xattrs not supported here
logger.warning('%s: Extended attributes are not supported on this filesystem' % path)
set_ec(EXIT_WARNING)
elif e.errno == errno.EACCES:
# permission denied to set this specific xattr (this may happen related to security.* keys)
logger.warning('%s: Permission denied when setting extended attribute %s' % (path, k.decode()))
set_ec(EXIT_WARNING)
err_str = 'xattrs not supported on this filesystem'
elif e.errno == errno.ENOSPC:
# no space left on device while setting this specific xattr
# ext4 reports ENOSPC when trying to set an xattr with >4kiB while ext4 can only support 4kiB xattrs
# (in this case, this is NOT a "disk full" error, just a ext4 limitation).
logger.warning('%s: No space left on device while setting extended attribute %s (len = %d)' % (
path, k.decode(), len(v)))
set_ec(EXIT_WARNING)
err_str = 'no space left on device [xattr len = %d]' % (len(v), )
else:
raise
# generic handler
# EACCES: permission denied to set this specific xattr (this may happen related to security.* keys)
# EPERM: operation not permitted
err_str = str(e)
logger.warning(msg_format % err_str)
set_ec(EXIT_WARNING)
# bsdflags include the immutable flag and need to be set last:
if not self.nobsdflags and 'bsdflags' in item:
try:
Expand Down

0 comments on commit 7db3cc0

Please sign in to comment.