X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwin32_apply.c;h=ce20fe6116744726b0e4d394d430ce4522db98a8;hb=334e2d17f2d69fbe28e6dd60a5b82a3837188d77;hp=f022e1d0bb1d2646e9edf291f51badd0a66e792c;hpb=d490e6e2a9cb3e421556ed3e50e0665ec955a418;p=wimlib diff --git a/src/win32_apply.c b/src/win32_apply.c index f022e1d0..ce20fe61 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -479,26 +479,6 @@ do_win32_extract_encrypted_stream(const wchar_t *path, return ret; } -static bool -path_is_root_of_drive(const wchar_t *path) -{ - if (*path == L'\0') - return false; - - if (!wcsncmp(path, L"\\\\?\\", 4)) - path += 4; - - if (*path != L'/' && *path != L'\\') { - if (*(path + 1) == L':') - path += 2; - else - return false; - } - while (*path == L'/' || *path == L'\\') - path++; - return (*path == L'\0'); -} - static inline DWORD win32_mask_attributes(DWORD i_attributes) { @@ -602,7 +582,7 @@ win32_begin_extract_unnamed_stream(const struct wim_inode *inode, * to CreateFileW() will merely open the directory that was already * created rather than creating a new file. */ if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) { - if (!path_is_root_of_drive(path)) { + if (!win32_path_is_root_of_drive(path)) { if (!CreateDirectoryW(path, NULL)) { err = GetLastError(); if (err != ERROR_ALREADY_EXISTS) { @@ -655,7 +635,7 @@ win32_begin_extract_unnamed_stream(const struct wim_inode *inode, * directory, so treat that as a special case and do not set attributes. * */ if (*creationDisposition_ret == OPEN_EXISTING && - !path_is_root_of_drive(path)) + !win32_path_is_root_of_drive(path)) { if (!SetFileAttributesW(path, win32_mask_attributes(inode->i_attributes))) @@ -813,12 +793,12 @@ win32_extract_stream(const struct wim_dentry *dentry, if (stream_name_utf16) { /* Named stream. Create a buffer that contains the UTF-16LE - * string [./]path:stream_name_utf16. This is needed to + * string [.\]path:stream_name_utf16. This is needed to * create and open the stream using CreateFileW(). I'm not * aware of any other APIs to do this. Note: the '$DATA' suffix - * seems to be unneeded. Additional note: a "./" prefix needs - * to be added when the path is not absolute to avoid ambiguity - * with drive letters. */ + * seems to be unneeded. Additional note: a ".\" prefix needs + * to be added when the path is a 1-character long relative path + * to avoid ambiguity with drive letters. */ size_t stream_path_nchars; size_t path_nchars; size_t stream_name_nchars; @@ -827,12 +807,10 @@ win32_extract_stream(const struct wim_dentry *dentry, path_nchars = wcslen(path); stream_name_nchars = wcslen(stream_name_utf16); stream_path_nchars = path_nchars + 1 + stream_name_nchars; - if (path[0] != cpu_to_le16(L'\0') && - path[0] != cpu_to_le16(L'/') && - path[0] != cpu_to_le16(L'\\') && - path[1] != cpu_to_le16(L':')) - { - prefix = L"./"; + if (path_nchars == 1 && !is_any_path_separator(path[0])) { + static const wchar_t _prefix[] = + {L'.', OS_PREFERRED_PATH_SEPARATOR, L'\0'}; + prefix = _prefix; stream_path_nchars += 2; } else { prefix = L""; @@ -871,7 +849,7 @@ try_open_again: if (h == INVALID_HANDLE_VALUE) { err = GetLastError(); if (err == ERROR_ACCESS_DENIED && - path_is_root_of_drive(stream_path)) + win32_path_is_root_of_drive(stream_path)) { ret = 0; goto out; @@ -885,7 +863,11 @@ try_open_again: requestedAccess &= ~ACCESS_SYSTEM_SECURITY; goto try_open_again; } - if (err == ERROR_SHARING_VIOLATION) { + if (err == ERROR_SHARING_VIOLATION && + (inode->i_attributes & (FILE_ATTRIBUTE_ENCRYPTED | + FILE_ATTRIBUTE_DIRECTORY)) == + (FILE_ATTRIBUTE_ENCRYPTED | FILE_ATTRIBUTE_DIRECTORY)) + { if (remaining_sharing_violations) { --remaining_sharing_violations; /* This can happen when restoring encrypted directories @@ -897,13 +879,12 @@ try_open_again: } else { ERROR("Too many sharing violations; giving up..."); } - } else { - if (creationDisposition == OPEN_EXISTING) - ERROR("Failed to open \"%ls\"", stream_path); - else - ERROR("Failed to create \"%ls\"", stream_path); - win32_error(err); } + if (creationDisposition == OPEN_EXISTING) + ERROR("Failed to open \"%ls\"", stream_path); + else + ERROR("Failed to create \"%ls\"", stream_path); + win32_error(err); ret = WIMLIB_ERR_OPEN; goto fail; } @@ -1285,7 +1266,7 @@ win32_do_apply_dentry_timestamps(const wchar_t *path, /* Windows doesn't let you change the timestamps of the root directory * (at least on FAT, which is dumb but expected since FAT doesn't store * any metadata about the root directory...) */ - if (path_is_root_of_drive(path)) + if (win32_path_is_root_of_drive(path)) return 0; DEBUG("Opening \"%ls\" to set timestamps", path);