pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files pkg_install-20080422:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/447863f478b0
branches:  trunk
changeset: 541428:447863f478b0
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Tue Apr 22 13:47:08 2008 +0000

description:
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:

 pkgtools/pkg_install/files/create/build.c |  80 +++++++++---------------------
 pkgtools/pkg_install/files/lib/version.h  |   4 +-
 2 files changed, 26 insertions(+), 58 deletions(-)

diffs (174 lines):

diff -r 2a19c9d0fb9c -r 447863f478b0 pkgtools/pkg_install/files/create/build.c
--- a/pkgtools/pkg_install/files/create/build.c Tue Apr 22 12:15:56 2008 +0000
+++ b/pkgtools/pkg_install/files/create/build.c Tue Apr 22 13:47:08 2008 +0000
@@ -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 @@
        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 @@
 
        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 @@
                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 @@
                        err(2, "cannot read symlink %s", name);
                buf[buf_len] = '\0';
                archive_entry_set_symlink(entry, buf);
-
-               if (archive_write_header(archive, entry))
-                       errx(2, "cannot write to archive: %s", archive_error_string(archive));
-
                break;
 
        case S_IFREG:
-               fd = open(name, O_RDONLY);
-               if (fd == -1)
+               if (archive_write_header(archive, entry))
+                       errx(2, "cannot write to archive: %s", archive_error_string(archive));
+
+               if (archive_entry_size(entry) == 0)
+                       break;
+
+               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 @@
        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 @@
 
        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 @@
        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 -r 2a19c9d0fb9c -r 447863f478b0 pkgtools/pkg_install/files/lib/version.h
--- a/pkgtools/pkg_install/files/lib/version.h  Tue Apr 22 12:15:56 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/version.h  Tue Apr 22 13:47:08 2008 +0000
@@ -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_ */



Home | Main Index | Thread Index | Old Index