Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a private function to retrive annotations
Baptiste Daroussin committed 11 years ago
commit d8b3bb56a45f838bdc5a8a38f3e68ef14958d147
parent 6da09b7
5 files changed +32 -22
modified libpkg/pkg.c
@@ -1215,10 +1215,25 @@ pkg_addprovide(struct pkg *pkg, const char *name)
	return (EPKG_OK);
}

+
const char *
+
pkg_getannotation(const struct pkg *pkg, const char *tag)
+
{
+
	const ucl_object_t *an, *notes;
+

+
	assert(pkg != NULL);
+
	assert(tag != NULL);
+

+
	pkg_get(pkg, PKG_ANNOTATIONS, &notes);
+
	an = pkg_object_find(notes, tag);
+

+
	if (an == NULL)
+
		return (NULL);
+
	return (pkg_object_string(an));
+
}
+

int
pkg_addannotation(struct pkg *pkg, const char *tag, const char *value)
{
-
	const ucl_object_t *an, *notes;
	ucl_object_t *o, *annotations;

	assert(pkg != NULL);
@@ -1227,9 +1242,7 @@ pkg_addannotation(struct pkg *pkg, const char *tag, const char *value)

	/* Tags are unique per-package */

-
	pkg_get(pkg, PKG_ANNOTATIONS, &notes);
-
	an = pkg_object_find(notes, tag);
-
	if (an != NULL) {
+
	if (pkg_getannotation(pkg, tag) != NULL) {
		if (pkg_object_bool(pkg_config_get("DEVELOPER_MODE"))) {
			pkg_emit_error("duplicate annotation tag: %s value: %s,"
			    " fatal (developer mode)", tag, value);
modified libpkg/pkg_create.c
@@ -52,7 +52,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
	struct stat	 st;
	char		 sha256[SHA256_DIGEST_LENGTH * 2 + 1];
	int64_t		 flatsize = 0;
-
	const ucl_object_t	*obj, *an;
+
	const char	*relocation;
	struct hardlinks *hardlinks = NULL;

	if (pkg_is_valid(pkg) != EPKG_OK) {
@@ -60,8 +60,9 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		return (EPKG_FATAL);
	}

-
	pkg_get(pkg, PKG_ANNOTATIONS, &an);
-
	obj = pkg_object_find(an, "relocated");
+
	relocation = pkg_getannotation(pkg, "relocated");
+
	if (relocation == NULL)
+
		relocation = "";

	/*
	 * Get / compute size / checksum if not provided in the manifest
@@ -71,7 +72,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		const char *pkg_sum = pkg_file_cksum(file);

		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
-
		    obj ? pkg_object_string(obj) : "", pkg_path);
+
		    relocation, pkg_path);

		if (lstat(fpath, &st) == -1) {
			pkg_emit_error("file '%s' is missing", fpath);
@@ -145,7 +146,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		const char *pkg_path = pkg_file_path(file);

		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
-
		    obj ? pkg_object_string(obj) : "", pkg_path);
+
		    relocation, pkg_path);

		ret = packing_append_file_attr(pkg_archive, fpath, pkg_path,
		    file->uname, file->gname, file->perm);
@@ -158,7 +159,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		const char *pkg_path = pkg_dir_path(dir);

		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
-
		    obj ? pkg_object_string(obj) : "", pkg_path);
+
		    relocation, pkg_path);

		ret = packing_append_file_attr(pkg_archive, fpath, pkg_path,
		    dir->uname, dir->gname, dir->perm);
modified libpkg/pkg_jobs.c
@@ -876,7 +876,7 @@ pkg_jobs_need_upgrade(struct pkg *rp, struct pkg *lp)
	struct pkg_shlib *ls = NULL, *rs = NULL;
	struct pkg_conflict *lc = NULL, *rc = NULL;
	struct pkg_provide *lpr = NULL, *rpr = NULL;
-
	const ucl_object_t *an, *obj;
+
	const char *repository;

	/* If no local package, then rp is obviously need to be added */
	if (lp == NULL)
@@ -909,10 +909,9 @@ pkg_jobs_need_upgrade(struct pkg *rp, struct pkg *lp)

	/* Check reponame */
	pkg_get(rp, PKG_REPONAME, &reponame);
-
	pkg_get(lp, PKG_ANNOTATIONS, &obj);
-
	an = pkg_object_find(obj, "repository");
-
	if (an != NULL)  {
-
		if (strcmp(reponame, ucl_object_tostring(an)) != 0) {
+
	repository = pkg_getannotation(lp, "repository");
+
	if (repository != NULL) {
+
		if (strcmp(reponame, repository) != 0) {
			/*
			 * If we have packages from some different repo, then
			 * we should not try to detect options changed and so on,
@@ -920,7 +919,7 @@ pkg_jobs_need_upgrade(struct pkg *rp, struct pkg *lp)
			 */
			pkg_debug(2, "package %s was installed from repo %s, so we ignore "
					"the same version of %s in %s repository", origin,
-
					ucl_object_tostring(an), origin, reponame);
+
					repository , origin, reponame);
			return (false);
		}
	}
modified libpkg/pkg_printf.c
@@ -1310,16 +1310,12 @@ struct sbuf *
format_repo_ident(struct sbuf *sbuf, const void *data, struct percent_esc *p)
{
	const struct pkg	*pkg = data;
-
	const ucl_object_t	*an, *rn;
	const char		*reponame;

	pkg_get(pkg, PKG_REPONAME, &reponame);
	if (reponame == NULL) {
-
		pkg_get(pkg, PKG_ANNOTATIONS, &an);
-
		rn = pkg_object_find(an, "repository");
-
		if (rn != NULL)
-
			reponame = ucl_object_tostring(rn);
-
		else
+
		reponame = pkg_getannotation(pkg, "repository");
+
		if (reponame == NULL)
			reponame = "unknown-repository";
	}
	return (string_val(sbuf, reponame, p));
modified libpkg/private/pkg.h
@@ -579,5 +579,6 @@ void pkg_add_dir_to_del(struct pkg *pkg, const char *file, const char *dir);
struct plist *plist_new(struct pkg *p, const char *stage);
int plist_parse_line(struct pkg *pkg, struct plist *p, char *line);
void plist_free(struct plist *);
+
const char *pkg_getannotation(const struct pkg *, const char *);

#endif