diff mbox series

[RFC,07/15] fetch2: remove basename from FetchData

Message ID 20250205071538.2681-8-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series Make mirror replacement syntax explicit | expand

Commit Message

Stefan Herbrechtsmeier Feb. 5, 2025, 7:15 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Remove the basename variable from the FetchData class. The variable
contains the same information as the localfile variable and is mainly
used by duplicated code. Consolidate the duplicated code inside the
FetchData class.

The variable name is also misleading because it doesn’t contain the
basename of a file.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 lib/bb/fetch2/__init__.py | 14 ++++++++++----
 lib/bb/fetch2/gcp.py      |  8 --------
 lib/bb/fetch2/local.py    |  1 -
 lib/bb/fetch2/s3.py       |  7 -------
 lib/bb/fetch2/sftp.py     |  7 -------
 lib/bb/fetch2/wget.py     |  9 ---------
 6 files changed, 10 insertions(+), 36 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index f4cf25cfd..2328a8fe3 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -1304,7 +1304,6 @@  class FetchData(object):
         self.localpath = None
         self.lockfile = None
         self.mirrortarballs = []
-        self.basename = None
         (self.type, self.host, self.path, self.user, self.pswd, self.parm) = decodeurl(d.expand(url))
         self.date = self.getSRCDate(d)
         self.url = url
@@ -1360,10 +1359,17 @@  class FetchData(object):
 
         self.ignore_checksums = False
 
+        if not self.localfile and self.needdonestamp:
+            if 'downloadfilename' in self.parm:
+                self.localfile = self.parm['downloadfilename']
+            else:
+                self.localfile = os.path.basename(self.path)
+            if not os.path.basename(self.localfile):
+                self.localfile = self.host + self.path.replace("/", ".")
+
         if "localpath" in self.parm:
             # if user sets localpath for file, use it instead.
             self.localpath = self.parm["localpath"]
-            self.basename = os.path.basename(self.localpath)
         elif self.localfile:
             self.localpath = self.method.localpath(self, d)
 
@@ -1377,8 +1383,8 @@  class FetchData(object):
             basepath = self.localpath
         elif self.localpath:
             basepath = dldir + os.sep + os.path.basename(self.localpath)
-        elif self.basename:
-            basepath = dldir + os.sep + self.basename
+        elif self.localfile:
+            basepath = dldir + os.sep + self.localfile
         else:
             bb.fatal("Can't determine lock path for url %s" % url)
 
diff --git a/lib/bb/fetch2/gcp.py b/lib/bb/fetch2/gcp.py
index 86546d40b..62715f746 100644
--- a/lib/bb/fetch2/gcp.py
+++ b/lib/bb/fetch2/gcp.py
@@ -40,14 +40,6 @@  class GCP(FetchMethod):
     def recommends_checksum(self, urldata):
         return True
 
-    def urldata_init(self, ud, d):
-        if 'downloadfilename' in ud.parm:
-            ud.basename = ud.parm['downloadfilename']
-        else:
-            ud.basename = os.path.basename(ud.path)
-
-        ud.localfile = ud.basename
-
     def get_gcp_client(self):
         from google.cloud import storage
         self.gcp_client = storage.Client(project=None)
diff --git a/lib/bb/fetch2/local.py b/lib/bb/fetch2/local.py
index fda56a564..0e9357968 100644
--- a/lib/bb/fetch2/local.py
+++ b/lib/bb/fetch2/local.py
@@ -29,7 +29,6 @@  class Local(FetchMethod):
 
     def urldata_init(self, ud, d):
         # We don't set localfile as for this fetcher the file is already local!
-        ud.basename = os.path.basename(ud.path)
         ud.basepath = ud.path
         ud.needdonestamp = False
         if "*" in ud.path:
diff --git a/lib/bb/fetch2/s3.py b/lib/bb/fetch2/s3.py
index 22c053813..2cf181442 100644
--- a/lib/bb/fetch2/s3.py
+++ b/lib/bb/fetch2/s3.py
@@ -72,13 +72,6 @@  class S3(FetchMethod):
         return True
 
     def urldata_init(self, ud, d):
-        if 'downloadfilename' in ud.parm:
-            ud.basename = ud.parm['downloadfilename']
-        else:
-            ud.basename = os.path.basename(ud.path)
-
-        ud.localfile = ud.basename
-
         ud.basecmd = d.getVar("FETCHCMD_s3") or "/usr/bin/env aws s3"
 
     def download(self, ud, d):
diff --git a/lib/bb/fetch2/sftp.py b/lib/bb/fetch2/sftp.py
index bee71a0d0..2a2a70a1b 100644
--- a/lib/bb/fetch2/sftp.py
+++ b/lib/bb/fetch2/sftp.py
@@ -72,13 +72,6 @@  class SFTP(FetchMethod):
                 "git repository using ssh, you need to use the " +
                 "git:// prefix with protocol=ssh", ud.url)
 
-        if 'downloadfilename' in ud.parm:
-            ud.basename = ud.parm['downloadfilename']
-        else:
-            ud.basename = os.path.basename(ud.path)
-
-        ud.localfile = ud.basename
-
     def download(self, ud, d):
         """Fetch urls"""
 
diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 6cb728ab4..161c66bea 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -73,15 +73,6 @@  class Wget(FetchMethod):
             if ud.parm['protocol'] == 'git':
                 raise bb.fetch2.ParameterError("Invalid protocol - if you wish to fetch from a git repository using http, you need to instead use the git:// prefix with protocol=http", ud.url)
 
-        if 'downloadfilename' in ud.parm:
-            ud.basename = ud.parm['downloadfilename']
-        else:
-            ud.basename = os.path.basename(ud.path)
-
-        ud.localfile = ud.basename
-        if not ud.localfile:
-            ud.localfile = ud.host + ud.path.replace("/", ".")
-
         self.basecmd = d.getVar("FETCHCMD_wget") or "/usr/bin/env wget -t 2 -T 100"
 
         if ud.type == 'ftp' or ud.type == 'ftps':