Skip to content

Commit

Permalink
Windows: restore attributes on directories
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pstorz committed Sep 25, 2017
1 parent 328d2aa commit 219eb49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/findlib/bfile.c
Expand Up @@ -653,14 +653,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;
}

Expand Down
38 changes: 18 additions & 20 deletions src/win32/compat/compat.c
Expand Up @@ -382,7 +382,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;
Expand Down Expand Up @@ -2917,29 +2917,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;
}
}

Expand Down

0 comments on commit 219eb49

Please sign in to comment.