Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add flags to pkg_open to allow some optimizations.
Vsevolod Stakhov committed 13 years ago
commit eb5315f68f653fb5fac3800ce619d0a80b02134d
parent 41df825
9 files changed +20 -13
modified libpkg/pkg.c
@@ -1040,13 +1040,13 @@ pkg_list_free(struct pkg *pkg, pkg_list list) {
}

int
-
pkg_open(struct pkg **pkg_p, const char *path, struct pkg_manifest_key *keys)
+
pkg_open(struct pkg **pkg_p, const char *path, struct pkg_manifest_key *keys, int flags)
{
	struct archive *a;
	struct archive_entry *ae;
	int ret;

-
	ret = pkg_open2(pkg_p, &a, &ae, path, keys);
+
	ret = pkg_open2(pkg_p, &a, &ae, path, keys, flags);

	if (ret != EPKG_OK && ret != EPKG_END)
		return (EPKG_FATAL);
@@ -1057,7 +1057,8 @@ pkg_open(struct pkg **pkg_p, const char *path, struct pkg_manifest_key *keys)
}

int
-
pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, const char *path, struct pkg_manifest_key *keys)
+
pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae,
+
		const char *path, struct pkg_manifest_key *keys, int flags)
{
	struct pkg *pkg;
	pkg_error_t retcode = EPKG_OK;
@@ -1114,6 +1115,8 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con
				retcode = EPKG_FATAL;
				goto cleanup;
			}
+
			if (flags & PKG_OPEN_MANIFEST_ONLY)
+
				break;
		}

		for (i = 0; files[i].name != NULL; i++) {
modified libpkg/pkg.h.in
@@ -451,6 +451,8 @@ typedef enum {
	EPKG_INSECURE,
} pkg_error_t;

+
#define PKG_OPEN_MANIFEST_ONLY 0x1
+

/**
 * test if pkg is installed and activated.
 * @param count  If all the tests pass, and count is non-NULL,
@@ -485,8 +487,10 @@ int pkg_is_valid(struct pkg *);
 * @param p A pointer to pkg allocated by pkg_new(), or if it points to a
 * NULL pointer, the function allocate a new pkg using pkg_new().
 * @param path The path to the local package archive.
+
 * @param keys manifest keys that should be initialised
+
 * @param flags open flags
 */
-
int pkg_open(struct pkg **p, const char *path, struct pkg_manifest_key *keys);
+
int pkg_open(struct pkg **p, const char *path, struct pkg_manifest_key *keys, int flags);

/**
 * @return the type of the package.
modified libpkg/pkg_add.c
@@ -177,7 +177,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_
	 * current archive_entry to the first non-meta file.
	 * If there is no non-meta files, EPKG_END is returned.
	 */
-
	ret = pkg_open2(&pkg, &a, &ae, path, keys);
+
	ret = pkg_open2(&pkg, &a, &ae, path, keys, 0);
	if (ret == EPKG_END)
		extract = false;
	else if (ret != EPKG_OK) {
modified libpkg/pkg_jobs.c
@@ -468,7 +468,7 @@ pkg_jobs_install(struct pkg_jobs *j)
		}
		snprintf(path, sizeof(path), "%s/%s", cachedir, pkgrepopath);

-
		pkg_open(&newpkg, path, keys);
+
		pkg_open(&newpkg, path, keys, 0);
		if (newversion != NULL) {
			pkg_emit_upgrade_begin(p);
		} else {
@@ -666,7 +666,7 @@ pkg_jobs_fetch(struct pkg_jobs *j)
		pkg_get(p, PKG_REPOPATH, &pkgrepopath);
		snprintf(path, sizeof(path), "%s/%s", cachedir,
		    pkgrepopath);
-
		if (pkg_open(&pkg, path, keys) != EPKG_OK) {
+
		if (pkg_open(&pkg, path, keys, 0) != EPKG_OK) {
			return (EPKG_FATAL);
		}

modified libpkg/pkg_repo.c
@@ -467,7 +467,7 @@ read_pkg_file(void *data)

		r = calloc(1, sizeof(struct pkg_result));

-
		if (pkg_open(&r->pkg, fts_accpath, keys) != EPKG_OK) {
+
		if (pkg_open(&r->pkg, fts_accpath, keys, PKG_OPEN_MANIFEST_ONLY) != EPKG_OK) {
			r->retcode = EPKG_WARN;
		} else {
			sha256_file(fts_accpath, r->cksum);
modified libpkg/private/pkg.h
@@ -310,7 +310,7 @@ int pkg_add_user_group(struct pkg *pkg);
int pkg_delete_user_group(struct pkgdb *db, struct pkg *pkg);

int pkg_open2(struct pkg **p, struct archive **a, struct archive_entry **ae,
-
	      const char *path, struct pkg_manifest_key *keys);
+
	      const char *path, struct pkg_manifest_key *keys, int flags);

void pkg_list_free(struct pkg *, pkg_list);

modified pkg/clean.c
@@ -209,7 +209,7 @@ usage_clean(void)
}

int
-
exec_clean(__unused int argc, __unused char **argv)
+
exec_clean(int argc, char **argv)
{
	struct pkgdb	*db = NULL;
	struct pkgdb_it	*it = NULL;
@@ -298,7 +298,7 @@ exec_clean(__unused int argc, __unused char **argv)
		if (repopath[0] == '/')
			repopath++;

-
		if (pkg_open(&pkg, ent->fts_path, keys) != EPKG_OK) {
+
		if (pkg_open(&pkg, ent->fts_path, keys, PKG_OPEN_MANIFEST_ONLY) != EPKG_OK) {
			if (!quiet)
				warnx("skipping %s", ent->fts_path);
			continue;
modified pkg/info.c
@@ -196,7 +196,7 @@ exec_info(int argc, char **argv)

	if (file != NULL) {
		pkg_manifest_keys_new(&keys);
-
		if (pkg_open(&pkg, file, keys) != EPKG_OK) {
+
		if (pkg_open(&pkg, file, keys, 0) != EPKG_OK) {
			return (1);
		}
		pkg_manifest_keys_free(keys);
modified pkg/query.c
@@ -927,7 +927,7 @@ exec_query(int argc, char **argv)

	if (pkgname != NULL) {
		pkg_manifest_keys_new(&keys);
-
		if (pkg_open(&pkg, pkgname, keys) != EPKG_OK) {
+
		if (pkg_open(&pkg, pkgname, keys, 0) != EPKG_OK) {
			return (EX_IOERR);
		}