Rev 3064: TreeTransform.apply gives better errors when OSErrors occur (Belchenko) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sun Dec 2 13:49:45 GMT 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3064
revision-id:pqm at pqm.ubuntu.com-20071202134939-jvspioo8sh18aok3
parent: pqm at pqm.ubuntu.com-20071201001053-zi6k6s2817c1p97s
parent: aaron.bentley at utoronto.ca-20071202022902-zbcg5bf5t6aivn5v
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2007-12-02 13:49:39 +0000
message:
  TreeTransform.apply gives better errors when OSErrors occur (Belchenko)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
  bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
    ------------------------------------------------------------
    revno: 3063.1.3
    revision-id:aaron.bentley at utoronto.ca-20071202022902-zbcg5bf5t6aivn5v
    parent: bialix at ukr.net-20071202005121-ojfk3u9free2h2en
    parent: argentina at gmail.com-20071121033507-zrd00inp8fbazoln
    committer: Aaron Bentley <aaron.bentley at utoronto.ca>
    branch nick: bzr.ab.integration
    timestamp: Sat 2007-12-01 21:29:02 -0500
    message:
      Update for Linux
    modified:
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
    ------------------------------------------------------------
    revno: 3063.1.2
    revision-id:bialix at ukr.net-20071202005121-ojfk3u9free2h2en
    parent: bialix at ukr.net-20071201215946-cv7sc7jdv2czuisf
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bugfix.111758
    timestamp: Sun 2007-12-02 02:51:21 +0200
    message:
      test for two directories clash
    modified:
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
    ------------------------------------------------------------
    revno: 3063.1.1
    revision-id:bialix at ukr.net-20071201215946-cv7sc7jdv2czuisf
    parent: pqm at pqm.ubuntu.com-20071201001053-zi6k6s2817c1p97s
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: bugfix.111758
    timestamp: Sat 2007-12-01 23:59:46 +0200
    message:
      Catch OSError 17 (file exists) in final phase of tree transform and show filename to user (#111758).
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
=== modified file 'NEWS'
--- a/NEWS	2007-11-30 22:43:21 +0000
+++ b/NEWS	2007-12-01 21:59:46 +0000
@@ -14,6 +14,10 @@
 
   BUGFIXES:
 
+   * Catch OSError 17 (file exists) in final phase of tree transform and show
+     filename to user.
+     (Alexander Belchenko, #111758)
+
    * Catch ShortReadvErrors while using pycurl. Also make readv more robust by
      allowing multiple GET requests to be issued if too many ranges are
      required.

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-11-29 07:12:42 +0000
+++ b/bzrlib/tests/__init__.py	2007-12-01 21:59:46 +0000
@@ -2771,3 +2771,29 @@
         return 'FTPServer'
 
 FTPServerFeature = _FTPServerFeature()
+
+
+class _CaseInsensitiveFilesystemFeature(Feature):
+    """Check if underlined filesystem is case-insensitive
+    (e.g. on Windows, Cygwin, MacOS)
+    """
+
+    def _probe(self):
+        if TestCaseWithMemoryTransport.TEST_ROOT is None:
+            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
+            TestCaseWithMemoryTransport.TEST_ROOT = root
+        else:
+            root = TestCaseWithMemoryTransport.TEST_ROOT
+        tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
+            dir=root)
+        name_a = osutils.pathjoin(tdir, 'a')
+        name_A = osutils.pathjoin(tdir, 'A')
+        os.mkdir(name_a)
+        result = osutils.isdir(name_A)
+        _rmtree_temp_dir(tdir)
+        return result
+
+    def feature_name(self):
+        return 'case-insensitive filesystem'
+
+CaseInsensitiveFilesystemFeature = _CaseInsensitiveFilesystemFeature()

=== modified file 'bzrlib/tests/test_transform.py'
--- a/bzrlib/tests/test_transform.py	2007-11-28 23:08:40 +0000
+++ b/bzrlib/tests/test_transform.py	2007-12-02 02:29:02 +0000
@@ -36,6 +36,7 @@
 from bzrlib.osutils import file_kind, pathjoin
 from bzrlib.merge import Merge3Merger
 from bzrlib.tests import (
+    CaseInsensitiveFilesystemFeature,
     SymlinkFeature,
     TestCase,
     TestCaseInTempDir,
@@ -1088,8 +1089,44 @@
         self.callDeprecated([txt], change_entry, None, None, None, None, None,
             None, None, None)
 
+    def test_case_insensitive_clash(self):
+        self.requireFeature(CaseInsensitiveFilesystemFeature)
+        def tt_helper():
+            wt = self.make_branch_and_tree('.')
+            tt = TreeTransform(wt)  # TreeTransform obtains write lock
+            try:
+                tt.new_file('foo', tt.root, 'bar')
+                tt.new_file('Foo', tt.root, 'spam')
+                # Lie to tt that we've already resolved all conflicts.
+                tt.apply(no_conflicts=True)
+            except:
+                wt.unlock()
+                raise
+        err = self.assertRaises(errors.FileExists, tt_helper)
+        self.assertContainsRe(str(err),
+            "^File exists: .+/foo")
+
+    def test_two_directories_clash(self):
+        def tt_helper():
+            wt = self.make_branch_and_tree('.')
+            tt = TreeTransform(wt)  # TreeTransform obtains write lock
+            try:
+                foo_1 = tt.new_directory('foo', tt.root)
+                tt.new_directory('bar', foo_1)
+                foo_2 = tt.new_directory('foo', tt.root)
+                tt.new_directory('baz', foo_2)
+                # Lie to tt that we've already resolved all conflicts.
+                tt.apply(no_conflicts=True)
+            except:
+                wt.unlock()
+                raise
+        err = self.assertRaises(errors.FileExists, tt_helper)
+        self.assertContainsRe(str(err),
+            "^File exists: .+/foo")
+
 
 class TransformGroup(object):
+
     def __init__(self, dirname, root_id):
         self.name = dirname
         os.mkdir(dirname)
@@ -1462,6 +1499,7 @@
         object.__init__(self)
         self.name = "name"
 
+
 class TestGetBackupName(TestCase):
     def test_get_backup_name(self):
         tt = MockTransform()
@@ -1521,7 +1559,7 @@
         mover.rename('c/e', 'c/d')
         try:
             mover.rename('a', 'c')
-        except OSError, e:
+        except errors.FileExists, e:
             mover.rollback()
         self.failUnlessExists('a')
         self.failUnlessExists('c/d')

=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py	2007-11-27 13:24:44 +0000
+++ b/bzrlib/transform.py	2007-12-02 02:29:02 +0000
@@ -1878,7 +1878,12 @@
 
     def rename(self, from_, to):
         """Rename a file from one path to another.  Functions like os.rename"""
-        os.rename(from_, to)
+        try:
+            os.rename(from_, to)
+        except OSError, e:
+            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
+                raise errors.FileExists(to, str(e))
+            raise
         self.past_renames.append((from_, to))
 
     def pre_delete(self, from_, to):




More information about the bazaar-commits mailing list