From owner-freebsd-questions@FreeBSD.ORG Sat Sep 13 04:09:44 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B958D686 for ; Sat, 13 Sep 2014 04:09:44 +0000 (UTC) Received: from mail-qa0-x22a.google.com (mail-qa0-x22a.google.com [IPv6:2607:f8b0:400d:c00::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 778D9345 for ; Sat, 13 Sep 2014 04:09:44 +0000 (UTC) Received: by mail-qa0-f42.google.com with SMTP id j7so1751502qaq.15 for ; Fri, 12 Sep 2014 21:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=rAsX6sIWxO2RdsZ7kqTzdAJdmtcOEJKUfJkp21cOT/s=; b=moVbiTbnwxuaO9qpjmiOM06RHFA3aZYXqrQkZs6e/CtWnnsQljrKSj5wpoNYmQyJR1 LDgXIjzgeQbaw1KLsLF630QoL6FKDcfFxAudVs5LVtLskfzz2m7u0i7lOgSolxOju1xe vVnQt1dgnSoR/ueVEwBDsU2RbglXnwOmi50tyn03J3wH/AFBWHYFMj1r/di67ASB6Dcp mnC6Qji1puso7I+f2BDuuBsHM5yqlGJDxk7e39a08bVHCUT70nhUu8WGMVP7QA+brFvv KEYz3HdrMkqvhrwmuh0xrwmnOZrR8KPvyxmYrQZdrLtP8aLIFYKJT/MsTZqsx01tpDE1 FUug== MIME-Version: 1.0 X-Received: by 10.224.104.1 with SMTP id m1mr18744648qao.81.1410581383532; Fri, 12 Sep 2014 21:09:43 -0700 (PDT) Received: by 10.224.10.198 with HTTP; Fri, 12 Sep 2014 21:09:43 -0700 (PDT) In-Reply-To: References: Date: Fri, 12 Sep 2014 23:09:43 -0500 Message-ID: Subject: Re: Repository Search Order From: Dan Lists To: freebsd-questions Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Sep 2014 04:09:44 -0000 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 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 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? >> > >