Explorar el Código

bitbake: fetch2: Avoid using FILESDIR in unpack

Currently there is code which uses FILESDIR in unpack to ensure
parent directories are created, leading to differing behaviour depending on
which search path is used to locate the directory.

This change standardises the code and takes the data from the fetcher in
question meaning we can standardise the code and deprecate FILESDIR.

(Bitbake rev: 1cccb3bd01ed82e4978acfef0fda1bd797eef72a)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Richard Purdie hace 12 años
padre
commit
6a2ce81fc6
Se han modificado 2 ficheros con 11 adiciones y 7 borrados
  1. 10 7
      bitbake/lib/bb/fetch2/__init__.py
  2. 1 0
      bitbake/lib/bb/fetch2/local.py

+ 10 - 7
bitbake/lib/bb/fetch2/__init__.py

@@ -963,15 +963,18 @@ class FetchMethod(object):
             dest = os.path.join(rootdir, os.path.basename(file))
             dest = os.path.join(rootdir, os.path.basename(file))
             if (file != dest) and not (os.path.exists(dest) and os.path.samefile(file, dest)):
             if (file != dest) and not (os.path.exists(dest) and os.path.samefile(file, dest)):
                 if os.path.isdir(file):
                 if os.path.isdir(file):
-                    filesdir = os.path.realpath(data.getVar("FILESDIR", True))
+                    # If for example we're asked to copy file://foo/bar, we need to unpack the result into foo/bar
+                    basepath = getattr(urldata, "basepath", None)
                     destdir = "."
                     destdir = "."
-                    if file[0:len(filesdir)] == filesdir:
-                        destdir = file[len(filesdir):file.rfind('/')]
+                    if basepath and basepath.endswith("/"):
+                        basepath = basepath.rstrip("/")
+                    elif basepath:
+                        basepath = os.path.dirname(basepath)
+                    if basepath and basepath.find("/") != -1:
+                        destdir = basepath[:basepath.rfind('/')]
                         destdir = destdir.strip('/')
                         destdir = destdir.strip('/')
-                        if len(destdir) < 1:
-                            destdir = "."
-                        elif not os.access("%s/%s" % (rootdir, destdir), os.F_OK):
-                            os.makedirs("%s/%s" % (rootdir, destdir))
+                    if destdir != "." and not os.access("%s/%s" % (rootdir, destdir), os.F_OK):
+                        os.makedirs("%s/%s" % (rootdir, destdir))
                     cmd = 'cp -pPR %s %s/%s/' % (file, rootdir, destdir)
                     cmd = 'cp -pPR %s %s/%s/' % (file, rootdir, destdir)
                     #cmd = 'tar -cf - -C "%d" -ps . | tar -xf - -C "%s/%s/"' % (file, rootdir, destdir)
                     #cmd = 'tar -cf - -C "%d" -ps . | tar -xf - -C "%s/%s/"' % (file, rootdir, destdir)
                 else:
                 else:

+ 1 - 0
bitbake/lib/bb/fetch2/local.py

@@ -44,6 +44,7 @@ class Local(FetchMethod):
         # We don't set localfile as for this fetcher the file is already local!
         # We don't set localfile as for this fetcher the file is already local!
         ud.decodedurl = urllib.unquote(ud.url.split("://")[1].split(";")[0])
         ud.decodedurl = urllib.unquote(ud.url.split("://")[1].split(";")[0])
         ud.basename = os.path.basename(ud.decodedurl)
         ud.basename = os.path.basename(ud.decodedurl)
+        ud.basepath = ud.decodedurl
         return
         return
 
 
     def localpath(self, url, urldata, d):
     def localpath(self, url, urldata, d):