Win32 fixes
authorEric Biggers <ebiggers3@gmail.com>
Sun, 24 Mar 2013 01:21:41 +0000 (20:21 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 24 Mar 2013 01:21:41 +0000 (20:21 -0500)
configure.ac
programs/imagex-win32.c
src/metadata_resource.c
src/verify.c
src/win32.c

index 80ea8df..13da4dd 100644 (file)
@@ -192,7 +192,7 @@ case "$host" in
                WINDOWS_NATIVE_BUILD="yes"
                VISIBILITY_CFLAGS=""
                WINDOWS_CFLAGS="-municode"
-               WINDOWS_CPPFLAGS="-D_POSIX"
+               WINDOWS_CPPFLAGS="-D_POSIX -DUNICODE -D_UNICODE"
                WINDOWS_LDFLAGS="-no-undefined"
                WINDOWS_LDADD="-lshlwapi"
                ;;
index 18581ed..19aa92c 100644 (file)
@@ -119,7 +119,7 @@ globfree(glob_t *pglob)
 }
 
 static bool
-win32_modify_privilege(const char *privilege, bool enable)
+win32_modify_privilege(const wchar_t *privilege, bool enable)
 {
        HANDLE hToken;
        LUID luid;
@@ -129,13 +129,10 @@ win32_modify_privilege(const char *privilege, bool enable)
        if (!OpenProcessToken(GetCurrentProcess(),
                              TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                              &hToken))
-       {
                goto out;
-       }
 
-       if (!LookupPrivilegeValue(NULL, privilege, &luid)) {
+       if (!LookupPrivilegeValueW(NULL, privilege, &luid))
                goto out;
-       }
 
        newState.PrivilegeCount = 1;
        newState.Privileges[0].Luid = luid;
index d54641d..a2ae93c 100644 (file)
@@ -213,7 +213,7 @@ write_wim_resource_from_buffer(const u8 *buf, u64 buf_size,
        lte.resource_entry.size          = buf_size;
        lte.resource_entry.offset        = 0;
        lte.resource_location            = RESOURCE_IN_ATTACHED_BUFFER;
-       lte.attached_buffer              = buf;
+       lte.attached_buffer              = (void*)buf;
 
        zero_out_hash(lte.hash);
        ret = write_wim_resource(&lte, out_fp, out_ctype, out_res_entry, 0);
index efaca0d..decd90c 100644 (file)
@@ -265,7 +265,7 @@ verify_swm_set(WIMStruct *w, WIMStruct **additional_swms,
        }
        if (w->hdr.part_number != 1) {
                ERROR("WIM `%"TS"' is not the first part of the split WIM.",
-                     T(w->filename));
+                     w->filename);
                return WIMLIB_ERR_SPLIT_INVALID;
        }
        for (unsigned i = 0; i < num_additional_swms; i++) {
index dfa92ff..21225e2 100644 (file)
@@ -949,6 +949,23 @@ do_win32_extract_stream(HANDLE hStream, struct wim_lookup_table_entry *lte)
                                    win32_extract_chunk, hStream);
 }
 
+static bool
+path_is_root_of_drive(const wchar_t *path)
+{
+       if (!*path)
+               return false;
+
+       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 int
 win32_extract_stream(const struct wim_inode *inode,
                     const wchar_t *path,
@@ -1013,7 +1030,14 @@ win32_extract_stream(const struct wim_inode *inode,
                if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) {
                        if (!CreateDirectoryW(stream_path, secattr)) {
                                err = GetLastError();
-                               if (err != ERROR_ALREADY_EXISTS) {
+                               switch (err) {
+                               case ERROR_ALREADY_EXISTS:
+                                       break;
+                               case ERROR_ACCESS_DENIED:
+                                       if (path_is_root_of_drive(path))
+                                               break;
+                                       /* Fall through */
+                               default:
                                        ERROR("Failed to create directory \"%ls\"",
                                              stream_path);
                                        win32_error(err);