Date: Fri, 12 Sep 2014 23:09:43 -0500 From: Dan Lists <lists.dan@gmail.com> To: freebsd-questions <freebsd-questions@freebsd.org> Subject: Re: Repository Search Order Message-ID: <CAPW8bZ21B=rgDmwuYN4ezbTV6d3Z8FroPTWRkLJhDASyGBR7ew@mail.gmail.com> In-Reply-To: <CAPW8bZ3gfX_YMfLi0_7WnOMyJhT%2BvrWG17dJtkvyv334nc5pXA@mail.gmail.com> References: <CAPW8bZ3tnUk_FhR5oS-p7K-Cy3kY1rL8YDzdK11O860tjfcjpw@mail.gmail.com> <CAPW8bZ3gfX_YMfLi0_7WnOMyJhT%2BvrWG17dJtkvyv334nc5pXA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Looks like the list scrubbed the attachment. Here is the patch. --- libpkg/pkg_config.c.orig 2014-09-12 20:02:24.292995291 -0500 +++ libpkg/pkg_config.c 2014-09-12 21:08:07.945030287 -0500 @@ -592,6 +592,13 @@ ucl_object_unref(obj); } +int cmp(const void *a, const void *b) +{ + const char **ia = (const char **)a; + const char **ib = (const char **)b; + return strcmp(*ia, *ib); +} + static void load_repo_files(const char *repodir) { @@ -600,6 +607,8 @@ char *p; size_t n; char path[MAXPATHLEN]; + char *repos[1024]; + int r=0; if ((d = opendir(repodir)) == NULL) return; @@ -610,14 +619,26 @@ continue; p = &ent->d_name[n - 5]; if (strcmp(p, ".conf") == 0) { - snprintf(path, sizeof(path), "%s%s%s", + repos[r]=malloc(n+1); + snprintf(repos[r], n+1, ent->d_name); + r++; + } + } + closedir(d); + + if( r == 0 ) + return; + + qsort(repos, r, sizeof(char *), cmp); + + for( int i=0 ; i < r ; i++ ){ + snprintf(path, sizeof(path), "%s%s%s", repodir, repodir[strlen(repodir) - 1] == '/' ? "" : "/", - ent->d_name); + repos[i]); load_repo_file(path); + free(repos[i]); } - } - closedir(d); } static void On Fri, Sep 12, 2014 at 9:14 PM, Dan Lists <lists.dan@gmail.com> wrote: > Attached is a proof of concept patch that handles the sorting. For > production, the repos array would need bounds checking, and the 1024 should > be a define. > > > > On Fri, Sep 12, 2014 at 8:02 PM, Dan Lists <lists.dan@gmail.com> wrote: > >> man pkg.conf states: >> >> Repositories are prioritized in the order they are found on the >> REPOS_DIR >> search path, with individual repository configuration files in the >> same >> directory processed in alphabetical order. Earlier files take prece- >> dence, meaning that packages will be downloaded from them >> preferentially >> where the same package is available from several repositories. >> >> This is not true, but I would like it to be. >> >> # ls /usr/local/etc/pkg/repos/ >> 00_Local.conf 80_zzz.conf 90_fff.conf 99_mmm.conf FreeBSD.conf >> >> So the order should be local, zzz, fff, mmm. >> >> Repositories: >> mmm: { >> url : "http://some.dom/freebsd:8:x86:64/mmm", >> enabled : yes >> } >> fff: { >> url : "http://some.dom/freebsd:8:x86:64/fff", >> enabled : yes >> } >> local: { >> url : "file:///usr/ports/packages", >> enabled : yes >> } >> zzz: { >> url : "http://some.dom/freebsd:8:x86:64/zzz", >> enabled : yes >> } >> >> The order has no relation to alphabetical order at all. Interestingly, >> if I use find (unsorted), it matches the repository order! >> >> # find /usr/local/etc/pkg/repos >> /usr/local/etc/pkg/repos >> /usr/local/etc/pkg/repos/FreeBSD.conf >> /usr/local/etc/pkg/repos/99_mmm.conf >> /usr/local/etc/pkg/repos/90_fff.conf >> /usr/local/etc/pkg/repos/00_Local.conf >> /usr/local/etc/pkg/repos/80_zzz.conf >> >> I quick look at the source shows that load_repo_files is just reading the >> files in the order they are in the directory table: >> >> while ((ent = readdir(d))) { >> ... >> } >> >> Can we get the repo config files sorted like the docs say? >> > >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPW8bZ21B=rgDmwuYN4ezbTV6d3Z8FroPTWRkLJhDASyGBR7ew>