From 7afb66df403c24730cd80d4bd7b0c7349020544c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 22 Sep 2017 14:48:36 +0200 Subject: [PATCH] Windows: restore attributes on directories For unknown reason, directories were skipped when applying windows attributes. We now apply attributes also to directories. We need the additional access right GENERIC_READ even when only opening directories WRITE_ONLY, as otherwise access is denied when applying the compressed attribute. Fixes #629: windows: Attributes for directories not restored --- src/findlib/bfile.c | 4 ++-- src/win32/compat/compat.c | 38 ++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/findlib/bfile.c b/src/findlib/bfile.c index e4a43de7640..9a4615c5cca 100644 --- a/src/findlib/bfile.c +++ b/src/findlib/bfile.c @@ -651,14 +651,14 @@ static inline int bopen_nonencrypted(BFILE *bfd, const char *fname, int flags, m * Open existing for write */ if (bfd->use_backup_api) { - dwaccess = GENERIC_WRITE | WRITE_OWNER | WRITE_DAC; + dwaccess = GENERIC_READ | GENERIC_WRITE | WRITE_OWNER | WRITE_DAC; if (flags & O_NOFOLLOW) { dwflags = FILE_FLAG_BACKUP_SEMANTICS; } else { dwflags = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT; } } else { - dwaccess = GENERIC_WRITE; + dwaccess = GENERIC_READ | GENERIC_WRITE; dwflags = 0; } diff --git a/src/win32/compat/compat.c b/src/win32/compat/compat.c index a252d5782e4..3af1e865a6f 100644 --- a/src/win32/compat/compat.c +++ b/src/win32/compat/compat.c @@ -381,7 +381,7 @@ static inline void conv_unix_to_vss_win32_path(const char *name, char *win32_nam /** * Strip any trailing slash, if we stored something - * but leave "c:\" with backslash (root directory case + * but leave "c:\" with backslash (root directory case) */ if (*fname != 0 && win32_name[-1] == '\\' && strlen (fname) != 3) { win32_name[-1] = 0; @@ -2915,29 +2915,27 @@ bool win32_restore_file_attributes(POOLMEM *ofname, HANDLE handle, WIN32_FILE_AT bool retval = false; Dmsg1(100, "SetFileAtts %s\n", ofname); - if (!(atts->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - if (p_SetFileAttributesW) { - BOOL b; - POOLMEM *pwszBuf = get_pool_memory(PM_FNAME); + if (p_SetFileAttributesW) { + BOOL b; + POOLMEM *pwszBuf = get_pool_memory(PM_FNAME); - make_win32_path_UTF8_2_wchar(pwszBuf, ofname); - b = p_SetFileAttributesW((LPCWSTR)pwszBuf, atts->dwFileAttributes & SET_ATTRS); - free_pool_memory(pwszBuf); + make_win32_path_UTF8_2_wchar(pwszBuf, ofname); + b = p_SetFileAttributesW((LPCWSTR)pwszBuf, atts->dwFileAttributes & SET_ATTRS); + free_pool_memory(pwszBuf); - if (!b) { - goto bail_out; - } - } else { - BOOL b; - POOLMEM *win32_ofile = get_pool_memory(PM_FNAME); + if (!b) { + goto bail_out; + } + } else { + BOOL b; + POOLMEM *win32_ofile = get_pool_memory(PM_FNAME); - unix_name_to_win32(win32_ofile, ofname); - b = p_SetFileAttributesA(win32_ofile, atts->dwFileAttributes & SET_ATTRS); - free_pool_memory(win32_ofile); + unix_name_to_win32(win32_ofile, ofname); + b = p_SetFileAttributesA(win32_ofile, atts->dwFileAttributes & SET_ATTRS); + free_pool_memory(win32_ofile); - if (!b) { - goto bail_out; - } + if (!b) { + goto bail_out; } }