Skip to contentSkip to conversation

fetch2/__init__.py: Extend subdir unpack parameter to local folder

PATCH New Ming Liu 1 participant 2 messages Nov 13, 2015

lore
Share & tools
lore

Ming Liu

author
#0 lore raw

PATCH 1/2 fetch2/__init__.py: Extend subdir unpack parameter to local folder

From: Ming Liu <[email protected]>

This fixes urls of the form file://some/path/file;subdir=b. When the file is a folder.

Also tweaks the way to get subdir parameter, storing it into a variable instead of calling urldata.parm.get() multiple times.

---
 lib/bb/fetch2/__init__.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/bb/fetch2/__init__.py +7 -4
index 288a1c8..d7439fa 100644
@@ -1412,6 +1412,7 @@ class FetchMethod(object):
             # If file == dest, then avoid any copies, as we already put the file into dest!
             dest = os.path.join(rootdir, os.path.basename(file))
             if (file != dest) and not (os.path.exists(dest) and os.path.samefile(file, dest)):
+                subdir = urldata.parm.get('subdir')
                 if os.path.isdir(file):
                     # 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)
@@ -1423,6 +1424,8 @@ class FetchMethod(object):
                     if basepath and basepath.find("/") != -1:
                         destdir = basepath[:basepath.rfind('/')]
                         destdir = destdir.strip('/')
+                    if subdir:
+                        destdir = subdir + "/" + destdir
                     if destdir != "." and not os.access("%s/%s" % (rootdir, destdir), os.F_OK):
                         os.makedirs("%s/%s" % (rootdir, destdir))
                     cmd = 'cp -fpPR %s %s/%s/' % (file, rootdir, destdir)
@@ -1432,11 +1435,11 @@ class FetchMethod(object):
                     # items.  So, only do so for file:// entries.
                     if urldata.type == "file" and urldata.path.find("/") != -1:
                        destdir = urldata.path.rsplit("/", 1)[0]
-                       if urldata.parm.get('subdir') != None:
-                          destdir = urldata.parm.get('subdir') + "/" + destdir
+                       if subdir:
+                          destdir = subdir + "/" + destdir
                     else:
-                       if urldata.parm.get('subdir') != None:
-                          destdir = urldata.parm.get('subdir')
+                       if subdir:
+                          destdir = subdir
                        else:
                           destdir = "."
                     bb.utils.mkdirhier("%s/%s" % (rootdir, destdir))
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 2/2 tests/fetch.py: adds test_local_dir_subdirparam test case

From: Ming Liu <[email protected]>

Also renames test_local_subdirparam to test_local_file_subdirparam to distinguish with test_local_dir_subdirparam.

---
 lib/bb/tests/fetch.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/bb/tests/fetch.py +5 -1
index 94173c1..435cd91 100644
@@ -469,10 +469,14 @@ class FetcherLocalTest(FetcherTest):
         tree = self.fetchUnpack(['file://dir/subdir/e'])
         self.assertEqual(tree, ['dir/subdir/e'])
 
-    def test_local_subdirparam(self):
+    def test_local_file_subdirparam(self):
         tree = self.fetchUnpack(['file://a;subdir=bar'])
         self.assertEqual(tree, ['bar/a'])
 
+    def test_local_dir_subdirparam(self):
+        tree = self.fetchUnpack(['file://dir;subdir=bar'])
+        self.assertEqual(tree, ['bar/dir/c', 'bar/dir/d', 'bar/dir/subdir/e'])
+
     def test_local_deepsubdirparam(self):
         tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])
         self.assertEqual(tree, ['bar/dir/subdir/e'])
Signature · 1 line
1.9.1