From 3b0abff6935bcc25acfff727e594efd793bbf906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Thu, 10 Sep 2020 03:37:44 +0200 Subject: [PATCH] Handle overwrite of local files in Url class --- agetpkg | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/agetpkg b/agetpkg index 135911d..923f154 100755 --- a/agetpkg +++ b/agetpkg @@ -102,8 +102,10 @@ class Url(object): raise Error(f"Failed to get headers at {self}: {exp}") return getattr(self, "_headers") - def download(self, destination): + def download(self, destination, overwrite=True): """Download URL to destination""" + if not overwrite and exists(destination): + raise Error(f"Local file {destination} already exists") debug(f"Downloading from : {self.url}") debug(f" to : {destination}") try: @@ -154,14 +156,9 @@ class Package(Url): def get(self, sign=True, force=False): """Download the package locally""" - if not force: - if exists(self.filename): - raise Error(f"Local file {self.filename} already exists") - if sign and exists(self.sigfilename): - raise Error(f"Local file {self.sigfilename} already exists") - self.url.download(self.filename) + self.url.download(self.filename, force) if sign and self.sigurl.exists: - self.sigurl.download(self.sigfilename) + self.sigurl.download(self.sigfilename, force) class Archive(object): """Abstract access to the package Archive""" -- GitLab