From 64341690bfbe01e6efc697746e6e34c1f0d5a3da Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 5 Dec 2019 11:43:46 +0100 Subject: global-functions: $DownloadPackage: retry on error --- global-functions | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/global-functions b/global-functions index 2bff9cc..d0d91a9 100644 --- a/global-functions +++ b/global-functions @@ -215,22 +215,27 @@ :local PkgDest [ $CleanFilePath ($PkgDir . "/" . $PkgFile) ]; $CertificateAvailable "Let's Encrypt Authority X3"; - :do { - / tool fetch check-certificate=yes-without-crl \ - ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile) \ - dst-path=$PkgDest; - $WaitForFile $PkgDest; - } on-error={ - / file remove [ find where name=$PkgDest ]; - :return false; - } - :if ([ / file get [ find where name=$PkgDest ] type ] != "package") do={ + :local Retry 3; + :while ($Retry > 0) do={ + :do { + / tool fetch check-certificate=yes-without-crl \ + ("https://upgrade.mikrotik.com/routeros/" . $PkgVer . "/" . $PkgFile) \ + dst-path=$PkgDest; + $WaitForFile $PkgDest; + + :if ([ / file get [ find where name=$PkgDest ] type ] = "package") do={ + :return true; + } + } on-error={ + # catch error and fall through + } + / file remove [ find where name=$PkgDest ]; - :return false; + :set Retry ($Retry - 1); } - :return true; + :return false; } # lock script against multiple invocation -- cgit v1.2.3-54-g00ecf