X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fextract.c;h=1648adea343f911c5f789df65429c929598f21b1;hb=b8dd0c7d735c9e7db3f190a284a6255dab10ef1b;hp=0cb06b87edb11d802845d254fda12c083be75515;hpb=b3f993d2ece8fda5c989dc8c0311732fb20e3233;p=wimlib diff --git a/src/extract.c b/src/extract.c index 0cb06b87..1648adea 100644 --- a/src/extract.c +++ b/src/extract.c @@ -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); }