Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Sort fts traversal in repo creation
Ed Maste committed 8 years ago
commit 49c4fb7b158ae4ed3378dc3b4e0a453f14db7749
parent 2e15b90
1 file changed +12 -1
modified libpkg/pkg_repo_create.c
@@ -497,6 +497,17 @@ pkg_create_repo_read_pipe(int fd, struct digest_list_entry **dlist)
	return (EPKG_OK);
}

+
static int
+
fts_compare(const FTSENT *const *a, const FTSENT *const *b)
+
{
+
	/* Sort files before directories, then alpha order */
+
	if ((*a)->fts_info != FTS_D && (*b)->fts_info == FTS_D)
+
		return -1;
+
	if ((*a)->fts_info == FTS_D && (*b)->fts_info != FTS_D)
+
		return 1;
+
	return (strcmp((*a)->fts_name, (*b)->fts_name));
+
}
+

int
pkg_create_repo(char *path, const char *output_dir, bool filelist,
	const char *metafile)
@@ -566,7 +577,7 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
			num_workers = 6;
	}

-
	if ((fts = fts_open(repopath, FTS_PHYSICAL|FTS_NOCHDIR, NULL)) == NULL) {
+
	if ((fts = fts_open(repopath, FTS_PHYSICAL|FTS_NOCHDIR, fts_compare)) == NULL) {
		pkg_emit_errno("fts_open", path);
		retcode = EPKG_FATAL;
		goto cleanup;