Skip to content

Commit

Permalink
Windows specific directory handling
Browse files Browse the repository at this point in the history
On windows os.open does not work for directories.
If borg tries to open an directory on windows, None is returned
as file descriptor. The archive and archiver where adjusted to
handle the case if a file descriptor is None.
  • Loading branch information
jrast committed Aug 24, 2019
1 parent 6b426d0 commit bff97a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def OsOpen(*, flags, path=None, parent_fd=None, name=None, noatime=False, op='op
try:
yield fd
finally:
os.close(fd)
# On windows fd is None for directories.
if fd is not None:
os.close(fd)


class DownloadPipeline:
Expand Down
6 changes: 4 additions & 2 deletions src/borg/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,10 @@ def _process(self, *, path, parent_fd=None, name=None,
elif stat.S_ISDIR(st.st_mode):
with OsOpen(path=path, parent_fd=parent_fd, name=name, flags=flags_dir,
noatime=True, op='dir_open') as child_fd:
with backup_io('fstat'):
st = stat_update_check(st, os.fstat(child_fd))
# child_fd is None for directories on windows, in that case a race condition check is not possible.
if child_fd is not None:
with backup_io('fstat'):
st = stat_update_check(st, os.fstat(child_fd))
if recurse:
tag_names = dir_is_tagged(path, exclude_caches, exclude_if_present)
if tag_names:
Expand Down
4 changes: 4 additions & 0 deletions src/borg/helpers/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import textwrap

from .process import prepare_subprocess_env
from ..platformflags import is_win32

from ..constants import * # NOQA

Expand Down Expand Up @@ -230,6 +231,9 @@ def os_open(*, flags, path=None, parent_fd=None, name=None, noatime=False):
fname = name # use name relative to parent_fd
else:
fname, parent_fd = path, None # just use the path
if is_win32 and os.path.isdir(fname):
# Directories can not be opened on Windows.
return None
_flags_normal = flags
if noatime:
_flags_noatime = _flags_normal | O_('NOATIME')
Expand Down

0 comments on commit bff97a9

Please sign in to comment.