ustclug / mirrorhelp

Documentation for USTC Mirrors
https://mirrors.ustc.edu.cn/help/
Other
509 stars 147 forks source link

freebsd-pkg: add mirror_type: "none" #264

Closed CismonX closed 1 month ago

CismonX commented 2 months ago

Since currently there is no SRV record on either _http._tcp.mirrors.ustc.edu.cn or _https._tcp.mirrors.ustc.edu.cn, the mirror_type field in /etc/pkg/FreeBSD.conf should be overridden to none, otherwise pkg(8) may produce warnings like:

pkg: No SRV record found for the repo 'FreeBSD'

See also: pkg.conf(5), #90665, #90716

taoky commented 2 months ago

In pkg.conf(5), it says:

        MIRROR_TYPE: string  MIRROR_TYPE  for  this  repository  only.
                     Default:  NONE.   Any  of  HTTP or SRV or
                     NONE.

And:

       For a MIRROR_TYPE of NONE, any of the following URL  schemes:  http://,
       https://,  file://,  ssh://,  tcp://.   Where  MIRROR_TYPE  is SRV, you
       should use a pkg+http:// or pkg+https:// (etc.) URL scheme.   Using  an
       http:// URL implies that the hostname part is a simple hostname accord-
       ing to RFC 2616, and is no longer accepted.

I'm curious that if it's really necessary to explicitly declare mirror_type as none.

CismonX commented 1 month ago

In pkg.conf(5):

Repository configuration files are searched for in order of the directories listed in the REPOS_DIR array, which defaults to /etc/pkg/ and /usr/local/etc/pkg/repos/.

Also:

Reusing the repository tag will cause those items defined in configuration files later on the REPOS_DIR search path to overwrite the equivalent settings for the same tag earlier on the search path.

Since the default configuration in /etc/pkg/FreeBSD.conf already declares mirror_type as srv, that value will be used by pkg(8) unless explicitly overridden.

In freebsd/pkg/libpkg/fetch_libcurl.c:

// ...
if (repo->mirror_type == SRV && repo->srv == NULL) {
    int urloff = 0;
    cr->url = curl_url();
    if (strncasecmp(repo->url, "pkg+", 4) == 0)
        urloff = 4;
    CURLUcode c = curl_url_set(cr->url, CURLUPART_URL, repo->url + urloff, 0);
    if (c) {
        pkg_emit_error("impossible to parse url: '%s'", repo->url);
        return (EPKG_FATAL);
    }

    char *zone;
    char *host = NULL, *scheme = NULL;
    curl_url_get(cr->url, CURLUPART_HOST, &host, 0);
    curl_url_get(cr->url, CURLUPART_SCHEME, &scheme, 0);
    xasprintf(&zone, "_%s._tcp.%s", scheme, host);
    repo->srv = dns_getsrvinfo(zone);
    free(zone);
    free(host);
    free(scheme);
    if (repo->srv == NULL) {
        pkg_emit_error("No SRV record found for the "
            "repo '%s'", repo->name);
        repo->mirror_type = NOMIRROR;
    }
}
// ...

When mirror_type is srv, pkg(8) attempts to resolve the SRV record even if the URL is not prefixed with pkg+, leading to the aforementioned warning message.

This behavior is introduced in commit #f06399ce03, and continues to exist in all releases since 1.20.0. That explains why users never encountered this problem until recently...