@@ -511,21 +511,47 @@ void printTableForCacheStatus(Package[] packages)
511511
512512Package checkPackage (Package pkg)
513513{
514- string curlOutput = execute([
515- " curl" , " --silent" , " -H" ,
516- " Authorization: Bearer " ~ params.cachixAuthToken, " -I" ,
517- pkg.cacheUrl
518- ], false );
519- bool isAvailable = curlOutput
520- .split(" \n " )
521- .filter! (line => line.startsWith(" HTTP" ))
522- .map! (line => line.split(" " )[1 ])
523- .map! (code => code == " 200" )
524- .any;
525- pkg.isCached = isAvailable;
514+ import std.algorithm : canFind;
515+ import std.string : lineSplitter;
516+ import std.net.curl : HTTP , httpGet = get , HTTPStatusException;
517+
518+ auto http = HTTP ();
519+ http.addRequestHeader(" Authorization" , " Bearer " ~ params.cachixAuthToken);
520+
521+ try
522+ {
523+ pkg.isCached = httpGet(pkg.cacheUrl, http)
524+ .lineSplitter
525+ .canFind(" StorePath: " ~ pkg.output);
526+ }
527+ catch (HTTPStatusException e)
528+ {
529+ pkg.isCached = false ;
530+ }
531+
526532 return pkg;
527533}
528534
535+ @(" checkPackage" )
536+ unittest
537+ {
538+ const nixosCacheEndpoint = " https://cache.nixos.org/" ;
539+ const storePathHash = " mdb034kf7sq6g03ric56jxr4a7043l41" ;
540+ const storePath = " /nix/store/" ~ storePathHash ~ " -hello-2.12.1" ;
541+
542+ auto testPackage = Package(
543+ output: storePath,
544+ cacheUrl: nixosCacheEndpoint ~ storePathHash ~ " .narinfo" ,
545+ );
546+
547+ assert (! testPackage.isCached);
548+ assert (checkPackage(testPackage).isCached);
549+
550+ testPackage.cacheUrl = nixosCacheEndpoint ~ " nonexistent.narinfo" ;
551+
552+ assert (! checkPackage(testPackage).isCached);
553+ }
554+
529555Package[] getPrecalcMatrix ()
530556{
531557 auto precalcMatrixStr = params.precalcMatrix == " " ? " {\" include\" : []}" : params.precalcMatrix;
0 commit comments