Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Load conflicts from a repo.
Vsevolod Stakhov committed 12 years ago
commit c0bbd657480cad3dc9cbcaf77d3cd2c768fa4197
parent 0480072
3 files changed +69 -1
modified libpkg/pkgdb_repo.c
@@ -929,3 +929,15 @@ pkgdb_repo_origins(sqlite3 *sqlite)

	return pkgdb_it_new(&repodb, stmt, PKG_REMOTE, PKGDB_IT_FLAG_ONCE);
}
+

+
int
+
pkgdb_repo_register_conflicts(const char *origin, char **conflicts,
+
		int conflicts_num, sqlite3 *sqlite)
+
{
+
	/* TODO: implement this */
+
	(void)origin;
+
	(void)conflicts;
+
	(void)conflicts_num;
+
	(void)sqlite;
+
	return (EPKG_OK);
+
}
modified libpkg/private/pkgdb.h
@@ -137,4 +137,15 @@ int pkgdb_repo_check_version(struct pkgdb *db, const char *database);
 */
struct pkgdb_it *pkgdb_repo_origins(sqlite3 *sqlite);

+
/**
+
 * Register a conflicts list in a repo
+
 * @param origin the origin of a package
+
 * @param conflicts a list of conflicts origins
+
 * @param conflicts_num number of conflicts for this package
+
 * @param sqlite database
+
 * @return error code
+
 */
+
int pkgdb_repo_register_conflicts(const char *origin, char **conflicts,
+
		int conflicts_num, sqlite3 *sqlite);
+

#endif
modified libpkg/update.c
@@ -448,10 +448,42 @@ pkg_update_increment_item_new(struct pkg_increment_task_item **head, const char
	HASH_ADD_KEYPTR(hh, *head, item->origin, strlen(item->origin), item);
}

+
static void
+
pkg_parse_conflicts_file(FILE *f, sqlite3 *sqlite)
+
{
+
	size_t linecap = 0;
+
	ssize_t linelen;
+
	char *linebuf = NULL, *p, **deps;
+
	const char *origin, *pdep;
+
	int ndep, i;
+

+
	while ((linelen = getline(&linebuf, &linecap, f)) > 0) {
+
		p = linebuf;
+
		origin = strsep(&p, ":");
+
		/* Check dependencies number */
+
		pdep = p;
+
		ndep = 1;
+
		while (*pdep != '\0') {
+
			if (*pdep == ',')
+
				ndep ++;
+
			pdep ++;
+
		}
+
		deps = malloc(sizeof(char *) * ndep);
+
		for (i = 0; i < ndep; i ++) {
+
			deps[i] = strsep(&p, ",");
+
		}
+
		pkgdb_repo_register_conflicts(origin, deps, ndep, sqlite);
+
		free(deps);
+
	}
+

+
	if (linebuf != NULL)
+
		free(linebuf);
+
}
+

static int
pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
{
-
	FILE *fmanifest = NULL, *fdigests = NULL;
+
	FILE *fmanifest = NULL, *fdigests = NULL, *fconflicts = NULL;
	sqlite3 *sqlite = NULL;
	struct pkg *pkg = NULL;
	int rc = EPKG_FATAL;
@@ -503,6 +535,10 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
			&rc, repo_packagesite_file);
	if (fmanifest == NULL)
		goto cleanup;
+
	local_t = *mtime;
+
	fmanifest = repo_fetch_remote_extract_tmp(repo,
+
			repo_conflicts_archive, "txz", &local_t,
+
			&rc, repo_conflicts_file);
	*mtime = local_t;
	fseek(fmanifest, 0, SEEK_END);
	len = ftell(fmanifest);
@@ -583,6 +619,11 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
		free(item);
	}
	pkg_manifest_parser_free(parser);
+

+
	if (fconflicts != NULL) {
+
		pkg_parse_conflicts_file(fconflicts, sqlite);
+
	}
+

	pkg_emit_incremental_update(updated, removed, added, processed);

cleanup:
@@ -596,8 +637,12 @@ cleanup:
		fclose(fmanifest);
	if (fdigests)
		fclose(fdigests);
+
	if (fconflicts)
+
		fclose(fconflicts);
	if (map != MAP_FAILED)
		munmap(map, len);
+
	if (linebuf != NULL)
+
		free(linebuf);

	return (rc);
}