Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix repos initialization
Vsevolod Stakhov committed 9 years ago
commit c95bf07bee87037b7ff620aae308e3496352dfd1
parent fc2875b
2 files changed +32 -13
modified libpkg/pkgdb.c
@@ -741,7 +741,7 @@ pkgdb_is_insecure_mode(const char *path, bool install_as_user)
			return (EPKG_ENOACCESS);
		else if (errno == ENOENT)
			return (EPKG_ENODB);
-
		else 
+
		else
			return (EPKG_FATAL);
	}

@@ -835,7 +835,7 @@ pkgdb_check_access(unsigned mode, const char* dbdir, const char *dbname)
		else
			return (EPKG_FATAL);
	}
-
 
+

	return (EPKG_OK);
}

@@ -852,7 +852,7 @@ pkgdb_access(unsigned mode, unsigned database)
	 *
	 * EPKG_ENODB:  a database doesn't exist and we don't want to create
	 *             it, or dbdir doesn't exist
-
	 * 
+
	 *
	 * EPKG_INSECURE: the dbfile or one of the directories in the
	 *	       path to it are writable by other than root or
	 *             (if $INSTALL_AS_USER is set) the current euid
@@ -944,6 +944,10 @@ pkgdb_open_repos(struct pkgdb *db, const char *reponame)
	struct _pkg_repo_list_item *item;

	while (pkg_repos(&r) == EPKG_OK) {
+
		if (!r->enable) {
+
			continue;
+
		}
+

		if (reponame == NULL || strcasecmp(r->name, reponame) == 0) {
			/* We need read only access here */
			if (r->ops->open(r, R_OK) == EPKG_OK) {
@@ -1189,7 +1193,7 @@ pkgdb_close(struct pkgdb *db)
	free(db);
}

-
/* How many times to try COMMIT or ROLLBACK if the DB is busy */ 
+
/* How many times to try COMMIT or ROLLBACK if the DB is busy */
#define BUSY_RETRIES	6
#define BUSY_SLEEP	200

@@ -2095,7 +2099,7 @@ pkgdb_reanalyse_shlibs(struct pkgdb *db, struct pkg *pkg)

		"DELETE FROM shlibs "
		"WHERE id NOT IN "
-
		"(SELECT DISTINCT shlib_id FROM pkg_shlibs_required)" 
+
		"(SELECT DISTINCT shlib_id FROM pkg_shlibs_required)"
		"AND id NOT IN "
		"(SELECT DISTINCT shlib_id FROM pkg_shlibs_provided)",
	};
@@ -2268,7 +2272,7 @@ pkgdb_register_finale(struct pkgdb *db, int retcode)

	assert(db != NULL);

-
	if (retcode == EPKG_OK) 
+
	if (retcode == EPKG_OK)
		ret = pkgdb_transaction_commit_sqlite(db->sqlite, NULL);
	else
		ret = pkgdb_transaction_rollback_sqlite(db->sqlite, NULL);
modified libpkg/repo/binary/init.c
@@ -315,31 +315,46 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)

	/* Open metafile */
	if (access(filepath, R_OK) != -1) {
-
		if (pkg_repo_meta_load(filepath, &repo->meta) != EPKG_OK)
+
		if (pkg_repo_meta_load(filepath, &repo->meta) != EPKG_OK) {
+
			pkg_emit_error("Repository %s load error: "
+
					"meta cannot be loaded %s", pkg_repo_name(repo),
+
					strerror(errno));
			return (EPKG_FATAL);
+
		}
	}

	snprintf(filepath, sizeof(filepath), "%s/%s",
		dbdir, pkg_repo_binary_get_filename(pkg_repo_name(repo)));

	/* Always want read mode here */
-
	if (access(filepath, R_OK | mode) != 0)
+
	if (access(filepath, R_OK | mode) != 0) {
+
		pkg_emit_error("Repository %s load error: "
+
				"access repo file(%s) failed: %s", pkg_repo_name(repo),
+
				filepath,
+
				strerror(errno));
		return (EPKG_ENOACCESS);
+
	}

	flags = (mode & W_OK) != 0 ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;
-
	if (sqlite3_open_v2(filepath, &sqlite, flags, NULL) != SQLITE_OK)
+
	if (sqlite3_open_v2(filepath, &sqlite, flags, NULL) != SQLITE_OK) {
+
		pkg_emit_error("Repository %s load error: "
+
				"cannot open sqlite3 db: %s", pkg_repo_name(repo),
+
				strerror(errno));
		return (EPKG_FATAL);
+
	}

	/* Sanitise sqlite database */
	if (get_pragma(sqlite, "SELECT count(name) FROM sqlite_master "
		"WHERE type='table' AND name='repodata';", &res, false) != EPKG_OK) {
-
		pkg_emit_error("Unable to query repository");
+
		pkg_emit_error("Repository %s load error: "
+
				"unable to query db: %s", pkg_repo_name(repo),
+
				strerror(errno));
		sqlite3_close(sqlite);
		return (EPKG_FATAL);
	}

	if (res != 1) {
-
		pkg_emit_notice("Repository %s contains no repodata table, "
+
		pkg_emit_error("Repository %s contains no repodata table, "
			"need to re-create database", repo->name);
		sqlite3_close(sqlite);
		return (EPKG_FATAL);
@@ -353,7 +368,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	get_pragma(sqlite, req, &res, true);
	sqlite3_free(req);
	if (res != 1) {
-
		pkg_emit_notice("Repository %s has a wrong packagesite, need to "
+
		pkg_emit_error("Repository %s has a wrong packagesite, need to "
			"re-create database", repo->name);
		sqlite3_close(sqlite);
		return (EPKG_FATAL);
@@ -380,7 +395,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)
	}
	it->ops->free(it);
	if (pkg->digest == NULL || !pkg_checksum_is_valid(pkg->digest, strlen(pkg->digest))) {
-
		pkg_emit_notice("Repository %s has incompatible checksum format, need to "
+
		pkg_emit_error("Repository %s has incompatible checksum format, need to "
			"re-create database", repo->name);
		pkg_free(pkg);
		sqlite3_close(sqlite);