From 2f3f7b330bf4f06c32bdb101fba8530d90399752 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 19 Oct 2016 22:55:55 +0100 Subject: [PATCH] dgit: ftpmaster api fetch: Check http error code (!) We are going to want to handle 404 specially so do not just use -f. Handle file:/// specially since curl just always invents 000 for the http error code in that case. Signed-off-by: Ian Jackson --- debian/changelog | 1 + dgit | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/debian/changelog b/debian/changelog index 180a3f1d..3036438d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ dgit (2.6~) unstable; urgency=medium + * Check for non-2xx HTTP status codes from ftpmaster api server. * Always honour --curl= and --curl:. -- diff --git a/dgit b/dgit index 19a0835a..ae07145c 100755 --- a/dgit +++ b/dgit @@ -989,7 +989,16 @@ sub api_query ($$) { badcfg "ftpmasterapi archive query method takes no data part" if length $data; my @cmd = archive_api_query_cmd($subpath); + my $url = $cmd[$#cmd]; + push @cmd, qw(-w %{http_code}); my $json = cmdoutput @cmd; + unless ($json =~ s/\d+\d+\d$//) { + failedcmd_report_cmd undef, @cmd; + fail "curl failed to print 3-digit HTTP code"; + } + my $code = $&; + fail "fetch of $url gave HTTP code $code" + unless $url =~ m#^file://# or $code =~ m/^2/; return decode_json($json); } -- 2.30.2