summaryrefslogtreecommitdiff
path: root/dgit
diff options
context:
space:
mode:
Diffstat (limited to 'dgit')
-rwxr-xr-xdgit24
1 files changed, 13 insertions, 11 deletions
diff --git a/dgit b/dgit
index 5bd648a..48be198 100755
--- a/dgit
+++ b/dgit
@@ -1192,10 +1192,9 @@ sub cfg_apply_map ($$$) {
$$varref = $_;
}
-#---------- `ftpmasterapi' archive query method (nascent) ----------
-
-sub archive_api_query_curl ($) {
- my ($url) = @_;
+sub url_fetch ($;@) {
+ my ($url, %xopts) = @_;
+ # Ok404 => 1 means give undef for 404
use WWW::Curl::Easy;
@@ -1220,7 +1219,7 @@ sub archive_api_query_curl ($) {
}
}
- printdebug "archive api query: fetching $url...\n";
+ printdebug "query: fetching $url...\n";
local $SIG{PIPE} = 'IGNORE';
@@ -1229,18 +1228,21 @@ sub archive_api_query_curl ($) {
$url, $curl->strerror($x), $curl->errbuf
if $x;
- return $curl->getinfo(CURLINFO_HTTP_CODE), $response_body;
+ my $code = $curl->getinfo(CURLINFO_HTTP_CODE);
+ if ($code eq '404' && $xopts{Ok404}) { return undef; }
+
+ fail f_ "fetch of %s gave HTTP code %s", $url, $code
+ unless $url =~ m#^file://# or $code =~ m/^2/;
+ return $response_body;
}
+#---------- `ftpmasterapi' archive query method (nascent) ----------
+
sub api_query_raw ($;$) {
my ($subpath, $ok404) = @_;
my $url = access_cfg('archive-query-url');
$url .= $subpath;
- my ($code,$json) = archive_api_query_curl($url);
- return undef if $code eq '404' && $ok404;
- fail f_ "fetch of %s gave HTTP code %s", $url, $code
- unless $url =~ m#^file://# or $code =~ m/^2/;
- return $json;
+ return url_fetch $url, Ok404 => $ok404;
}
sub api_query ($$;$) {