PERFORCE change 177984 for review
Garrett Cooper
gcooper at FreeBSD.org
Sun May 9 00:18:18 UTC 2010
http://p4web.freebsd.org/@@177984?ac=10
Change 177984 by gcooper at gcooper-bayonetta on 2010/05/09 00:17:23
Checkpoint work to convert pkg_create over to archive_write(3).
Affected files ...
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#5 edit
Differences ...
==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/perform.c#5 (text+ko) ====
@@ -21,14 +21,20 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/create/perform.c,v 1.85 2010/04/23 11:07:43 flz Exp $");
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
#include <err.h>
+#include <errno.h>
#include <libgen.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <archive.h>
+#include <archive_entry.h>
#include <pkg.h>
#include "create.h"
@@ -73,10 +79,8 @@
}
if (Zipper == BZIP2) {
suf = "tbz";
- setenv("BZIP2", "--best", 0);
} else if (Zipper == GZIP) {
suf = "tgz";
- setenv("GZIP", "-9", 0);
} else
suf = "tar";
@@ -339,7 +343,7 @@
return TRUE; /* Success */
}
-#define EXTRACT_ARCHIVE_FLAGS (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM| \
+#define COMPRESS_ARCHIVE_FLAGS (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM| \
ARCHIVE_EXTRACT_TIME |ARCHIVE_EXTRACT_ACL | \
ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR)
@@ -347,17 +351,57 @@
make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist)
{
-#ifdef NOTYET
+#define ADD_FILE(src_file, dest_file) \
+ if (error == NULL) { \
+ if ((archive_entry_fd = open(src_file, \
+ archive_entry_fd)) == -1 || \
+ fstat(archive_entry_fd, sb) == -1) { \
+ error = strerror(errno); \
+ } else if ((archive_entry_map_addr = mmap(NULL, \
+ PROT_READ, sb->st_size, MAP_SHARED, \
+ archive_entry_fd, 0)) == NULL) { \
+ error = strerror(errno); \
+ } else { \
+ if ((entry = archive_entry_new()) == NULL) \
+ error = archive_error_string(archive); \
+ else { \
+ archive_entry_copy_stat(entry, sb); \
+ if (archive_write_header(archive, \
+ entry) != ARCHIVE_OK) \
+ error = archive_error_string(archive); \
+ else if (archive_write_data(archive, \
+ archive_entry_map_addr, \
+ sb->st_size) != ARCHIVE_OK) \
+ error = archive_error_string(archive); \
+ (void) munmap(archive_entry_map_addr, \
+ sb->st_size); \
+ archive_entry_free(entry); \
+ } \
+ } \
+ if (0 <= archive_entry_fd) \
+ close(archive_entry_fd); \
+ }
+
+#if NOTYET
PackingList p;
#endif
+ struct stat *sb;
struct archive *archive = NULL;
+ struct archive_entry *entry = NULL;
char tball[PATH_MAX];
-#ifdef NOTYET
+#if NOTYET
char *prefix = NULL;
#endif
+ char *starting_point = NULL;
+
const char *cname = NULL;
const char *error = NULL;
- int archive_fd = -1, open_flags;
+ int archive_fd = -1;
+ int archive_open_flags;
+ int archive_entry_fd = -1;
+ int archive_entry_open_flags;
+ void *archive_entry_map_addr;
+
Boolean passed = FALSE;
if (*pkg == '/')
@@ -365,132 +409,135 @@
else
snprintf(tball, sizeof(tball), "%s/%s.%s", homedir, pkg, suff);
- open_flags = O_WRONLY;
+ archive_entry_open_flags = O_RDONLY;
+
+ if (Dereference == FALSE)
+ archive_entry_open_flags |= O_NOFOLLOW;
+
+ archive_open_flags = O_WRONLY;
if (Regenerate == FALSE)
- open_flags |= O_CREAT;
+ archive_open_flags |= O_CREAT;
+ if ((starting_point = getwd(NULL)) == NULL)
+ warn("%s: failed to determine current directory", __func__);
/*
* If the package tarball exists already, and we are running in
* `no clobber' mode, skip this package.
*/
- if ((archive_fd = open(tball, open_flags)) == -1) {
+ else if ((archive_fd = open(tball, archive_open_flags)) == -1) {
if (Verbose)
warn("Skipping package creation for: '%s'", tball);
- } else {
+ }
+ else if ((archive = archive_write_new()) == NULL)
+ error = archive_error_string(archive);
+ else if (archive_write_set_format_ustar(archive) != ARCHIVE_OK)
+ error = archive_error_string(archive);
+ else {
- if ((archive = archive_write_new()) == NULL) {
- error = archive_error_string(archive);
- warnx("%s: unable to create the package '%s': %s",
- __func__, tball, error);
- } else {
+ switch(Zipper) {
+ case BZIP2:
+ cname = "bzipp";
+ if (archive_write_set_compression_bzip2(archive) !=
+ ARCHIVE_OK)
+ error = archive_error_string(archive);
+ else if (archive_write_set_compressor_options(archive,
+ "compression-level=9") != ARCHIVE_OK)
+ error = archive_error_string(archive);
+ break;
+ case GZIP:
+ cname = "gzipp";
+ if (archive_write_set_compression_gzip(archive) !=
+ ARCHIVE_OK)
+ error = archive_error_string(archive);
+ else if (archive_write_set_compressor_options(archive,
+ "compression-level=9") != ARCHIVE_OK)
+ error = archive_error_string(archive);
+ break;
+ default:
+ cname = "uncompress";
+ if (archive_write_set_compression_none(archive) !=
+ ARCHIVE_OK)
+ error = archive_error_string(archive);
+ }
- if (archive_write_set_format_ustar(archive) !=
- ARCHIVE_OK) {
- error = archive_error_string(archive);
- } else if (strncmp(suff, "tbz", 3) == 0) {
- if (archive_write_set_compression_bzip2(archive)
- == ARCHIVE_OK)
- cname = "bzipp";
- else
- error = archive_error_string(archive);
- } else if (strncmp(suff, "tgz", 3) == 0) {
- if (archive_write_set_compression_gzip(archive)
- == ARCHIVE_OK)
- cname = "gzipp";
- else
- error = archive_error_string(archive);
- } else {
- if (archive_write_set_compression_none(archive)
- == ARCHIVE_OK)
- cname = "uncompress";
- else
- error = archive_error_string(archive);
- }
+ }
- if (error != NULL) {
+ if (error != NULL)
+ if (archive_write_open_fd(archive, archive_fd) != ARCHIVE_OK)
+ error = archive_error_string(archive);
+ if (error != NULL) {
- /* XXX (gcooper): fill this stuff in. */
#ifdef NOTYET
- if (Dereference == TRUE) ;
+ /*
+ * XXX (gcooper): Need to fill bits for the exclude
+ * stuff
+ */
+ if (ExcludeFrom != NULL) ;
+#endif
- if (ExcludeFrom != NULL) ;
+ if (Verbose)
+ printf("Creating %sed tar ball in '%s'\n",
+ cname, tball);
- if (Verbose)
- printf("Creating %sed tar ball in '%s'\n", cname, tball);
+ ADD_FILE(CONTENTS_FNAME, CONTENTS_FNAME);
+ ADD_FILE(COMMENT_FNAME, COMMENT_FNAME);
+ ADD_FILE(DESC_FNAME, DESC_FNAME);
- //fprintf(totar, "%s\n", CONTENTS_FNAME);
- //fprintf(totar, "%s\n", COMMENT_FNAME);
- //fprintf(totar, "%s\n", DESC_FNAME);
+ if (Install)
+ ADD_FILE(INSTALL_FNAME, INSTALL_FNAME);
+ if (PostInstall)
+ ADD_FILE(POST_INSTALL_FNAME, POST_INSTALL_FNAME);
+ if (DeInstall)
+ ADD_FILE(DEINSTALL_FNAME, DEINSTALL_FNAME);
+ if (PostDeInstall)
+ ADD_FILE(POST_DEINSTALL_FNAME, POST_DEINSTALL_FNAME);
+ if (Require)
+ ADD_FILE(REQUIRE_FNAME, REQUIRE_FNAME);
+ if (Display)
+ ADD_FILE(DISPLAY_FNAME, DISPLAY_FNAME);
+ if (Mtree)
+ ADD_FILE(MTREE_FNAME, MTREE_FNAME);
- if (Install) ;
- //fprintf(totar, "%s\n", INSTALL_FNAME);
- if (PostInstall) ;
- //fprintf(totar, "%s\n", POST_INSTALL_FNAME);
- if (DeInstall) ;
- //fprintf(totar, "%s\n", DEINSTALL_FNAME);
- if (PostDeInstall) ;
- //fprintf(totar, "%s\n", POST_DEINSTALL_FNAME);
- if (Require) ;
- //fprintf(totar, "%s\n", REQUIRE_FNAME);
- if (Display) ;
- //fprintf(totar, "%s\n", DISPLAY_FNAME);
- if (Mtree) ;
- //fprintf(totar, "%s\n", MTREE_FNAME);
+ passed = TRUE;
- passed = TRUE;
-
- for (p = plist->head; p != NULL; p = p->next) {
-
- switch(p->type) {
- case PLIST_FILE:
- /* Add p->name to archive. */
- break;
- case PLIST_CWD:
-
- if (p->name != NULL) {
- /*
- * Add <base>/<@cwd dir>
- * to archive.
- */
- if (BaseDir != NULL &&
- p->name[0] == '/') ;
- /* else,
- * chdir(<prefix>) . */
-
- if (prefix == NULL)
- prefix = p->name;
-
- }
-
- /* FALLTHROUGH */
- case PLIST_SRC:
- /*
- * 1. chdir(<base>).
- * 2. Add the
- * <base>/<@cwd-dir>.
- */
- break;
- default:
- /*
- * Catch-all for the rest of
- * the cases.
- */
- break;
- }
-
+#if NOTYET
+ /*
+ * XXX (gcooper): Fix style(9) for for-loop after changes have
+ * stabilized.
+ */
+ for (p = plist->head; p != NULL; p = p->next) {
+ switch(p->type) {
+ case PLIST_FILE:
+ /* Add p->name to archive. */
+ break;
+ case PLIST_CWD:
+ if (p->name != NULL) {
/*
- * if the file operation is invalid,
- * set passed to FALSE .
+ * Add <base>/<@cwd dir>
+ * to archive.
*/
+ if (BaseDir != NULL &&
+ p->name[0] == '/') ;
+ /* else, chdir(<prefix>) . */
+ if (prefix == NULL)
+ prefix = p->name;
}
-#endif
-
+ /* FALLTHROUGH */
+ case PLIST_SRC:
+ /*
+ * 1. chdir(<base>).
+ * 2. Add the <base>/<@cwd-dir>.
+ */
+ break;
+ default:
+ /* Catch-all for the rest of the cases. */
+ break;
}
-
}
+#endif
}
@@ -501,11 +548,14 @@
warnx("%s: unable to create the package '%s': %s",
__func__, tball, error);
}
- if (0 <= archive_fd)
+ if (0 <= archive_fd) {
close(archive_fd);
- if (passed == FALSE && unlink(tball) == -1)
- warn("%s: failed to remove incomplete package - '%s'",
- __func__, tball);
+ if (passed == FALSE && unlink(tball) == -1)
+ warn("%s: failed to remove incomplete package - '%s'",
+ __func__, tball);
+ }
+ if (starting_point != NULL)
+ free(starting_point);
}
More information about the p4-projects
mailing list