]> wimlib.net Git - wimlib/blobdiff - src/win32.c
win32_get_short_name(): Add missing FindClose
[wimlib] / src / win32.c
index 4a9e8becec2a762876765834e0d8dc9d4655002e..c36b13ae8593d106080d34915ed8b712c4b9764a 100644 (file)
@@ -46,6 +46,7 @@
 
 #define MAX_GET_SD_ACCESS_DENIED_WARNINGS 1
 #define MAX_GET_SACL_PRIV_NOTHELD_WARNINGS 1
+#define MAX_CREATE_HARD_LINK_WARNINGS 5
 struct win32_capture_state {
        unsigned long num_get_sd_access_denied;
        unsigned long num_get_sacl_priv_notheld;
@@ -393,22 +394,31 @@ static int
 win32_get_short_name(struct wim_dentry *dentry, const wchar_t *path)
 {
        WIN32_FIND_DATAW dat;
-       if (FindFirstFileW(path, &dat) && dat.cAlternateFileName[0] != L'\0') {
-               DEBUG("\"%ls\": short name \"%ls\"", path, dat.cAlternateFileName);
-               size_t short_name_nbytes = wcslen(dat.cAlternateFileName) *
-                                          sizeof(wchar_t);
-               size_t n = short_name_nbytes + sizeof(wchar_t);
-               dentry->short_name = MALLOC(n);
-               if (!dentry->short_name)
-                       return WIMLIB_ERR_NOMEM;
-               memcpy(dentry->short_name, dat.cAlternateFileName, n);
-               dentry->short_name_nbytes = short_name_nbytes;
-       }
+       HANDLE hFind;
+       int ret = 0;
+
        /* If we can't read the short filename for some reason, we just ignore
         * the error and assume the file has no short name.  I don't think this
         * should be an issue, since the short names are essentially obsolete
         * anyway. */
-       return 0;
+       hFind = FindFirstFileW(path, &dat);
+       if (hFind != INVALID_HANDLE_VALUE) {
+               if (dat.cAlternateFileName[0] != L'\0') {
+                       DEBUG("\"%ls\": short name \"%ls\"", path, dat.cAlternateFileName);
+                       size_t short_name_nbytes = wcslen(dat.cAlternateFileName) *
+                                                  sizeof(wchar_t);
+                       size_t n = short_name_nbytes + sizeof(wchar_t);
+                       dentry->short_name = MALLOC(n);
+                       if (dentry->short_name) {
+                               memcpy(dentry->short_name, dat.cAlternateFileName, n);
+                               dentry->short_name_nbytes = short_name_nbytes;
+                       } else {
+                               ret = WIMLIB_ERR_NOMEM;
+                       }
+               }
+               FindClose(hFind);
+       }
+       return ret;
 }
 
 static int
@@ -875,6 +885,12 @@ win32_capture_stream(const wchar_t *path,
                }
        }
 
+       /* If zero length stream, no lookup table entry needed. */
+       if ((u64)dat->StreamSize.QuadPart == 0) {
+               ret = 0;
+               goto out;
+       }
+
        /* Create a UTF-16LE string @spath that gives the filename, then a
         * colon, then the stream name.  Or, if it's an unnamed stream, just the
         * filename.  It is MALLOC()'ed so that it can be saved in the
@@ -1858,10 +1874,15 @@ win32_do_apply_dentry(const wchar_t *output_path,
                        win32_error(err);
                        return WIMLIB_ERR_LINK;
                } else {
-                       WARNING("Can't create hard link \"%ls => %ls\":\n"
-                               "          Volume does not support hard links!\n"
-                               "          Falling back to extracting a copy of the file.",
-                               output_path, inode->i_extracted_file);
+                       args->num_hard_links_failed++;
+                       if (args->num_hard_links_failed < MAX_CREATE_HARD_LINK_WARNINGS) {
+                               WARNING("Can't create hard link \"%ls => %ls\":\n"
+                                       "          Volume does not support hard links!\n"
+                                       "          Falling back to extracting a copy of the file.",
+                                       output_path, inode->i_extracted_file);
+                       } else if (args->num_hard_links_failed == MAX_CREATE_HARD_LINK_WARNINGS) {
+                               WARNING("Suppressing further hard linking warnings...");
+                       }
                }
        }