mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 21:56:44 +00:00
Merge pull request #3162 from ThomasWaldmann/dont-open-special-1.1
bsdflags support: do not open BLK/CHR/LNK files, fixes #3130
This commit is contained in:
commit
7a05b4c960
1 changed files with 9 additions and 2 deletions
|
@ -72,8 +72,11 @@ BSD_TO_LINUX_FLAGS = {
|
||||||
|
|
||||||
|
|
||||||
def set_flags(path, bsd_flags, fd=None):
|
def set_flags(path, bsd_flags, fd=None):
|
||||||
if fd is None and stat.S_ISLNK(os.lstat(path).st_mode):
|
if fd is None:
|
||||||
return
|
st = os.stat(path, follow_symlinks=False)
|
||||||
|
if stat.S_ISBLK(st.st_mode) or stat.S_ISCHR(st.st_mode) or stat.S_ISLNK(st.st_mode):
|
||||||
|
# see comment in get_flags()
|
||||||
|
return
|
||||||
cdef int flags = 0
|
cdef int 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 bsd_flags & bsd_flag:
|
if bsd_flags & bsd_flag:
|
||||||
|
@ -92,6 +95,10 @@ def set_flags(path, bsd_flags, fd=None):
|
||||||
|
|
||||||
|
|
||||||
def get_flags(path, st):
|
def get_flags(path, st):
|
||||||
|
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 symlinks, O_NOFOLLOW would make the open() fail anyway.
|
||||||
|
return 0
|
||||||
cdef int linux_flags
|
cdef int linux_flags
|
||||||
try:
|
try:
|
||||||
fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK|os.O_NOFOLLOW)
|
fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK|os.O_NOFOLLOW)
|
||||||
|
|
Loading…
Reference in a new issue