From 0005c23b3862a480e135c3361738e20f07b1a4c5 Mon Sep 17 00:00:00 2001 From: Ian Walton Date: Tue, 3 Sep 2019 14:28:35 -0400 Subject: [PATCH] feat: Handle nonexistent binary. This patches the version component to return a version of 0.0.0 if it fails to detect a version. This allows the update script to install the binary if it does not already exist or is corrupted. --- gitea_auto_update/lib/version.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gitea_auto_update/lib/version.py b/gitea_auto_update/lib/version.py index 8f2c8a5..6c8e60b 100644 --- a/gitea_auto_update/lib/version.py +++ b/gitea_auto_update/lib/version.py @@ -35,9 +35,13 @@ class Version: currentVersion = self.getVersionFromFile() except: # Get the version via the web api if the file does fail - currentVersion = requests.get(self.gtSite).json()['version'] - if currentVersion.status_code != 200: - currentVersion = self.getVersionFromFile() + try: + currentVersion = requests.get(self.gtSite).json()['version'] + if currentVersion.status_code != 200: + raise RuntimeError("Could not download version.") + except: + # To allow installation, return a default version of "0.0.0". + currentVersion = "0.0.0" finally: logging.info('Version: current_version = %s', currentVersion) return currentVersion @@ -45,4 +49,4 @@ class Version: def getGithubVersionTag(self, apiUrl): versionTag = requests.get(apiUrl).json()['tag_name'] logging.info('Version: github_version_tag = %s', versionTag) - return versionTag \ No newline at end of file + return versionTag