From c74f244febe14aa982a7c7860cb8e3c524b947c1 Mon Sep 17 00:00:00 2001 From: Steven Leung Date: Mon, 14 May 2018 13:52:00 -0700 Subject: [PATCH] Account for failed fetches with body in HTTP req Eg. a 404 that may contain a message in JSON - LWP::UserAgent will not replace the local file if it is newer than a successful dist archive --- Menlo-Legacy/lib/Menlo/CLI/Compat.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Menlo-Legacy/lib/Menlo/CLI/Compat.pm b/Menlo-Legacy/lib/Menlo/CLI/Compat.pm index 6d157f2ef..e5ea01101 100644 --- a/Menlo-Legacy/lib/Menlo/CLI/Compat.pm +++ b/Menlo-Legacy/lib/Menlo/CLI/Compat.pm @@ -1427,8 +1427,11 @@ sub fetch_module { my $file; eval { local $SIG{INT} = sub { $cancelled = 1; die "SIGINT\n" }; - $self->mirror($uri, $name); - $file = $name if -e $name; + if ($self->mirror($uri, $name)->{success} && -e $name) { + $file = $name; + } else { + unlink $name; + } }; $self->diag("ERROR: " . trim("$@") . "\n", 1) if $@ && $@ ne "SIGINT\n"; return $file;