Repository Search Order

Matthew Seaman matthew at FreeBSD.org
Sat Sep 13 10:12:38 UTC 2014


Can you open an issue on github concerning this please?
https://github.com/freebsd/pkg/issues

Bonus points if you can generate a pull request.

On 13/09/2014 05:09, Dan Lists wrote:
> 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);

I think asprintf() would be a better choice here.

> +          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
> 

While changing the order that the repo configuration files load seems to
be a useful approach, I think that it works, if at all, by chance.  It
will be fragile in the sense that an unrelated change elsewhere in
dependency solving could easily destroy any effect from the order that
config files are processed.

Repository data is downloaded and processed into a number of sqlite
databases each named after the tag in the repo.conf -- it strikes me
that imposing some preference ordering based on the repository tag at
the point that data about available packages is pulled out of the repo
databases would be a more robust approach.

	Cheers,

	Matthew


-- 
Dr Matthew J Seaman MA, D.Phil.
PGP: http://www.infracaninophile.co.uk/pgpkey


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 971 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20140913/e65ee7a0/attachment.sig>


More information about the freebsd-questions mailing list