Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use new load function in pkg_compat
Baptiste Daroussin committed 13 years ago
commit 1b627397d77f2e316f14b2e50f0287307ffe68d6
parent adca70f
3 files changed +11 -41
modified libpkg/pkg.h.in
@@ -947,8 +947,6 @@ typedef enum pkg_formats { TAR, TGZ, TBZ, TXZ } pkg_formats;
 */
int pkg_create_installed(const char *, pkg_formats, const char *,
			 struct pkg *);
-
int pkg_create_oldinstalled(const char *, pkg_formats, const char *,
-
			 char *);

/**
 * Create package from stage install with a metadata directory
@@ -1171,6 +1169,5 @@ int pkgdb_reanalyse_shlibs(struct pkgdb *, struct pkg *);
int pkg_get_myarch(char *pkgarch, size_t sz);

void pkgdb_cmd(int argc, char **argv);
-

int pkg_old_load_from_path(struct pkg *pkg, const char *path);
#endif
modified libpkg/pkg_create.c
@@ -317,13 +317,6 @@ cleanup:
}

int
-
pkg_create_oldinstalled(const char *outdir __unused, pkg_formats format __unused,
-
    const char *rootdir __unused, char *pkgname __unused)
-
{
-
	return (EPKG_OK);
-
}
-

-
int
pkg_create_installed(const char *outdir, pkg_formats format,
    const char *rootdir, struct pkg *pkg)
{
@@ -332,7 +325,7 @@ pkg_create_installed(const char *outdir, pkg_formats format,
		PKG_LOAD_CATEGORIES | PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS |
		PKG_LOAD_OPTIONS | PKG_LOAD_MTREE | PKG_LOAD_LICENSES ;

-
	assert(pkg->type == PKG_INSTALLED);
+
	assert(pkg->type == PKG_INSTALLED || pkg->type == PKG_OLD_FILE);

	pkg_archive = pkg_create_archive(outdir, pkg, format, required_flags);
	if (pkg_archive == NULL) {
modified pkg/create.c
@@ -45,11 +45,7 @@
#include "pkgcli.h"

struct pkg_entry {
-
#ifndef PKG_COMPAT
	struct pkg *pkg;
-
#else
-
	char *pkgname;
-
#endif
	STAILQ_ENTRY(pkg_entry) next;
};

@@ -71,13 +67,12 @@ static int
pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
    const char * const outdir, const char * const rootdir, bool overwrite)
{
-
	int i, retcode = EPKG_OK;
+
	int i, ret = EPKG_OK, retcode = EPKG_OK;
+
	const char *name, *version;
#ifndef PKG_COMPAT
-
	int ret = EPKG_OK;
+
	struct pkg *pkg = NULL;
	struct pkgdb *db = NULL;
	struct pkgdb_it *it = NULL;
-
	struct pkg *pkg = NULL;
-
	const char *name, *version;
	int query_flags = PKG_LOAD_DEPS | PKG_LOAD_FILES | 
	    PKG_LOAD_CATEGORIES | PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS |
	    PKG_LOAD_OPTIONS | PKG_LOAD_MTREE | PKG_LOAD_LICENSES |
@@ -156,7 +151,10 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
				if (dp->d_type == DT_DIR) {
					if ((e = malloc(sizeof(struct pkg_entry))) == NULL)
						err(1, "malloc(pkg_entry)");
-
					e->pkgname = strdup(dp->d_name);
+
					e->pkg = NULL;
+
					pkg_new(&e->pkg, PKG_OLD_FILE);
+
					snprintf(pkgpath, MAXPATHLEN, "%s/%s", dbdir, dp->d_name);
+
					ret = pkg_old_load_from_path(e->pkg, pkgpath);
					STAILQ_INSERT_TAIL(&head, e, next);
					foundone = true;
				}
@@ -170,7 +168,9 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
				foundone = true;
				if ((e = malloc(sizeof(struct pkg_entry))) == NULL)
					err(1, "malloc(pkg_entry)");
-
				e->pkgname = strdup(argv[i]);
+
				e->pkg = NULL;
+
				pkg_new(&e->pkg, PKG_OLD_FILE);
+
				ret = pkg_old_load_from_path(e->pkg, pkgpath);
				STAILQ_INSERT_TAIL(&head, e, next);
				foundone = true;
			}
@@ -182,43 +182,23 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt,
		e = STAILQ_FIRST(&head);
		STAILQ_REMOVE_HEAD(&head, next);

-
#ifndef PKG_COMPAT
		pkg_get(e->pkg, PKG_NAME, &name, PKG_VERSION, &version);
-
#endif
		if (!overwrite) {
-
#ifndef PKG_COMPAT
			snprintf(pkgpath, MAXPATHLEN, "%s/%s-%s.%s", outdir,
			    name, version, format);
-
#else
-
			snprintf(pkgpath, MAXPATHLEN, "%s/%s.%s", outdir,
-
			    e->pkgname, format);
-
#endif
			if (access(pkgpath, F_OK) == 0) {
-
#ifndef PKG_COMPAT
				printf("%s-%s already packaged, skipping...\n",
				    name, version);
				pkg_free(e->pkg);
-
#else
-
				printf("%s already packaged, skipping...\n",
-
				    e->pkgname);
-
				free(e->pkgname);
-
#endif
				free(e);
				continue;
			}
		}
-
#ifndef PKG_COMPAT
		printf("Creating package for %s-%s\n", name, version);
		if (pkg_create_installed(outdir, fmt, rootdir, e->pkg) !=
		    EPKG_OK)
			retcode++;
		pkg_free(e->pkg);
-
#else
-
		printf("Creating package for %s\n", e->pkgname);
-
		if (pkg_create_oldinstalled(outdir, fmt, rootdir, e->pkgname) != EPKG_OK)
-
			retcode++;
-
		free(e->pkgname);
-
#endif
		free(e);
	}