- if (tar_open(&t, const_cast<char*>(filename.c_str()), &gztype, O_RDONLY, 0, TAR_GNU) == -1)
- throw runtime_error_with_errno("could not open " + filename);
+ for (i = 0; archive_read_next_header(archive, &entry) ==
+ ARCHIVE_OK; ++i) {
+
+ mode_t mode = archive_entry_mode(entry);
+
+ if (!archive_entry_hardlink(entry)) {
+ const char *s = archive_entry_pathname(entry);
+
+ hardlink_target_modes[s] = mode;
+ }
+
+ if (S_ISREG(mode) && archive_read_data_skip(archive))
+ throw runtime_error_with_errno("could not read " + filename, archive_errno(archive));
+ }
+
+ archive_read_finish(archive);
+
+ // Too bad, there doesn't seem to be a way to reuse our archive
+ // instance
+ archive = archive_read_new();
+ INIT_ARCHIVE(archive);
+
+ if (archive_read_open_filename(archive,
+ const_cast<char*>(filename.c_str()),
+ ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
+ throw runtime_error_with_errno("could not open " + filename, archive_errno(archive));
+
+ for (i = 0; archive_read_next_header(archive, &entry) ==
+ ARCHIVE_OK; ++i) {
+ mode_t mode = archive_entry_mode(entry);