]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
change IVirtualDrive.get_node_at_path to accept either a list or a single slash-separ...
authorBrian Warner <warner@allmydata.com>
Fri, 29 Jun 2007 00:46:14 +0000 (17:46 -0700)
committerBrian Warner <warner@allmydata.com>
Fri, 29 Jun 2007 00:46:14 +0000 (17:46 -0700)
src/allmydata/interfaces.py
src/allmydata/test/test_system.py
src/allmydata/vdrive.py

index af99b727ce01a089e41811ceae9720ecf1d74447..ba4367f041ebee0ba4d7c8aa3b84e0c0a9e401a3 100644 (file)
@@ -682,11 +682,17 @@ class IVirtualDrive(Interface):
     def get_node_at_path(self, path):
         """Transform a path into an IDirectoryNode or IFileNode.
 
-        The path is a list of path-name elements, typically constructed by
-        doing userpath.split('/') . If the first element of this list is '~',
-        the rest will be interpreted relative to the local user's private
-        root directory. Otherwse it will be interpreted relative to the
-        global public root directory.
+        The path can either be a single string or a list of path-name
+        elements. The former is generated from the latter by using
+        .join('/'). If the first element of this list is '~', the rest will
+        be interpreted relative to the local user's private root directory.
+        Otherwse it will be interpreted relative to the global public root
+        directory. As a result, the following three values of 'path' are
+        equivalent::
+
+         '/dirname/foo.txt'
+         'dirname/foo.txt'
+         ['dirname', 'foo.txt']
 
         This method returns a Deferred that fires with the node in question,
         or errbacks with an IndexError if the target node could not be found.
index 4733a00ef36c31fe5b6616eed172f7e994a4bd7c..ec445271954609fe4d412a6d8c6e08f288ba3eaf 100644 (file)
@@ -313,7 +313,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
     def _do_publish_private(self, res):
         ut = upload.Data(self.data)
         vdrive0 = self.clients[0].getServiceNamed("vdrive")
-        d = vdrive0.get_node_at_path(["~"])
+        d = vdrive0.get_node_at_path("~")
         d.addCallback(self.log, "GOT ~")
         def _got_root(rootnode):
             d1 = rootnode.create_empty_directory("personal")
@@ -350,12 +350,11 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
     def _check_publish2(self, res):
         # this one uses the path-based API
         vdrive1 = self.clients[1].getServiceNamed("vdrive")
-        def get_path(path):
-            return vdrive1.get_node_at_path(path.split("/"))
+        get_path = vdrive1.get_node_at_path
         d = get_path("subdir1")
         d.addCallback(lambda dirnode:
                       self.failUnless(IDirectoryNode.providedBy(dirnode)))
-        d.addCallback(lambda res: get_path("subdir1/mydata567"))
+        d.addCallback(lambda res: get_path("/subdir1/mydata567"))
         d.addCallback(lambda filenode: filenode.download_to_data())
         d.addCallback(lambda data: self.failUnlessEqual(data, self.data))
 
@@ -371,7 +370,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
         # this one uses the path-based API
         def get_path(path):
             vdrive0 = self.clients[0].getServiceNamed("vdrive")
-            return vdrive0.get_node_at_path(path.split("/"))
+            return vdrive0.get_node_at_path(path)
         d = get_path("~/personal")
         def _got_personal(personal):
             self._personal_node = personal
index cb44d36f10327e7df668f00119afd8b2500dcc26..48c3eea45c9b902c5bbbe46c9be583b2dd22f548 100644 (file)
@@ -93,6 +93,11 @@ class VirtualDrive(service.MultiService):
 
 
     def get_node_at_path(self, path, root=None):
+        if not isinstance(path, (list, tuple)):
+            assert isinstance(path, (str, unicode))
+            if path[0] == "/":
+                path = path[1:]
+            path = path.split("/")
         assert isinstance(path, (list, tuple))
 
         if root is None: