]> wimlib.net Git - wimlib/blobdiff - src/extract.c
--hardlink fix
[wimlib] / src / extract.c
index 0cb06b87edb11d802845d254fda12c083be75515..1648adea343f911c5f789df65429c929598f21b1 100644 (file)
@@ -47,7 +47,7 @@ static int extract_regular_file_linked(const struct dentry *dentry,
                                       const char *output_dir,
                                       const char *output_path,
                                       int extract_flags,
-                                      const struct lookup_table_entry *lte)
+                                      struct lookup_table_entry *lte)
 {
        /* This mode overrides the normal hard-link extraction and
         * instead either symlinks or hardlinks *all* identical files in
@@ -56,6 +56,7 @@ static int extract_regular_file_linked(const struct dentry *dentry,
 
        wimlib_assert(lte->file_on_disk);
 
+
        if (extract_flags & WIMLIB_EXTRACT_FLAG_HARDLINK) {
                if (link(lte->file_on_disk, output_path) != 0) {
                        ERROR_WITH_ERRNO("Failed to hard link "
@@ -71,6 +72,8 @@ static int extract_regular_file_linked(const struct dentry *dentry,
                const char *p2;
                size_t i;
 
+               wimlib_assert(extract_flags & WIMLIB_EXTRACT_FLAG_SYMLINK);
+
                num_path_components = 
                        get_num_path_components(dentry->full_path_utf8) - 1;
                num_output_dir_path_components =
@@ -208,14 +211,19 @@ static int extract_regular_file(WIMStruct *w,
 
        lte = __lookup_resource(w->lookup_table, dentry_hash(dentry));
 
-       if ((extract_flags & (WIMLIB_EXTRACT_FLAG_SYMLINK | WIMLIB_EXTRACT_FLAG_HARDLINK)) &&
-             lte && lte->out_refcnt != 0)
-               return extract_regular_file_linked(dentry, output_dir,
-                                                  output_path, extract_flags,
-                                                  lte);
-       else
-               return extract_regular_file_unlinked(w, dentry, output_path,
-                                                    extract_flags, lte);
+       if ((extract_flags & (WIMLIB_EXTRACT_FLAG_SYMLINK |
+                             WIMLIB_EXTRACT_FLAG_HARDLINK)) && lte) {
+               if (lte->out_refcnt++ != 0)
+                       return extract_regular_file_linked(dentry, output_dir,
+                                                          output_path,
+                                                          extract_flags, lte);
+               lte->file_on_disk = STRDUP(output_path);
+               if (!lte->file_on_disk)
+                       return WIMLIB_ERR_NOMEM;
+       }
+
+       return extract_regular_file_unlinked(w, dentry, output_path,
+                                            extract_flags, lte);
 
 }