Rev 2833: Review feedback. in file:///v/home/vila/src/cleanup/commit.builder/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Sep 20 10:30:41 BST 2007


At file:///v/home/vila/src/cleanup/commit.builder/

------------------------------------------------------------
revno: 2833
revision-id: v.ladeuil+lp at free.fr-20070920093039-xnjzgav92o44ient
parent: v.ladeuil+lp at free.fr-20070919013514-1gagtna1cfzbeedv
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: commit.builder
timestamp: Thu 2007-09-20 11:30:39 +0200
message:
  Review feedback.
  
  * bzrlib/tests/repository_implementations/test_commit_builder.py:
  (TestCommitBuilder._check_kind_change.change_kind): Use
  osutils.delete_any.
  
  * bzrlib/osutils.py:
  (delete_any): Rewritten for portability.
modified:
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/tests/repository_implementations/test_commit_builder.py test_commit_builder.py-20060606110838-76e3ra5slucqus81-1
-------------- next part --------------
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2007-09-17 22:13:29 +0000
+++ b/bzrlib/osutils.py	2007-09-20 09:30:39 +0000
@@ -786,15 +786,18 @@
             raise
         shutil.copyfile(src, dest)
 
-def delete_any(full_path):
+
+# Look Before You Leap (LBYL) is appropriate here instead of Easier to Ask for
+# Forgiveness than Permission (EAFP) because:
+# - root can damage a solaris file system by using unlink,
+# - unlink raises different exceptions on different OSes (linux: EISDIR, win32:
+#   EACCES, OSX: EPERM) when invoked on a directory.
+def delete_any(path):
     """Delete a file or directory."""
-    try:
-        os.unlink(full_path)
-    except OSError, e:
-    # We may be renaming a dangling inventory id
-        if e.errno not in (errno.EISDIR, errno.EACCES, errno.EPERM):
-            raise
-        os.rmdir(full_path)
+    if isdir(path): # Takes care of symlinks
+        os.rmdir(path)
+    else:
+        os.unlink(path)
 
 
 def has_symlinks():
@@ -802,7 +805,7 @@
         return True
     else:
         return False
-        
+
 
 def contains_whitespace(s):
     """True if there are any whitespace characters in s."""

=== modified file 'bzrlib/tests/repository_implementations/test_commit_builder.py'
--- a/bzrlib/tests/repository_implementations/test_commit_builder.py	2007-09-19 01:35:14 +0000
+++ b/bzrlib/tests/repository_implementations/test_commit_builder.py	2007-09-20 09:30:39 +0000
@@ -420,15 +420,11 @@
         tree = self.make_branch_and_tree('.')
         path = 'name'
         make_before(path)
+
         def change_kind():
-            # Look Before You Leap (LBYL) is appropriate here because unlink
-            # will raise different exceptions on different OSes (linux: EISDIR,
-            # win32: EACCES, OSX: EPERM) when invoked on a directory.
-            if osutils.isdir(path): # Takes care of symlinks
-                os.rmdir(path)
-            else:
-                os.unlink(path)
+            osutils.delete_any(path)
             make_after(path)
+
         self._add_commit_change_check_changed(tree, path, change_kind)
 
     def test_last_modified_dir_file(self):



More information about the bazaar-commits mailing list