Skip to content

Commit

Permalink
windows: call DeleteFileW and RemoveDirectoryW to be able to remove s…
Browse files Browse the repository at this point in the history
…ymlinks before restore

Windows symlinks could not be replaced during restore because
win32_unlink() only used _wunlink() to remove existing files before
recovery. _wunlink() cannot remove symlinks so that the
overwrite of existing symlinks did not work.

We first try with _unlink(); on failure DeleteFileW()
and as last option we do RemoveDirectoryW()

win32_unlink now is able to remove:
 * direcories
 * files
 * file symlinks and
 * directory symlinks

Fixes #967: Symbolic links are not replaceable during restore on Win FD
  • Loading branch information
pstorz committed Jun 22, 2018
1 parent c55a050 commit 7995c82
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/win32/compat/compat.c
Expand Up @@ -2873,7 +2873,34 @@ int win32_unlink(const char *filename)
}
}
}

/* if deletion with _unlink failed, try to use DeleteFileW (which also can remove file links) */
if (nRetCode == -1) {
Dmsg0(100, "_unlink failed, trying DeleteFileW \n");
if (DeleteFileW( (LPCWSTR)pwszBuf ) == 0) { // 0 = fail
Dmsg0(100, "DeleteFileW failed\n");
nRetCode = -1;
} else {
Dmsg0(100, "DeleteFileW success\n");
nRetCode = 0;
}
}


/* if deletion with DeleteFileW failed, try to use RemoveDirectoryW (which also can remove directory links) */
if (nRetCode == -1) {
Dmsg0(100, "DeleteFileW failed, trying RemoveDirectoryW \n");
if (RemoveDirectoryW( (LPCWSTR)pwszBuf ) == 0) { // 0 = fail
Dmsg0(100, "RemoveDirectoryW failed\n");
nRetCode = -1;
} else {
Dmsg0(100, "RemoveDirectoryW success\n");
nRetCode = 0;
}
}

free_pool_memory(pwszBuf);

} else {
nRetCode = _unlink(filename);

Expand Down

0 comments on commit 7995c82

Please sign in to comment.