[PATCH] Prefer lstat over stat, don't chmod symlinks
Elliot Murphy
elliot at canonical.com
Mon Jun 11 23:10:56 BST 2007
Hi!
I ran into a problem today with 'bzr diff --using meld' on a branch
containing dangling symlinks (I'm using the difftools plugin). Down in
bzrlib.osutils.make_readonly, os.stat() was complaining about 'No such
file or directory' when hitting a dangling symlink.
This patch tries to use lstat instead of stat, reverting to stat on
platforms that don't have lstat (windows). It also checks to see whether
a file is a symlink and does not os.chmod() symlinks.
=== modified file 'bzrlib/osutils.py'
--- bzrlib/osutils.py 2007-05-15 22:40:39 +0000
+++ bzrlib/osutils.py 2007-06-11 22:00:01 +0000
@@ -69,18 +69,23 @@
# OR with 0 on those platforms
O_BINARY = getattr(os, 'O_BINARY', 0)
+# On posix, use lstat instead of stat so that we can
+# operate on broken symlinks. On Windows revert to stat.
+lstat = getattr(os, 'lstat', os.stat)
def make_readonly(filename):
"""Make a filename read-only."""
- mod = os.stat(filename).st_mode
- mod = mod & 0777555
- os.chmod(filename, mod)
+ mod = lstat(filename).st_mode
+ if not stat.S_ISLNK(mod):
+ mod = mod & 0777555
+ os.chmod(filename, mod)
def make_writable(filename):
- mod = os.stat(filename).st_mode
- mod = mod | 0200
- os.chmod(filename, mod)
+ mod = lstat(filename).st_mode
+ if not stat.S_ISLNK(mod):
+ mod = mod | 0200
+ os.chmod(filename, mod)
_QUOTE_RE = None
--
Elliot Murphy | https://launchpad.net/~emurphy/
More information about the bazaar
mailing list