diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index a680783c4..de1ab0782 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -1269,7 +1269,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
@@ -1325,10 +1324,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)
 
@@ -1342,8 +1348,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':
