Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Stop creating pkg 1.0 catalog
Baptiste Daroussin committed 12 years ago
commit 73bc6880cc9ce3190c9f1bd413312c8836acfeb5
parent c962de3
4 files changed +15 -201
modified libpkg/pkg.h.in
@@ -940,7 +940,7 @@ int pkg_is_installed(struct pkgdb *db, const char *origin);
 * @param data A pointer which is passed to the callback.
 * @param sum An 65 long char array to receive the sha256 sum
 */
-
int pkg_create_repo(char *path, bool force, bool filelist, void (*callback)(struct pkg *, void *), void *);
+
int pkg_create_repo(char *path, bool filelist, void (*callback)(struct pkg *, void *), void *);
int pkg_finish_repo(char *path, pem_password_cb *cb, char **argv, int argc, bool filelist);

/**
modified libpkg/pkg_repo.c
@@ -138,36 +138,6 @@ pkg_repo_fetch(struct pkg *pkg)
	return (retcode);
}

-
static void
-
pack_extract(const char *pack, const char *dbname, const char *dbpath)
-
{
-
	struct archive *a = NULL;
-
	struct archive_entry *ae = NULL;
-

-
	if (access(pack, F_OK) != 0)
-
		return;
-

-
	a = archive_read_new();
-
	archive_read_support_filter_all(a);
-
	archive_read_support_format_tar(a);
-
	if (archive_read_open_filename(a, pack, 4096) != ARCHIVE_OK) {
-
		/* if we can't unpack it it won't be useful for us */
-
		unlink(pack);
-
		archive_read_free(a);
-
		return;
-
	}
-

-
	while (archive_read_next_header(a, &ae) == ARCHIVE_OK) {
-
		if (strcmp(archive_entry_pathname(ae), dbname) == 0) {
-
			archive_entry_set_pathname(ae, dbpath);
-
			archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS);
-
			break;
-
		}
-
	}
-

-
	archive_read_free(a);
-
}
-

