From c9e07e536f19820c4bba1f11e2edcb23069874d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20M=C3=BCller?= Date: Thu, 7 Dec 2023 18:30:36 +0100 Subject: [PATCH] Try to fetch the element as deleted if initial access failed The reference to the object might be already deleted by when the request is failing. plus setting deleted=0 is rejected by the API. So try with deleted=1 if and only if the previous access failed. --- lib/obs.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/obs.py b/lib/obs.py index 3d149ae..6f00e5b 100644 --- a/lib/obs.py +++ b/lib/obs.py @@ -148,12 +148,28 @@ class OBS: ] def _download(self, project, package, name, revision): + # the object might be deleted but we can only pass deleted=1 + # if it is actually deleted + deleted = 0 + while deleted < 2: + url = osc.core.makeurl( + self.url, + ["source", project, package, urllib.parse.quote(name)], + {"rev": revision, "expand": 1, "deleted": deleted if deleted else ()}, + ) + try: + osc.core.http_request("HEAD", url) + break + except Exception: + pass + deleted += 1 + url = osc.core.makeurl( - self.url, - ["source", project, package, urllib.parse.quote(name)], - {"rev": revision, "expand": 1}, - ) - return osc.core.http_GET(url) + self.url, + ["source", project, package, urllib.parse.quote(name)], + {"rev": revision, "expand": 1, "deleted": 1 if deleted else ()}, + ) + return osc.core.http_request("GET", url) def download( self,