100
100
mod = os.lstat(filename).st_mode
101
101
if not stat.S_ISLNK(mod):
102
102
mod = mod & 0777555
103
os.chmod(filename, mod)
103
chmod_if_possible(filename, mod)
106
106
def make_writable(filename):
107
107
mod = os.lstat(filename).st_mode
108
108
if not stat.S_ISLNK(mod):
110
os.chmod(filename, mod)
110
chmod_if_possible(filename, mod)
113
def chmod_if_possible(filename, mode):
114
# Set file mode if that can be safely done.
115
# Sometimes even on unix the filesystem won't allow it - see
116
# https://bugs.launchpad.net/bzr/+bug/606537
118
# It is probably faster to just do the chmod, rather than
119
# doing a stat, and then trying to compare
120
os.chmod(filename, mode)
121
except (IOError, OSError),e:
122
# Permission/access denied seems to commonly happen on smbfs; there's
123
# probably no point warning about it.
124
# <https://bugs.launchpad.net/bzr/+bug/606537>
125
if getattr(e, 'errno') in (errno.EPERM, errno.EACCES):
126
trace.mutter("ignore error on chmod of %r: %r" % (
113
132
def minimum_path_selection(paths):
2565
def ensure_empty_directory_exists(path, exception_class):
2566
"""Make sure a local directory exists and is empty.
2568
If it does not exist, it is created. If it exists and is not empty, an
2569
instance of exception_class is raised.
2574
if e.errno != errno.EEXIST:
2576
if os.listdir(path) != []:
2577
raise exception_class(path)
2546
2580
def is_environment_error(evalue):
2547
2581
"""True if exception instance is due to a process environment issue