97
97
mod = os.lstat(filename).st_mode
98
98
if not stat.S_ISLNK(mod):
99
99
mod = mod & 0777555
100
os.chmod(filename, mod)
100
chmod_if_possible(filename, mod)
103
103
def make_writable(filename):
104
104
mod = os.lstat(filename).st_mode
105
105
if not stat.S_ISLNK(mod):
107
os.chmod(filename, mod)
107
chmod_if_possible(filename, mod)
110
def chmod_if_possible(filename, mode):
111
# Set file mode if that can be safely done.
112
# Sometimes even on unix the filesystem won't allow it - see
113
# https://bugs.launchpad.net/bzr/+bug/606537
115
# It is probably faster to just do the chmod, rather than
116
# doing a stat, and then trying to compare
117
os.chmod(filename, mode)
118
except (IOError, OSError),e:
119
# Permission/access denied seems to commonly happen on smbfs; there's
120
# probably no point warning about it.
121
# <https://bugs.launchpad.net/bzr/+bug/606537>
122
if getattr(e, 'errno') in (errno.EPERM, errno.EACCES):
123
trace.mutter("ignore error on chmod of %r: %r" % (
110
129
def minimum_path_selection(paths):
277
296
# copy posixpath.abspath, but use os.getcwdu instead
278
297
if not posixpath.isabs(path):
279
298
path = posixpath.join(getcwd(), path)
280
return posixpath.normpath(path)
299
return _posix_normpath(path)
283
302
def _posix_realpath(path):
284
303
return posixpath.realpath(path.encode(_fs_enc)).decode(_fs_enc)
306
def _posix_normpath(path):
307
path = posixpath.normpath(path)
308
# Bug 861008: posixpath.normpath() returns a path normalized according to
309
# the POSIX standard, which stipulates (for compatibility reasons) that two
310
# leading slashes must not be simplified to one, and only if there are 3 or
311
# more should they be simplified as one. So we treat the leading 2 slashes
312
# as a special case here by simply removing the first slash, as we consider
313
# that breaking POSIX compatibility for this obscure feature is acceptable.
314
# This is not a paranoid precaution, as we notably get paths like this when
315
# the repo is hosted at the root of the filesystem, i.e. in "/".
316
if path.startswith('//'):
287
321
def _win32_fixdrive(path):
288
322
"""Force drive letters to be consistent.
2487
2521
is_local_pid_dead = win32utils.is_local_pid_dead
2489
2523
is_local_pid_dead = _posix_is_local_pid_dead
2526
def fdatasync(fileno):
2527
"""Flush file contents to disk if possible.
2529
:param fileno: Integer OS file handle.
2530
:raises TransportNotPossible: If flushing to disk is not possible.
2532
fn = getattr(os, 'fdatasync', getattr(os, 'fsync', None))
2537
def ensure_empty_directory_exists(path, exception_class):
2538
"""Make sure a local directory exists and is empty.
2540
If it does not exist, it is created. If it exists and is not empty, an
2541
instance of exception_class is raised.
2546
if e.errno != errno.EEXIST:
2548
if os.listdir(path) != []:
2549
raise exception_class(path)