[MERGE] Bug in MemoryTransport.rmdir

Andrew Bennetts andrew at canonical.com
Tue Mar 13 05:41:14 GMT 2007


I bumped into a bug while working on the smart server tests:
MemoryTransport.rmdir('.bzr/branch') fails if there's a '.bzr/branch-format'
file (even when the directory is empty, as is the case during a move call).

This bundle fixes that bug and adds a transport_implementations test.

-Andrew.

-------------- next part --------------
# Bazaar revision bundle v0.9
#
# message:
#   Fix bug in MemoryTransport.rmdir.
# committer: Andrew Bennetts <andrew.bennetts at canonical.com>
# date: Tue 2007-03-13 16:27:12.851000071 +1100

=== modified file bzrlib/tests/test_transport_implementations.py
--- bzrlib/tests/test_transport_implementations.py
+++ bzrlib/tests/test_transport_implementations.py
@@ -759,6 +759,24 @@
         t.mkdir('adir/bdir')
         self.assertRaises(PathError, t.rmdir, 'adir')
 
+    def test_rmdir_empty_but_similar_prefix(self):
+        """rmdir does not get confused by sibling paths.
+        
+        A naive implementation of MemoryTransport would refuse to rmdir
+        ".bzr/branch" if there is a ".bzr/branch-format" directory, because it
+        uses "path.startswith(dir)" on all file paths to determine if directory
+        is empty.
+        """
+        t = self.get_transport()
+        if t.is_readonly():
+            return
+        t.mkdir('foo')
+        t.put_bytes('foo-bar', '')
+        t.mkdir('foo-baz')
+        t.rmdir('foo')
+        self.assertRaises((NoSuchFile, PathError), t.rmdir, 'foo')
+        self.failUnless(t.has('foo-bar'))
+
     def test_rename_dir_succeeds(self):
         t = self.get_transport()
         if t.is_readonly():

=== modified file bzrlib/transport/memory.py
--- bzrlib/transport/memory.py
+++ bzrlib/transport/memory.py
@@ -192,11 +192,11 @@
         if _abspath in self._files:
             self._translate_error(IOError(errno.ENOTDIR, relpath), relpath)
         for path in self._files:
-            if path.startswith(_abspath):
+            if path.startswith(_abspath + '/'):
                 self._translate_error(IOError(errno.ENOTEMPTY, relpath),
                                       relpath)
         for path in self._dirs:
-            if path.startswith(_abspath) and path != _abspath:
+            if path.startswith(_abspath + '/') and path != _abspath:
                 self._translate_error(IOError(errno.ENOTEMPTY, relpath), relpath)
         if not _abspath in self._dirs:
             raise NoSuchFile(relpath)

=== modified directory  // last-changed:andrew.bennetts at canonical.com-200703130
... 52712-fjpwxnglz6nlmehu
# revision id: andrew.bennetts at canonical.com-20070313052712-fjpwxnglz6nlmehu
# sha1: ca72e557f4bf4aa66be74dc9245a7488988a3931
# inventory sha1: bfcad47687ed83599f3b712226fc97b692d8c119
# parent ids:
#   pqm at pqm.ubuntu.com-20070311211206-0fd0176ac1e77ef7
# base id: pqm at pqm.ubuntu.com-20070311211206-0fd0176ac1e77ef7
# properties:
#   branch-nick: memory-transport-rmdir



More information about the bazaar mailing list