struct digest_list_entry {
	char *origin;
	char *digest;
@@ -183,7 +153,7 @@ digest_sort_compare_func(struct digest_list_entry *d1, struct digest_list_entry
}

int
-
pkg_create_repo(char *path, bool force, bool filelist,
+
pkg_create_repo(char *path, bool filelist,
		void (progress)(struct pkg *pkg, void *data), void *data)
{
	FTS *fts = NULL;
@@ -192,14 +162,11 @@ pkg_create_repo(char *path, bool force, bool filelist,
	size_t len;
	pthread_t *tids = NULL;
	struct digest_list_entry *dlist = NULL, *cur_dig, *dtmp;
-
	sqlite3 *sqlite = NULL;

-
	char *errmsg = NULL;
	int retcode = EPKG_OK;

	char *repopath[2];
	char repodb[MAXPATHLEN + 1];
-
	char repopack[MAXPATHLEN + 1];
	char *manifest_digest;
	FILE *psyml, *fsyml, *mandigests;

@@ -241,17 +208,6 @@ pkg_create_repo(char *path, bool force, bool filelist,
		goto cleanup;
	}

-
	snprintf(repodb, sizeof(repodb), "%s/%s", path, repo_db_file);
-
	snprintf(repopack, sizeof(repopack), "%s/repo.txz", path);
-

-
	pack_extract(repopack, repo_db_file, repodb);
-

-
	if ((retcode = pkgdb_repo_open(repodb, force, &sqlite, true)) != EPKG_OK)
-
		goto cleanup;
-

-
	if ((retcode = pkgdb_repo_init(sqlite, true)) != EPKG_OK)
-
		goto cleanup;
-

	thd_data.root_path = path;
	thd_data.max_results = num_workers;
	thd_data.num_results = 0;
@@ -299,33 +255,10 @@ pkg_create_repo(char *path, bool force, bool filelist,
			continue;
		}

-
		/* do not add if package if already in repodb
-
		   (possibly at a different pkg_path) */
-

-
		retcode = pkgdb_repo_cksum_exists(sqlite, r->cksum);
-
		if (retcode == EPKG_FATAL) {
-
			goto cleanup;
-
		}
-
		else if (retcode == EPKG_OK) {
-
			pkg_free(r->pkg);
-
			free(r);
-
			continue;
-
		}
-

		/* EPKG_END returned */

		if (progress != NULL)
			progress(r->pkg, data);
-
		retcode = pkgdb_repo_add_package(r->pkg, r->path, sqlite,
-
				manifest_digest, false, true);
-
		if (retcode == EPKG_END) {
-
			pkg_free(r->pkg);
-
			free(r);
-
			continue;
-
		}
-
		else if (retcode != EPKG_OK) {
-
			goto cleanup;
-
		}

		manifest_pos = ftell(psyml);
		pkg_emit_manifest_file(r->pkg, psyml, PKG_MANIFEST_EMIT_COMPACT, &manifest_digest);
@@ -352,14 +285,9 @@ pkg_create_repo(char *path, bool force, bool filelist,
	/* Now sort all digests */
	LL_SORT(dlist, digest_sort_compare_func);
cleanup:
-
	if (pkgdb_repo_close(sqlite, retcode == EPKG_OK) != EPKG_OK) {
-
		retcode = EPKG_FATAL;
-
	}
	LL_FOREACH_SAFE(dlist, cur_dig, dtmp) {
-
		if (retcode == EPKG_OK) {
-
			fprintf(mandigests, "%s:%s:%ld:%ld\n", cur_dig->origin,
-
				cur_dig->digest, cur_dig->manifest_pos, cur_dig->files_pos);
-
		}
+
		fprintf(mandigests, "%s:%s:%ld:%ld\n", cur_dig->origin,
+
		    cur_dig->digest, cur_dig->manifest_pos, cur_dig->files_pos);
		free(cur_dig->digest);
		free(cur_dig->origin);
		free(cur_dig);
@@ -390,14 +318,6 @@ cleanup:
	if (mandigests != NULL)
		fclose(mandigests);

-
	if (sqlite != NULL)
-
		sqlite3_close(sqlite);
-

-
	if (errmsg != NULL)
-
		sqlite3_free(errmsg);
-

-
	sqlite3_shutdown();
-

	return (retcode);
}

@@ -637,8 +557,10 @@ pack_db(const char *name, const char *archive, char *path, struct rsa_key *rsa,

	packing_finish(pack);
	unlink(path);
-
	sbuf_delete(sig);
-
	sbuf_delete(pub);
+
	if (sig != NULL)
+
		sbuf_delete(sig);
+
	if (pub != NULL)
+
		sbuf_delete(pub);

	return (EPKG_OK);
}
@@ -676,13 +598,6 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char **argv, int argc,
		goto cleanup;
	}

-
	snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_db_file);
-
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_db_archive);
-
	if (pack_db(repo_db_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
-
		ret = EPKG_FATAL;
-
		goto cleanup;
-
	}
-

	if (filelist) {
		snprintf(repo_path, sizeof(repo_path), "%s/%s", path, repo_filesite_file);
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s", path, repo_filesite_archive);
modified libpkg/update.c
@@ -523,101 +523,6 @@ pkg_register_repo(struct pkg_repo *repo, sqlite3 *sqlite)
}

static int
-
pkg_update_full(const char *repofile, struct pkg_repo *repo, time_t *mtime)
-
{
-
	char repofile_unchecked[MAXPATHLEN];
-
	int fd = -1, rc = EPKG_FATAL;
-
	sqlite3 *sqlite = NULL;
-
	char *req = NULL;
-
	char *bad_abis = NULL;
-
	const char *myarch;
-

-
	snprintf(repofile_unchecked, sizeof(repofile_unchecked),
-
			"%s.unchecked", repofile);
-

-
	/* If the repo.sqlite file exists, test that we can write to
-
		   it.  If it doesn't exist, assume we can create it */
-

-
	if (eaccess(repofile, F_OK) == 0 && eaccess(repofile, W_OK) == -1) {
-
		pkg_emit_error("Insufficient privilege to update %s\n",
-
				repofile);
-
		rc = EPKG_ENOACCESS;
-
		goto cleanup;
-
	}
-

-
	if ((fd = repo_fetch_remote_tmp(repo, repo_db_archive, "txz", mtime, &rc)) == -1) {
-
		goto cleanup;
-
	}
-

-
	if ((rc = repo_archive_extract_file(fd, repo_db_file, repofile_unchecked, repo, -1)) != EPKG_OK) {
-
		goto cleanup;
-
	}
-

-
	/* check if the repository is for valid architecture */
-
	if (access(repofile_unchecked, R_OK|W_OK) == -1) {
-
		pkg_emit_error("Archive file does not have repo.sqlite file");
-
		rc = EPKG_FATAL;
-
		goto cleanup;
-
	}
-
	if (sqlite3_open(repofile_unchecked, &sqlite) != SQLITE_OK) {
-
		unlink(repofile_unchecked);
-
		pkg_emit_error("Corrupted repository");
-
		rc = EPKG_FATAL;
-
		goto cleanup;
-
	}
-

-
	pkg_config_string(PKG_CONFIG_ABI, &myarch);
-

-
	req = sqlite3_mprintf("select group_concat(arch, ', ') from "
-
			"(select distinct arch from packages "
-
			"where arch not GLOB '%q')", myarch);
-

-
	if (get_sql_string(sqlite, req, &bad_abis) != EPKG_OK) {
-
		sqlite3_free(req);
-
		pkg_emit_error("Unable to query repository");
-
		rc = EPKG_FATAL;
-
		sqlite3_close(sqlite);
-
		goto cleanup;
-
	}
-

-
	if (bad_abis != NULL) {
-
		pkg_emit_error("At least one of the packages provided by "
-
				"the repository is not compatible with your ABI:\n"
-
				"    Your ABI: %s\n"
-
				"    Incompatible ABIs found: %s",
-
				myarch, bad_abis);
-
		rc = EPKG_FATAL;
-
		sqlite3_close(sqlite);
-
		goto cleanup;
-
	}
-

-
	/* register the packagesite */
-
	if (pkg_register_repo(repo, sqlite) != EPKG_OK) {
-
		sqlite3_close(sqlite);
-
		goto cleanup;
-
	}
-

-
	sqlite3_close(sqlite);
-
	sqlite3_shutdown();
-

-
	if (rename(repofile_unchecked, repofile) != 0) {
-
		pkg_emit_errno("rename", "");
-
		rc = EPKG_FATAL;
-
		goto cleanup;
-
	}
-

-
	if ((rc = remote_add_indexes(pkg_repo_ident(repo))) != EPKG_OK)
-
		goto cleanup;
-
	rc = EPKG_OK;
-

-
	cleanup:
-
	if (fd != -1)
-
		(void)close(fd);
-

-
	return (rc);
-
}
-

-
static int
pkg_add_from_manifest(char *buf, const char *origin, long offset,
		const char *manifest_digest, const char *local_arch, sqlite3 *sqlite,
		struct pkg_manifest_key **keys, struct pkg **p)
@@ -928,11 +833,8 @@ pkg_update(struct pkg_repo *repo, bool force)

	res = pkg_update_incremental(repofile, repo, &t);
	if (res != EPKG_OK && res != EPKG_UPTODATE) {
-
		pkg_emit_notice("No digest falling back on legacy catalog format");
-

-
		/* Still try to do full upgrade */
-
		if ((res = pkg_update_full(repofile, repo, &t)) != EPKG_OK)
-
			goto cleanup;
+
		pkg_emit_notice("Unable to find catalogs");
+
		goto cleanup;
	}

	res = EPKG_OK;
modified pkg/repo.c
@@ -37,7 +37,7 @@
void
usage_repo(void)
{
-
	fprintf(stderr, "Usage: pkg repo [-flq] <repo-path> [<rsa-key>|signing_command: <the command>]\n\n");
+
	fprintf(stderr, "Usage: pkg repo [-lq] <repo-path> [<rsa-key>|signing_command: <the command>]\n\n");
	fprintf(stderr, "For more information see 'pkg help repo'.\n");
}

@@ -88,16 +88,13 @@ exec_repo(int argc, char **argv)
	int ret;
	int pos = 0;
	int ch;
-
	bool force = false, filelist = false;
+
	bool filelist = false;

-
	while ((ch = getopt(argc, argv, "flq")) != -1) {
+
	while ((ch = getopt(argc, argv, "lq")) != -1) {
		switch (ch) {
		case 'q':
			quiet = true;
			break;
-
		case 'f':
-
			force = true;
-
			break;
		case 'l':
			filelist = true;
			break;
@@ -121,9 +118,9 @@ exec_repo(int argc, char **argv)

	if (!quiet) {
		printf("Generating repository catalog in %s:  ", argv[0]);
-
		ret = pkg_create_repo(argv[0], force, filelist, progress, &pos);
+
		ret = pkg_create_repo(argv[0], filelist, progress, &pos);
	} else
-
		ret = pkg_create_repo(argv[0], force, filelist, NULL, NULL);
+
		ret = pkg_create_repo(argv[0], filelist, NULL, NULL);

	if (ret != EPKG_OK) {
		printf("Cannot create repository catalogue\n");