Rev 3008: Rename on Windows is able to change filename case. (#77740) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Nov 20 17:46:33 GMT 2007


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

------------------------------------------------------------
revno: 3008
revision-id: pqm at pqm.ubuntu.com-20071120174630-11911fovhobm06cp
parent: pqm at pqm.ubuntu.com-20071119235416-b8dvkk17vngbf99s
parent: bialix at ukr.net-20071119225430-x0ewosrsagis0yno
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-11-20 17:46:30 +0000
message:
  Rename on Windows is able to change filename case. (#77740)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/blackbox/test_mv.py test_mv.py-20060705114902-33tkxz0o9cdshemo-1
  bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 2978.8.5
    merged: bialix at ukr.net-20071119225430-x0ewosrsagis0yno
    parent: bialix at ukr.net-20071119225114-9ixbx1dkgu3mx5s3
    parent: pqm at pqm.ubuntu.com-20071117180742-59zhz30s7839y41j
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: mv.change.case
    timestamp: Tue 2007-11-20 00:54:30 +0200
    message:
      merge bzr.dev
    ------------------------------------------------------------
    revno: 2978.8.4
    merged: bialix at ukr.net-20071119225114-9ixbx1dkgu3mx5s3
    parent: bialix at ukr.net-20071113174015-tkjuep3zakscvxb2
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: mv.change.case
    timestamp: Tue 2007-11-20 00:51:14 +0200
    message:
      fancy_rename: lower() test removed.
    ------------------------------------------------------------
    revno: 2978.8.3
    merged: bialix at ukr.net-20071113174015-tkjuep3zakscvxb2
    parent: bialix at ukr.net-20071112213515-oteyfud32v1yzgrl
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: mv.change.case
    timestamp: Tue 2007-11-13 19:40:15 +0200
    message:
      Aaron's review
    ------------------------------------------------------------
    revno: 2978.8.2
    merged: bialix at ukr.net-20071112213515-oteyfud32v1yzgrl
    parent: bialix at ukr.net-20071110131612-4s55g3rodrp41uwh
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: mv.change.case
    timestamp: Mon 2007-11-12 23:35:15 +0200
    message:
      teach fancy_rename to handle change case renames in possible case-insensitive filesystem
    ------------------------------------------------------------
    revno: 2978.8.1
    merged: bialix at ukr.net-20071110131612-4s55g3rodrp41uwh
    parent: pqm at pqm.ubuntu.com-20071109195036-5o5bwu0a01uniqwg
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: mv.change.case
    timestamp: Sat 2007-11-10 15:16:12 +0200
    message:
      Rename on Windows is able to change filename case. (#77740)
=== modified file 'NEWS'
--- a/NEWS	2007-11-17 18:07:42 +0000
+++ b/NEWS	2007-11-19 22:54:30 +0000
@@ -82,6 +82,9 @@
    * Removing an already-removed file reports the file does not exist. (Daniel
      Watkins, #152811)
 
+   * Rename on Windows is able to change filename case.
+     (Alexander Belchenko, #77740)
+
    * Stderr output via logging mechanism now goes through encoded wrapper
      and no more uses utf-8, but terminal encoding instead. So all unicode
      strings now should be readable in non-utf-8 terminal.

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2007-11-04 11:45:30 +0000
+++ b/bzrlib/osutils.py	2007-11-19 22:51:14 +0000
@@ -234,10 +234,17 @@
 
     success = False
     try:
-        # This may throw an exception, in which case success will
-        # not be set.
-        rename_func(old, new)
-        success = True
+        try:
+            # This may throw an exception, in which case success will
+            # not be set.
+            rename_func(old, new)
+            success = True
+        except (IOError, OSError), e:
+            # source and target may be aliases of each other (e.g. on a
+            # case-insensitive filesystem), so we may have accidentally renamed
+            # source by when we tried to rename target
+            if not (file_existed and e.errno in (None, errno.ENOENT)):
+                raise
     finally:
         if file_existed:
             # If the file used to exist, rename it back into place

=== modified file 'bzrlib/tests/blackbox/test_mv.py'
--- a/bzrlib/tests/blackbox/test_mv.py	2007-11-06 04:33:38 +0000
+++ b/bzrlib/tests/blackbox/test_mv.py	2007-11-19 22:54:30 +0000
@@ -124,6 +124,19 @@
         os.chdir('..')
         self.assertMoved('sub1/sub2/hello.txt','sub1/hello.txt')
 
+    def test_mv_change_case(self):
+        # test for bug #77740 (mv unable change filename case on Windows)
+        tree = self.make_branch_and_tree('.')
+        self.build_tree(['test.txt'])
+        tree.add(['test.txt'])
+        self.run_bzr('mv test.txt Test.txt')
+        # we can't use failUnlessExists on case-insensitive filesystem
+        # so try to check shape of the tree
+        shape = sorted(os.listdir(u'.'))
+        self.assertEqual(['.bzr', 'Test.txt'], shape)
+        self.assertInWorkingTree('Test.txt')
+        self.assertNotInWorkingTree('test.txt')
+
     def test_mv_smoke_aliases(self):
         # just test that aliases for mv exist, if their behaviour is changed in
         # the future, then extend the tests.

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2007-11-03 09:39:11 +0000
+++ b/bzrlib/tests/test_osutils.py	2007-11-12 21:35:15 +0000
@@ -93,6 +93,16 @@
 
     # TODO: test fancy_rename using a MemoryTransport
 
+    def test_rename_change_case(self):
+        # on Windows we should be able to change filename case by rename
+        self.build_tree(['a', 'b/'])
+        osutils.rename('a', 'A')
+        osutils.rename('b', 'B')
+        # we can't use failUnlessExists on case-insensitive filesystem
+        # so try to check shape of the tree
+        shape = sorted(os.listdir('.'))
+        self.assertEquals(['A', 'B'], shape)
+
     def test_01_rand_chars_empty(self):
         result = osutils.rand_chars(0)
         self.assertEqual(result, '')

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-11-14 10:53:53 +0000
+++ b/bzrlib/workingtree.py	2007-11-19 22:54:30 +0000
@@ -1318,6 +1318,10 @@
                 only_change_inv = True
             elif self.has_filename(from_rel) and not self.has_filename(to_rel):
                 only_change_inv = False
+            elif (sys.platform == 'win32'
+                and from_rel.lower() == to_rel.lower()
+                and self.has_filename(from_rel)):
+                only_change_inv = False
             else:
                 # something is wrong, so lets determine what exactly
                 if not self.has_filename(from_rel) and \




More information about the bazaar-commits mailing list