@hsitter
Copy link
Contributor

hsitter commented May 15, 2018

Downloading from debian repos without Packages.xz file fails silently because the status line isn't checked (i.e. the current code ignores 404 or any other fatal code entirely)

debpkgindex.d calls downloadIfNecessary for remote roots. downloadIfNecessary iters xz,gz,bz2 to find a suitable Package.* file, it calls utils.d's downloadFile which in turn simply wraps download which is where the trouble is.

download calls HTTP.perform from std.net.curl, perform however seems to not care about the status code. From the documentation, and a casual look at curl.d, I'd say that when using perform one needs to set callback handlers for everything manually. e.g. https://github.com/dlang/phobos/blob/master/std/net/curl.d#L1075 is where .get and friends get their exception thrown, perform has no such convenience magic, and the docs for .get explicitly state that a statusexception may be raised.

Some printfdebugging seems to support that theory. Setting a status line callback in download

            downloader.onReceiveStatusLine = (HTTP.StatusLine status) { logDebug ("status %s", status); };

it definitely gets code 404 but ignores it.

2018-05-15 08:29:44 - DEBUG: Downloading https://origin.archive.neon.kde.org/dev/unstable/dists/xenial/main/binary-amd64/Packages.xz
2018-05-15 08:29:44 - DEBUG: status 404 Not Found (1.1)
2018-05-15 08:29:44 - DEBUG: Downloaded https://origin.archive.neon.kde.org/dev/unstable/dists/xenial/main/binary-amd64/Packages.xz

To that end I think all that's needed to fix this is to enforce the status code, as seen in curl.d's _basicHTTP.

Config I am using:

{
"ArchiveRoot": "https://origin.archive.neon.kde.org/dev/unstable/",
"MediaBaseUrl": "https://metadata.neon.kde.org/appstream/dev/unstable/media",
"HtmlBaseUrl": "https://metadata.neon.kde.org/appstream/dev/unstable/html",
"Backend": "debian",
"Features":
  {
    "validateMetainfo": true
  },
"Suites":
  {
    "xenial":
      {
        "sections": ["main"],
        "architectures": ["amd64"],
        "useIconTheme": "breeze",
        "dataPriority": 1
      }
  }
}