diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 2110bbb4841a..527df2b710ff 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -677,11 +677,6 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st, fd = -1; entry = archive_entry_new(); - archive_entry_set_pathname(entry, pathname); - - /* If there are hard links, record it for later use */ - if (!S_ISDIR(st->st_mode) && (st->st_nlink > 1)) - lookup_hardlink(bsdtar, entry, st); /* Non-regular files get archived with zero size. */ if (!S_ISREG(st->st_mode)) @@ -698,6 +693,11 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st, if (pathname && pathname[0] == '/' && !bsdtar->option_absolute_paths) pathname++; + archive_entry_set_pathname(entry, pathname); + + if (!S_ISDIR(st->st_mode) && (st->st_nlink > 1)) + lookup_hardlink(bsdtar, entry, st); + /* Display entry as we process it. This format is required by SUSv2. */ if (bsdtar->verbose) safe_fprintf(stderr, "a %s", pathname); @@ -733,6 +733,7 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st, } #endif + archive_entry_copy_stat(entry, st); setup_acls(bsdtar, entry, accpath); /* @@ -752,9 +753,6 @@ write_entry(struct bsdtar *bsdtar, struct archive *a, struct stat *st, } } - archive_entry_copy_stat(entry, st); - archive_entry_set_pathname(entry, pathname); - e = archive_write_header(a, entry); if (e != ARCHIVE_OK) { if (!bsdtar->verbose)