#include <errno.h>
+static const char *access_denied_msg =
+" If you are not running this program as the administrator, you may\n"
+" need to do so, so that all data and metadata can be backed up.\n"
+" Otherwise, there may be no way to access the desired data or\n"
+" metadata without taking ownership of the file or directory.\n";
+
#ifdef ENABLE_ERROR_MESSAGES
void
win32_error(u32 err_code)
err = GetLastError();
}
}
- ERROR("Win32 API: Failed to read security descriptor of \"%ls\"",
- path_utf16);
- win32_error(err);
- return WIMLIB_ERR_READ;
+
+ if (err == ERROR_ACCESS_DENIED) {
+ WARNING("Failed to read security descriptor of \"%ls\": "
+ "Access denied!\n%s", path_utf16, access_denied_msg);
+ return 0;
+ } else {
+ ERROR("Win32 API: Failed to read security descriptor of \"%ls\"",
+ path_utf16);
+ win32_error(err);
+ return WIMLIB_ERR_READ;
+ }
}
/* Reads the directory entries of directory using a Win32 API and recursively
{
struct wim_dentry *child;
- char *mbs_name;
+ mbchar *mbs_name;
size_t mbs_name_nbytes;
ret = utf16le_to_mbs(dat.cFileName,
wcslen(dat.cFileName) * sizeof(wchar_t),
if (ret)
goto out_find_close;
- char name[strlen(root_disk_path) + 1 + mbs_name_nbytes + 1];
+ mbchar name[strlen(root_disk_path) + 1 + mbs_name_nbytes + 1];
sprintf(name, "%s/%s", root_disk_path, mbs_name);
FREE(mbs_name);
ret = win32_build_dentry_tree(&child, name, lookup_table,
win32_capture_reparse_point(HANDLE hFile,
struct wim_inode *inode,
struct wim_lookup_table *lookup_table,
- const char *path)
+ const mbchar *path)
{
/* "Reparse point data, including the tag and optional GUID,
* cannot exceed 16 kilobytes." - MSDN */
is_named_stream = (p != colon);
if (is_named_stream) {
/* Allocate an ADS entry for the named stream. */
- char *mbs_stream_name;
+ mbchar *mbs_stream_name;
size_t mbs_stream_name_nbytes;
ret = utf16le_to_mbs(p,
(colon - p) * sizeof(wchar_t),
{
return 0;
} else {
- ERROR("Win32 API: Failed to look up data streams of \"%ls\"",
- path_utf16);
- win32_error(err);
- return WIMLIB_ERR_READ;
+ if (err == ERROR_ACCESS_DENIED) {
+ WARNING("Failed to look up data streams of \"%ls\": "
+ "Access denied!\n%s", path_utf16,
+ access_denied_msg);
+ return 0;
+ } else {
+ ERROR("Win32 API: Failed to look up data streams of \"%ls\"",
+ path_utf16);
+ win32_error(err);
+ return WIMLIB_ERR_READ;
+ }
}
}
do {
/* Win32 version of capturing a directory tree */
int
win32_build_dentry_tree(struct wim_dentry **root_ret,
- const char *root_disk_path,
+ const mbchar *root_disk_path,
struct wim_lookup_table *lookup_table,
struct wim_security_data *sd,
const struct capture_config *config,
if (!ret)
goto fail_win32;
- resolved_path = MALLOC(ret + 1);
+ resolved_path = MALLOC(ret);
if (!resolved_path)
goto fail;
ret = GetFullPathNameA(path, ret, resolved_path, NULL);
strcpy(buf, "Unknown");
return buf;
}
+
+/* rename() on Windows fails if the destination file exists. Fix it. */
+int
+rename_replacement(const char *oldpath, const char *newpath)
+{
+ if (MoveFileExA(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) {
+ return 0;
+ } else {
+ /* As usual, the possible error values are not documented */
+ DWORD err = GetLastError();
+ ERROR("MoveFileExA(): Can't rename \"%s\" to \"%s\"",
+ oldpath, newpath);
+ win32_error(err);
+ errno = 0;
+ return -1;
+ }
+}