1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-23 06:31:58 +00:00

Merge pull request #3961 from ThomasWaldmann/flags-fd-based

make bsdflags linux code fd-based
This commit is contained in:
TW 2018-07-07 18:05:58 +02:00 committed by GitHub
commit 8e91694c54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View file

@ -953,7 +953,7 @@ def stat_ext_attrs(self, st, path, fd=None):
with backup_io('extended stat'): with backup_io('extended stat'):
xattrs = xattr.get_all(fd or path, follow_symlinks=False) xattrs = xattr.get_all(fd or path, follow_symlinks=False)
if not self.nobsdflags: if not self.nobsdflags:
bsdflags = get_flags(path, st) bsdflags = get_flags(path, st, fd=fd)
acl_get(path, attrs, st, self.numeric_owner, fd=fd) acl_get(path, attrs, st, self.numeric_owner, fd=fd)
if xattrs: if xattrs:
attrs['xattrs'] = StableDict(xattrs) attrs['xattrs'] = StableDict(xattrs)

View file

@ -88,7 +88,7 @@ def set_flags(path, bsd_flags, fd=None):
pass pass
def get_flags(path, st): def get_flags(path, st, fd=None):
"""Return BSD-style file flags for path or stat without following symlinks.""" """Return BSD-style file flags for path or stat without following symlinks."""
return getattr(st, 'st_flags', 0) return getattr(st, 'st_flags', 0)

View file

@ -153,21 +153,24 @@ def set_flags(path, bsd_flags, fd=None):
os.close(fd) os.close(fd)
def get_flags(path, st): def get_flags(path, st, fd=None):
if stat.S_ISBLK(st.st_mode) or stat.S_ISCHR(st.st_mode) or stat.S_ISLNK(st.st_mode): if stat.S_ISBLK(st.st_mode) or stat.S_ISCHR(st.st_mode) or stat.S_ISLNK(st.st_mode):
# avoid opening devices files - trying to open non-present devices can be rather slow. # avoid opening devices files - trying to open non-present devices can be rather slow.
# avoid opening symlinks, O_NOFOLLOW would make the open() fail anyway. # avoid opening symlinks, O_NOFOLLOW would make the open() fail anyway.
return 0 return 0
cdef int linux_flags cdef int linux_flags
try: open_fd = fd is None
fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK|os.O_NOFOLLOW) if open_fd:
except OSError: try:
return 0 fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK|os.O_NOFOLLOW)
except OSError:
return 0
try: try:
if ioctl(fd, FS_IOC_GETFLAGS, &linux_flags) == -1: if ioctl(fd, FS_IOC_GETFLAGS, &linux_flags) == -1:
return 0 return 0
finally: finally:
os.close(fd) if open_fd:
os.close(fd)
bsd_flags = 0 bsd_flags = 0
for bsd_flag, linux_flag in BSD_TO_LINUX_FLAGS.items(): for bsd_flag, linux_flag in BSD_TO_LINUX_FLAGS.items():
if linux_flags & linux_flag: if linux_flags & linux_flag: