Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Load repository from a given dir ordered by filename
Baptiste Daroussin committed 11 years ago
commit 6003c750e924620beab6dd8947a00be34b701ebc
parent e232d64
2 files changed +38 -10
modified libpkg/pkg_config.c
@@ -646,32 +646,39 @@ load_repo_file(const char *repofile, pkg_init_flags flags)
	ucl_object_unref(obj);
}

+
static int
+
nodots(const struct dirent *dp)
+
{
+
	return (dp->d_name[0] != '.');
+
}
+

static void
load_repo_files(const char *repodir, pkg_init_flags flags)
{
-
	struct dirent *ent;
-
	DIR *d;
+
	struct dirent **ent;
	char *p;
	size_t n;
+
	int nents, i;
	char path[MAXPATHLEN];

-
	if ((d = opendir(repodir)) == NULL)
-
		return;
-

	pkg_debug(1, "PkgConfig: loading repositories in %s", repodir);
-
	while ((ent = readdir(d))) {
-
		if ((n = strlen(ent->d_name)) <= 5)
+

+
	nents = scandir(repodir, &ent, nodots, alphasort);
+
	for (i = 0; i < nents; i++) {
+
		if ((n = strlen(ent[i]->d_name)) <= 5)
			continue;
-
		p = &ent->d_name[n - 5];
+
		p = &ent[i]->d_name[n - 5];
		if (strcmp(p, ".conf") == 0) {
			snprintf(path, sizeof(path), "%s%s%s",
			    repodir,
			    repodir[strlen(repodir) - 1] == '/' ? "" : "/",
-
			    ent->d_name);
+
			    ent[i]->d_name);
			load_repo_file(path, flags);
		}
+
		free(ent[i]);
	}
-
	closedir(d);
+
	if (nents >= 0)
+
		free(ent);
}

static void
modified tests/frontend/pkg.shin
@@ -84,10 +84,31 @@ EOF
		-s exit:0 test -f test-1.txz
}

+
atf_test_case pkg_repo_load_order
+
pkg_repo_load_order_head()
+
{
+
	atf_set "descr" "Testing the order the repository configuration files are loaded"
+
}
+

+
pkg_repo_load_order_body()
+
{
+
	echo "03_repo: { url: file:///03_repo }" > plop.conf
+
	echo "02_repo: { url: file:///02_repo }" > 02.conf
+
	echo "01_repo: { url: file:///01_repo }" > 01.conf
+

+
	out=$(pkg -o REPOS_DIR=. -vv | tail -13)
+
	atf_check \
+
		-o match:'.*01_repo\:.*02_repo\:.*03_repo\:.*' \
+
		-e empty \
+
		-s exit:0 \
+
		echo $out
+
}
+

atf_init_test_cases() {
        . $(atf_get_srcdir)/test_environment.sh

	atf_add_test_case pkg_no_database
	atf_add_test_case pkg_config_defaults
	atf_add_test_case pkg_create_manifest_bad_syntax
+
	atf_add_test_case pkg_repo_load_order
}