Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a new function: pkg_create_from_manifest()
Matthew Seaman committed 11 years ago
commit 1dfb2859ef5b2bdcc5c141e80193d9d91df666db
parent 238ef2f
3 files changed +95 -13
modified docs/pkg-create.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd November 29, 2013
+
.Dd May 16, 2014
.Dt PKG-CREATE 8
.Os
.\" ---------------------------------------------------------------------------
@@ -30,7 +30,13 @@
.Op Fl o Ar outdir
.Op Fl p Ar plist
.Op Fl r Ar rootdir
-
.Fl m Ar manifestdir
+
.Fl m Ar metadatadir
+
.Nm
+
.Op Fl n
+
.Op Fl f Ar format
+
.Op Fl o Ar outdir
+
.Op Fl r Ar rootdir
+
.Fl M Ar manifest
.Nm
.Op Fl gnx
.Op Fl f Ar format
@@ -54,14 +60,16 @@ Any number of packages may be created in one invocation of this style.
.Pp
Alternatively, a single package can be created from an arbitrary
selection of files on your system, but this requires a
-
.Ar manifestdir
+
.Ar metadatadir
and optionally
.Ar plist
to be supplied.
The package name will be derived from the
.Pa +MANIFEST
file which must be contained within the
-
.Ar manifestdir .
+
.Ar metadatadir ,
+
or passed as the argument to
+
.Fl M .
.Pp
Packages thus created can be distributed and subsequently installed on
other machines using the
@@ -71,13 +79,13 @@ command.
.Sh OPTIONS
The following options are supported by
.Nm :
-
.Bl -tag -width ".Fl m Ar manifestdir"
+
.Bl -tag -width ".Fl m Ar metadatadir"
.It Fl a
Create package tarballs from all packages installed on your system.
This option is incompatible with the
.Fl g , x
or
-
.Fl m Ar manifestdir
+
.Fl m Ar metadatadir
options.
.It Fl g
Interpret
@@ -87,7 +95,7 @@ name match this pattern.
This option is incompatible with the
.Fl a , x
or
-
.Fl m Ar manifestdir
+
.Fl m Ar metadatadir
options.
.It Fl x
Like
@@ -99,7 +107,7 @@ as a regular expression using the "modern" or "extended" syntax described in
This option is incompatible with the
.Fl a, g
or
-
.Fl m Ar manifestdir
+
.Fl m Ar metadatadir
options.
.It Fl f Ar format
Set
@@ -113,7 +121,7 @@ which are currently the only supported format.
If an invalid or no format is specified
.Ar txz
is assumed.
-
.It Fl m Ar manifestdir
+
.It Fl m Ar metadatadir
Specify the directory containing the package manifest,
.Pa +MANIFEST
and optionally three other files; one containing a message to be
@@ -138,7 +146,21 @@ are not required; the
file can contain all the required information needed to build a
package.
This option is incompatible with the
-
.Fl a, g
+
.Fl M, a, g
+
or
+
.Fl x
+
options.
+
.It Fl M Ar manifest
+
Read all of the package metadata from the
+
.Ar manifest
+
file.
+
This is exactly the same format as
+
.Pa +MANIFEST
+
mentioned above, but any file name can be used, and no
+
other file will be used to read package metada from.
+
If specified, only a single package will be created.
+
This option is incompatible with the
+
.Fl m, a, g
or
.Fl x
options.
@@ -160,9 +182,9 @@ Metadata from the
G.Ar plist
file, if specified, will take precedence over any equivalents from
the
-
.Ar manifestdir .
+
.Ar metadatadir .
Only has any effect when used with
-
.Ar manifestdir .
+
.Ar metadatadir .
See
.Sx "PLIST FORMAT"
for details
modified libpkg/pkg.h.in
@@ -1243,6 +1243,13 @@ typedef enum pkg_formats { TAR, TGZ, TBZ, TXZ } pkg_formats;
int pkg_create_installed(const char *, pkg_formats, struct pkg *);

/**
+
 * Create package from stage install using just the manifest --
+
 * no old pkg_tools compatibility stuff
+
 */
+
int pkg_create_from_manifest(const char *, pkg_formats, const char *,
+
			     const char *, bool);
+

+
/**
 * Create package from stage install with a metadata directory
 */
int pkg_create_staged(const char *, pkg_formats, const char *, const char *,
modified libpkg/pkg_create.c
@@ -1,6 +1,7 @@
/*-
 * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
+
 * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
@@ -225,6 +226,58 @@ static const char * const scripts[] = {
	NULL
};

+

+
/* The "no concessions to old pkg_tools" variant: just get everything
+
 * from the manifest */
+
int
+
pkg_create_from_manifest(const char *outdir, pkg_formats format,
+
			 const char *rootdir, const char *manifest, bool old)
+
{
+
	struct pkg	*pkg = NULL;
+
	struct packing	*pkg_archive = NULL;
+
	char		 arch[BUFSIZ];
+
	int		 ret = ENOMEM;
+
	char		*buf;
+
	struct pkg_manifest_key *keys = NULL;
+

+
	pkg_debug(1, "Creating package from stage directory: '%s'", rootdir);
+

+
	if(pkg_new(&pkg, old ? PKG_OLD_FILE : PKG_FILE) != EPKG_OK) {
+
		ret = EPKG_FATAL;
+
		goto cleanup;
+
	}
+

+
	pkg_manifest_keys_new(&keys);
+
	if ((ret = pkg_parse_manifest_file(pkg, manifest, keys)) != EPKG_OK) {
+
		ret = EPKG_FATAL;
+
		goto cleanup;
+
	}
+

+
	/* if no arch autodetermine it */
+
	pkg_get(pkg, PKG_ARCH, &buf);
+
	if (buf == NULL) {
+
		pkg_get_myarch(arch, BUFSIZ);
+
		pkg_set(pkg, PKG_ARCH, arch);
+
	}
+

+
	/* Create the archive */
+
	pkg_archive = pkg_create_archive(outdir, pkg, format, 0);
+
	if (pkg_archive == NULL) {
+
		ret = EPKG_FATAL; /* XXX do better */
+
		goto cleanup;
+
	}
+

+
	pkg_create_from_dir(pkg, rootdir, pkg_archive);
+
	ret = EPKG_OK;
+

+
cleanup:
+
	free(pkg);
+
	pkg_manifest_keys_free(keys);
+
	if (ret == EPKG_OK)
+
		ret = packing_finish(pkg_archive);
+
	return (ret);
+
}
+

int
pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir,
    const char *md_dir, char *plist, bool old)
@@ -369,7 +422,7 @@ cleanup:
	pkg_manifest_keys_free(keys);
	if (ret == EPKG_OK)
		ret = packing_finish(pkg_archive);
-
	return ret;
+
	return (ret);
}

int