- 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;
+
+ chdir_do (ds->change_dir);
+
+ 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 (fstatat (chdir_fd, source, &st, AT_SYMLINK_NOFOLLOW) == 0
+ && st.st_dev == ds->dev
+ && st.st_ino == ds->ino
+ && timespec_cmp (get_stat_ctime (&st), ds->ctime) == 0)
+ {
+ /* Unlink the placeholder, then create a hard link if possible,
+ a symbolic link otherwise. */
+ if (unlinkat (chdir_fd, source, 0) != 0)
+ unlink_error (source);
+ else if (valid_source
+ && (linkat (chdir_fd, valid_source, chdir_fd, source, 0)
+ == 0))
+ ;
+ else if (!ds->is_symlink)
+ {
+ if (linkat (chdir_fd, ds->target, chdir_fd, source, 0) != 0)
+ link_error (ds->target, source);
+ }
+ else if (symlinkat (ds->target, chdir_fd, source) != 0)
+ symlink_error (ds->target, source);
+ else
+ {
+ struct tar_stat_info st1;
+ st1.stat.st_mode = ds->mode;
+ st1.stat.st_uid = ds->uid;
+ st1.stat.st_gid = ds->gid;
+ st1.atime = ds->atime;
+ st1.mtime = ds->mtime;
+ set_stat (source, &st1, -1, 0, 0, SYMTYPE,
+ false, AT_SYMLINK_NOFOLLOW);
+ 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;
+ }