Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
more conversion from utlist to tllist
Baptiste Daroussin committed 4 years ago
commit 55e87436a94f9c806f545c57407921cc24731ba1
parent 94275db
3 files changed +24 -26
modified libpkg/fetch.c
@@ -179,9 +179,9 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
    time_t *t, ssize_t offset, int64_t size, bool silent)
{
	struct url	*u = NULL;
-
	struct pkg_kv	*kv, *kvtmp;
-
	struct pkg_kv	*envtorestore = NULL;
-
	struct pkg_kv	*envtounset = NULL;
+
	struct pkg_kv	*kv;
+
	kvlist_t	 envtorestore = tll_init();
+
	kvlist_t	 envtounset = tll_init();
	char		*tmp;
	off_t		 done = 0;
	off_t		 r;
@@ -233,16 +233,16 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,

	if (repo != NULL) {
		repo->silent = silent;
-
		LL_FOREACH(repo->env, kv) {
-
			kvtmp = xcalloc(1, sizeof(*kvtmp));
-
			kvtmp->key = xstrdup(kv->key);
-
			if ((tmp = getenv(kv->key)) != NULL) {
-
				kvtmp->value = xstrdup(tmp);
-
				DL_APPEND(envtorestore, kvtmp);
+
		tll_foreach(repo->env, k) {
+
			kv = xcalloc(1, sizeof(*kv));
+
			kv->key = xstrdup(k->item->key);
+
			if ((tmp = getenv(k->item->key)) != NULL) {
+
				kv->value = xstrdup(tmp);
+
				tll_push_back(envtorestore, kv);
			} else {
-
				DL_APPEND(envtounset, kvtmp);
+
				tll_push_back(envtounset, kv);
			}
-
			setenv(kv->key, kv->value, 1);
+
			setenv(k->item->key, k->item->value, 1);
		}
	} else {
		fakerepo = xcalloc(1, sizeof(struct pkg_repo));
@@ -328,15 +328,16 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,

cleanup:
	if (repo != NULL) {
-
		LL_FOREACH_SAFE(envtorestore, kv, kvtmp) {
-
			setenv(kv->key, kv->value, 1);
-
			LL_DELETE(envtorestore, kv);
-
			pkg_kv_free(kv);
+
		tll_foreach(envtorestore, k) {
+
			setenv(k->item->key, k->item->value, 1);
+
			tll_remove_and_free(envtorestore, k, pkg_kv_free);
		}
-
		LL_FOREACH_SAFE(envtounset, kv, kvtmp) {
-
			unsetenv(kv->key);
-
			pkg_kv_free(kv);
+
		tll_free(envtorestore);
+
		tll_foreach(envtounset, k) {
+
			unsetenv(k->item->key);
+
			tll_remove_and_free(envtounset, k, pkg_kv_free);
		}
+
		tll_free(envtounset);
	}

	if (u != NULL) {
modified libpkg/pkg_config.c
@@ -770,7 +770,7 @@ add_repo(const ucl_object_t *obj, struct pkg_repo *r, const char *rname, pkg_ini
		while ((cur = ucl_iterate_object(env, &it, true))) {
			kv = pkg_kv_new(ucl_object_key(cur),
			    ucl_object_tostring_forced(cur));
-
			DL_APPEND(r->env, kv);
+
			tll_push_back(r->env, kv);
		}
	}
}
@@ -1470,8 +1470,6 @@ pkg_repo_overwrite(struct pkg_repo *r, const char *name, const char *url,
static void
pkg_repo_free(struct pkg_repo *r)
{
-
	struct pkg_kv *kv, *tmp;
-

	free(r->url);
	free(r->name);
	free(r->pubkey);
@@ -1481,10 +1479,7 @@ pkg_repo_free(struct pkg_repo *r)
		fprintf(r->ssh, "quit\n");
		pclose(r->ssh);
	}
-
	LL_FOREACH_SAFE(r->env, kv, tmp) {
-
		LL_DELETE(r->env, kv);
-
		pkg_kv_free(kv);
-
	}
+
	tll_free_and_free(r->env, pkg_kv_free);
	free(r);
}

modified libpkg/private/pkg.h
@@ -157,6 +157,8 @@ struct pkg_repo;
struct pkg_message;
struct pkg_lua_script;

+
typedef tll(struct pkg_kv *) kvlist_t;
+

struct pkg {
	bool		 direct;
	bool		 locked;
@@ -508,7 +510,7 @@ struct pkg_repo {
	unsigned int priority;

	pkg_repo_flags flags;
-
	struct pkg_kv *env;
+
	kvlist_t env;

	/* Opaque repository data */
	void *priv;