Rev 6061: (mbp) squelch chmod errors, in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.4/
Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Nov 18 01:02:55 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.4/
------------------------------------------------------------
revno: 6061 [merge]
revision-id: pqm at pqm.ubuntu.com-20111118010254-bmlsxny8e3xo7pj0
parent: pqm at pqm.ubuntu.com-20111110175055-y46fxb9dncmfewu0
parent: mbp at canonical.com-20111118003250-g8q58o9mpjvdb8a4
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.4
timestamp: Fri 2011-11-18 01:02:54 +0000
message:
(mbp) squelch chmod errors,
to cope with non-unixy unix filesystems (Martin Pool)
modified:
bzrlib/atomicfile.py atomicfile.py-20050509044450-dbd24e6c564f7c66
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/plugins/launchpad/lp_api.py lp_api.py-20090704082908-79il6zl4gugwl3wz-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
bzrlib/transport/local.py local_transport.py-20050711165921-9b1f142bfe480c24
doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/atomicfile.py'
--- a/bzrlib/atomicfile.py 2011-06-28 21:47:24 +0000
+++ b/bzrlib/atomicfile.py 2011-11-14 09:37:40 +0000
@@ -78,7 +78,7 @@
# the common case is that we won't, though.
st = os.fstat(self._fd)
if stat.S_IMODE(st.st_mode) != new_mode:
- os.chmod(self.tmpfilename, new_mode)
+ osutils.chmod_if_possible(self.tmpfilename, new_mode)
def _get_closed(self):
symbol_versioning.warn('AtomicFile.closed deprecated in bzr 0.10',
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2011-10-04 18:43:55 +0000
+++ b/bzrlib/osutils.py 2011-11-18 00:32:50 +0000
@@ -97,14 +97,33 @@
mod = os.lstat(filename).st_mode
if not stat.S_ISLNK(mod):
mod = mod & 0777555
- os.chmod(filename, mod)
+ chmod_if_possible(filename, mod)
def make_writable(filename):
mod = os.lstat(filename).st_mode
if not stat.S_ISLNK(mod):
mod = mod | 0200
- os.chmod(filename, mod)
+ chmod_if_possible(filename, mod)
+
+
+def chmod_if_possible(filename, mode):
+ # Set file mode if that can be safely done.
+ # Sometimes even on unix the filesystem won't allow it - see
+ # https://bugs.launchpad.net/bzr/+bug/606537
+ try:
+ # It is probably faster to just do the chmod, rather than
+ # doing a stat, and then trying to compare
+ os.chmod(filename, mode)
+ except (IOError, OSError),e:
+ # Permission/access denied seems to commonly happen on smbfs; there's
+ # probably no point warning about it.
+ # <https://bugs.launchpad.net/bzr/+bug/606537>
+ if getattr(e, 'errno') in (errno.EPERM, errno.EACCES):
+ trace.mutter("ignore error on chmod of %r: %r" % (
+ filename, e))
+ return
+ raise
def minimum_path_selection(paths):
=== modified file 'bzrlib/plugins/launchpad/lp_api.py'
--- a/bzrlib/plugins/launchpad/lp_api.py 2011-02-11 05:27:33 +0000
+++ b/bzrlib/plugins/launchpad/lp_api.py 2011-11-14 09:37:40 +0000
@@ -134,7 +134,7 @@
proxy_info=proxy_info)
# XXX: Work-around a minor security bug in launchpadlib 1.5.1, which would
# create this directory with default umask.
- os.chmod(cache_directory, 0700)
+ osutils.chmod_if_possible(cache_directory, 0700)
return launchpad
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2011-08-31 06:22:52 +0000
+++ b/bzrlib/tests/__init__.py 2011-11-14 09:37:40 +0000
@@ -4756,7 +4756,7 @@
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
fd, name = f
os.close(fd)
- os.chmod(name, write_perms)
+ osutils.chmod_if_possible(name, write_perms)
read_perms = os.stat(name).st_mode & 0777
os.unlink(name)
=== modified file 'bzrlib/tests/test_transport.py'
--- a/bzrlib/tests/test_transport.py 2011-07-05 05:32:18 +0000
+++ b/bzrlib/tests/test_transport.py 2011-11-14 09:37:40 +0000
@@ -16,6 +16,7 @@
from cStringIO import StringIO
+import errno
import os
import subprocess
import sys
@@ -723,6 +724,29 @@
self.assertEquals(t.local_abspath(''), here)
+class TestLocalTransportMutation(tests.TestCaseInTempDir):
+
+ def test_local_transport_mkdir(self):
+ here = osutils.abspath('.')
+ t = transport.get_transport(here)
+ t.mkdir('test')
+ self.assertTrue(os.path.exists('test'))
+
+ def test_local_transport_mkdir_permission_denied(self):
+ # See https://bugs.launchpad.net/bzr/+bug/606537
+ here = osutils.abspath('.')
+ t = transport.get_transport(here)
+ def fake_chmod(path, mode):
+ e = OSError('permission denied')
+ e.errno = errno.EPERM
+ raise e
+ self.overrideAttr(os, 'chmod', fake_chmod)
+ t.mkdir('test')
+ t.mkdir('test2', mode=0707)
+ self.assertTrue(os.path.exists('test'))
+ self.assertTrue(os.path.exists('test2'))
+
+
class TestLocalTransportWriteStream(tests.TestCaseWithTransport):
def test_local_fdatasync_calls_fdatasync(self):
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2011-10-26 15:21:29 +0000
+++ b/bzrlib/transform.py 2011-11-14 09:37:40 +0000
@@ -783,7 +783,7 @@
to_mode |= 0010 & ~umask
else:
to_mode = current_mode & ~0111
- os.chmod(abspath, to_mode)
+ osutils.chmod_if_possible(abspath, to_mode)
def _new_entry(self, name, parent_id, file_id):
"""Helper function to create a new filesystem entry."""
@@ -1642,7 +1642,7 @@
else:
raise
if typefunc(mode):
- os.chmod(self._limbo_name(trans_id), mode)
+ osutils.chmod_if_possible(self._limbo_name(trans_id), mode)
def iter_tree_children(self, parent_id):
"""Iterate through the entry's tree children, if any"""
=== modified file 'bzrlib/transport/local.py'
--- a/bzrlib/transport/local.py 2011-10-05 00:08:40 +0000
+++ b/bzrlib/transport/local.py 2011-11-14 09:37:40 +0000
@@ -255,7 +255,7 @@
if mode is not None and mode != S_IMODE(st.st_mode):
# Because of umask, we may still need to chmod the file.
# But in the general case, we won't have to
- os.chmod(abspath, mode)
+ osutils.chmod_if_possible(abspath, mode)
writer(fd)
finally:
os.close(fd)
@@ -314,12 +314,13 @@
local_mode = mode
try:
os.mkdir(abspath, local_mode)
- if mode is not None:
- # It is probably faster to just do the chmod, rather than
- # doing a stat, and then trying to compare
- os.chmod(abspath, mode)
except (IOError, OSError),e:
self._translate_error(e, abspath)
+ if mode is not None:
+ try:
+ osutils.chmod_if_possible(abspath, mode)
+ except (IOError, OSError), e:
+ self._translate_error(e, abspath)
def mkdir(self, relpath, mode=None):
"""Create a directory at the given path."""
@@ -354,7 +355,7 @@
if mode is not None and mode != S_IMODE(st.st_mode):
# Because of umask, we may still need to chmod the file.
# But in the general case, we won't have to
- os.chmod(file_abspath, mode)
+ osutils.chmod_if_possible(file_abspath, mode)
return st.st_size
def append_file(self, relpath, f, mode=None):
@@ -453,7 +454,7 @@
otherpath = other._abspath(path)
shutil.copy(mypath, otherpath)
if mode is not None:
- os.chmod(otherpath, mode)
+ osutils.chmod_if_possible(otherpath, mode)
except (IOError, OSError),e:
self._translate_error(e, path)
count += 1
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt 2011-10-27 15:04:35 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt 2011-11-14 09:37:40 +0000
@@ -32,6 +32,9 @@
.. Fixes for situations where bzr would previously crash or give incorrect
or undesirable results.
+* Cope with Unix filesystems, such as smbfs, where chmod gives 'permission
+ denied'. (Martin Pool, #606537)
+
* During merges, when two entries end up using the same path for two
different file-ids (the same file being 'bzr added' in two different
branches) , 'duplicate' conflicts are created instead of 'content'
More information about the bazaar-commits
mailing list