- struct delayed_set_stat *data = delayed_set_stat_head;
- if (data->file_name_len < file_name_len
- && file_name[data->file_name_len] == '/'
- && memcmp (file_name, data->file_name, data->file_name_len) == 0)
- break;
- delayed_set_stat_head = data->next;
- set_stat (data->file_name, &data->stat_info,
- data->invert_permissions, data->permstatus, DIRTYPE);
- free (data);
+ struct string_list *sources = ds->sources;
+ char const *valid_source = 0;
+
+ for (sources = ds->sources; sources; sources = sources->next)
+ {
+ char const *source = sources->string;
+ struct stat st;
+
+ /* Make sure the placeholder file is still there. If not,
+ don't create a link, as the placeholder was probably
+ removed by a later extraction. */
+ if (lstat (source, &st) == 0
+ && st.st_dev == ds->dev
+ && st.st_ino == ds->ino
+ && timespec_cmp (get_stat_mtime (&st), ds->mtime) == 0)
+ {
+ /* Unlink the placeholder, then create a hard link if possible,
+ a symbolic link otherwise. */
+ if (unlink (source) != 0)
+ unlink_error (source);
+ else if (valid_source && link (valid_source, source) == 0)
+ ;
+ else if (!ds->is_symlink)
+ {
+ if (link (ds->target, source) != 0)
+ link_error (ds->target, source);
+ }
+ else if (symlink (ds->target, source) != 0)
+ symlink_error (ds->target, source);
+ else
+ {
+ struct tar_stat_info st1;
+ st1.stat.st_uid = ds->uid;
+ st1.stat.st_gid = ds->gid;
+ set_stat (source, &st1, NULL, 0, 0, SYMTYPE);
+ valid_source = source;
+ }
+ }
+ }
+
+ for (sources = ds->sources; sources; )
+ {
+ struct string_list *next = sources->next;
+ free (sources);
+ sources = next;
+ }
+
+ {
+ struct delayed_link *next = ds->next;
+ free (ds);
+ ds = next;
+ }