+ const struct list_head *head = &dentry->link_group_list;
+
+ if (head->next != head) {
+ /* This dentry is one of a hard link set of at least 2 dentries.
+ * If one of the other dentries has already been extracted, make
+ * a hard link to the file corresponding to this
+ * already-extracted directory. Otherwise, extract the
+ * file, and set the dentry->extracted_file field so that other
+ * dentries in the hard link group can link to it. */
+ struct dentry *other;
+ list_for_each_entry(other, head, link_group_list) {
+ if (other->extracted_file) {
+ DEBUG("Extracting hard link `%s' => `%s'",
+ output_path, other->extracted_file);
+ if (link(other->extracted_file, output_path) != 0) {
+ ERROR_WITH_ERRNO("Failed to hard link "
+ "`%s' to `%s'",
+ output_path,
+ other->extracted_file);
+ return WIMLIB_ERR_LINK;
+ }
+ return 0;
+ }
+ }
+ FREE(dentry->extracted_file);
+ dentry->extracted_file = STRDUP(output_path);
+ if (!dentry->extracted_file) {
+ ERROR("Failed to allocate memory for filename");
+ return WIMLIB_ERR_NOMEM;
+ }
+ }
+
+ /* Extract the contents of the file to @output_path. */