summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjoerg <joerg@pkgsrc.org>2008-04-22 13:47:08 +0000
committerjoerg <joerg@pkgsrc.org>2008-04-22 13:47:08 +0000
commit6bb49fafeaf29d451e699cd7bb0e9738f4f68be4 (patch)
tree2d3ca171b4ec266e553f55e9733a867b8f5dd825 /pkgtools
parent47c9588cc5faaeb4a579ca0d87ca33c5a082a085 (diff)
downloadpkgsrc-6bb49fafeaf29d451e699cd7bb0e9738f4f68be4.tar.gz
pkg_install-20080422:
Make use of the linkresolver from libarchive and thereby fix the permissions of hardlinks in archives. This wasn't a problem so far as nbpax is (incorrectly) ignoring the permissions of the other entries.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/create/build.c76
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
2 files changed, 24 insertions, 56 deletions
diff --git a/pkgtools/pkg_install/files/create/build.c b/pkgtools/pkg_install/files/create/build.c
index f61e98a79c4..fa146491af8 100644
--- a/pkgtools/pkg_install/files/create/build.c
+++ b/pkgtools/pkg_install/files/create/build.c
@@ -1,4 +1,4 @@
-/* $NetBSD: build.c,v 1.5 2008/01/03 22:31:20 rillig Exp $ */
+/* $NetBSD: build.c,v 1.6 2008/04/22 13:47:08 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp";
#else
-__RCSID("$NetBSD: build.c,v 1.5 2008/01/03 22:31:20 rillig Exp $");
+__RCSID("$NetBSD: build.c,v 1.6 2008/04/22 13:47:08 joerg Exp $");
#endif
#endif
@@ -121,25 +121,15 @@ write_meta_file(struct memory_file *file, struct archive *archive)
archive_entry_free(entry);
}
-LIST_HEAD(hardlink_list, hardlinked_entry);
-struct hardlink_list written_hardlinks;
-
-struct hardlinked_entry {
- LIST_ENTRY(hardlinked_entry) link;
- const char *existing_name;
- nlink_t remaining_links;
- dev_t existing_device;
- ino_t existing_ino;
-};
-
static void
-write_normal_file(const char *name, struct archive *archive, const char *owner, const char *group)
+write_normal_file(const char *name, struct archive *archive,
+ struct archive_entry_linkresolver *resolver,
+ const char *owner, const char *group)
{
char buf[16384];
off_t len;
ssize_t buf_len;
- struct hardlinked_entry *older_link;
- struct archive_entry *entry;
+ struct archive_entry *entry, *linked_entry;
struct stat st;
int fd;
@@ -148,35 +138,6 @@ write_normal_file(const char *name, struct archive *archive, const char *owner,
entry = archive_entry_new();
archive_entry_set_pathname(entry, name);
-
- if (!S_ISDIR(st.st_mode) && st.st_nlink > 1) {
- LIST_FOREACH(older_link, &written_hardlinks, link) {
- if (st.st_dev == older_link->existing_device &&
- st.st_ino == older_link->existing_ino) {
- archive_entry_copy_hardlink(entry,
- older_link->existing_name);
- if (archive_write_header(archive, entry)) {
- errx(2, "cannot write to archive: %s",
- archive_error_string(archive));
- }
-
- if (--older_link->remaining_links > 0)
- return;
- LIST_REMOVE(older_link, link);
- free(older_link);
- return;
- }
- }
- /* Not yet linked */
- if ((older_link = malloc(sizeof(*older_link))) == NULL)
- err(2, "malloc failed");
- older_link->existing_name = name;
- older_link->remaining_links = st.st_nlink - 1;
- older_link->existing_device = st.st_dev;
- older_link->existing_ino = st.st_ino;
- LIST_INSERT_HEAD(&written_hardlinks, older_link, link);
- }
-
archive_entry_copy_stat(entry, &st);
if (owner != NULL) {
@@ -201,6 +162,8 @@ write_normal_file(const char *name, struct archive *archive, const char *owner,
archive_entry_set_gname(entry, group_from_gid(st.st_gid, 1));
}
+ archive_entry_linkify(resolver, &entry, &linked_entry);
+
switch (st.st_mode & S_IFMT) {
case S_IFLNK:
buf_len = readlink(name, buf, sizeof buf);
@@ -208,21 +171,19 @@ write_normal_file(const char *name, struct archive *archive, const char *owner,
err(2, "cannot read symlink %s", name);
buf[buf_len] = '\0';
archive_entry_set_symlink(entry, buf);
+ break;
+ case S_IFREG:
if (archive_write_header(archive, entry))
errx(2, "cannot write to archive: %s", archive_error_string(archive));
- break;
+ if (archive_entry_size(entry) == 0)
+ break;
- case S_IFREG:
- fd = open(name, O_RDONLY);
- if (fd == -1)
+ if ((fd = open(name, O_RDONLY)) == -1)
err(2, "cannot open data file %s", name);
- len = st.st_size;
-
- if (archive_write_header(archive, entry))
- errx(2, "cannot write to archive: %s", archive_error_string(archive));
+ len = archive_entry_size(entry);
while (len > 0) {
if (len > sizeof(buf))
@@ -252,10 +213,15 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
const char *owner, *group;
const plist_t *p;
struct archive *archive;
+ struct archive_entry_linkresolver *resolver;
char *initial_cwd;
archive = archive_write_new();
archive_write_set_format_pax_restricted(archive);
+ if ((resolver = archive_entry_linkresolver_new()) == NULL)
+ errx(2, "cannot create link resolver");
+ archive_entry_linkresolver_set_strategy(resolver,
+ ARCHIVE_FORMAT_TAR_USTAR);
if (strcmp(suffix, "tbz") == 0 || strcmp(suffix, "tar.bz2") == 0)
archive_write_set_compression_bzip2(archive);
@@ -302,7 +268,7 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
for (p = plist->head; p; p = p->next) {
if (p->type == PLIST_FILE) {
- write_normal_file(p->name, archive, owner, group);
+ write_normal_file(p->name, archive, resolver, owner, group);
} else if (p->type == PLIST_CWD || p->type == PLIST_SRC) {
/* XXX let PLIST_SRC override PLIST_CWD */
@@ -328,6 +294,8 @@ make_dist(const char *pkg, const char *suffix, const package_t *plist)
chdir(initial_cwd);
free(initial_cwd);
+ archive_entry_linkresolver_free(resolver);
+
if (archive_write_close(archive))
errx(2, "cannot finish archive: %s", archive_error_string(archive));
archive_write_finish(archive);
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index 048ae938095..185c49b9884 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.100 2008/04/16 00:53:06 joerg Exp $ */
+/* $NetBSD: version.h,v 1.101 2008/04/22 13:47:08 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20080415"
+#define PKGTOOLS_VERSION "20080422"
#endif /* _INST_LIB_VERSION_H_ */