Rev 3108: Fix LockableFiles to not use modes that allow the user to write to things they create. in http://bzr.arbash-meinel.com/branches/bzr/jam-integration

John Arbash Meinel john at arbash-meinel.com
Thu Dec 13 20:17:34 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/jam-integration

------------------------------------------------------------
revno: 3108
revision-id:john at arbash-meinel.com-20071213201706-nt8f4om80gyn6l6v
parent: pqm at pqm.ubuntu.com-20071213141047-tklbta8rymzfpj6y
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Thu 2007-12-13 14:17:06 -0600
message:
  Fix LockableFiles to not use modes that allow the user to write to things they create.
  It seems that cygwin + FAT32 will report all directories as readonly,
  even though they are not.
  Regardless, someone might have .bzr/repository as readonly, but still
  allow you to create files in a subdirectory.
  Either way, there is no reason to have a file that we are going to
  write to be created readonly.
modified:
  bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
  bzrlib/tests/test_lockable_files.py test_lockable_files.py-20051225183927-365c7fd99591caf1
  bzrlib/tests/test_lockdir.py   test_lockdir.py-20060220222025-33d4221569a3d600
-------------- next part --------------
=== modified file 'bzrlib/lockable_files.py'
--- a/bzrlib/lockable_files.py	2007-08-15 04:33:34 +0000
+++ b/bzrlib/lockable_files.py	2007-12-13 20:17:06 +0000
@@ -132,7 +132,11 @@
             self._dir_mode = 0755
             self._file_mode = 0644
         else:
-            self._dir_mode = st.st_mode & 07777
+            # Check the directory mode, but also make sure the created
+            # directories and files are read-write for this user. This is
+            # mostly a workaround for filesystems which lie about being able to
+            # write to a directory (cygwin & win32)
+            self._dir_mode = (st.st_mode & 07777) | 00700
             # Remove the sticky and execute bits for files
             self._file_mode = self._dir_mode & ~07111
         if not self._set_dir_mode:

=== modified file 'bzrlib/tests/test_lockable_files.py'
--- a/bzrlib/tests/test_lockable_files.py	2007-04-19 14:55:20 +0000
+++ b/bzrlib/tests/test_lockable_files.py	2007-12-13 20:17:06 +0000
@@ -17,11 +17,13 @@
 from StringIO import StringIO
 
 import bzrlib
-import bzrlib.errors as errors
+from bzrlib import (
+    errors,
+    lockdir,
+    osutils,
+    )
 from bzrlib.errors import BzrBadParameterNotString, NoSuchFile, ReadOnlyError
 from bzrlib.lockable_files import LockableFiles, TransportLock
-from bzrlib import lockdir
-from bzrlib.lockdir import LockDir
 from bzrlib.tests import TestCaseInTempDir
 from bzrlib.tests.test_smart import TestCaseWithSmartMedium
 from bzrlib.tests.test_transactions import DummyWeave
@@ -347,7 +349,7 @@
         self.lockable.create_lock()
 
     def get_lockable(self):
-        return LockableFiles(self.transport, 'my-lock', LockDir)
+        return LockableFiles(self.transport, 'my-lock', lockdir.LockDir)
 
     def test_lock_created(self):
         self.assertTrue(self.transport.has('my-lock'))
@@ -357,10 +359,16 @@
         self.assertFalse(self.transport.has('my-lock/held/info'))
         self.assertTrue(self.transport.has('my-lock'))
 
+    def test__file_modes(self):
+        self.transport.mkdir('readonly')
+        osutils.make_readonly('readonly')
+        lockable = LockableFiles(self.transport.clone('readonly'), 'test-lock',
+                                 lockdir.LockDir)
+        # The directory mode should be read-write-execute for the current user
+        self.assertEqual(00700, lockable._dir_mode & 00700)
+        # Files should be read-write for the current user
+        self.assertEqual(00600, lockable._file_mode & 00700)
 
-    # TODO: Test the lockdir inherits the right file and directory permissions
-    # from the LockableFiles.
-        
 
 class TestLockableFiles_RemoteLockDir(TestCaseWithSmartMedium,
                               _TestLockableFiles_mixin):

=== modified file 'bzrlib/tests/test_lockdir.py'
--- a/bzrlib/tests/test_lockdir.py	2007-10-05 04:47:09 +0000
+++ b/bzrlib/tests/test_lockdir.py	2007-12-13 20:17:06 +0000
@@ -597,7 +597,7 @@
 
     def test_lock_permission(self):
         if not osutils.supports_posix_readonly():
-            raise tests.TestSkipped('Cannot induce a permission failure')
+            raise tests.TestNotApplicable('Cannot induce a permission failure')
         ld1 = self.get_lock()
         lock_path = ld1.transport.local_abspath('test_lock')
         os.mkdir(lock_path)



More information about the bazaar-commits mailing list