265
265
fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
266
266
except OSError, e:
267
if e.errno in (errno.EPERM, errno.EACCES, errno.EBUSY):
268
# If we try to rename a non-existant file onto cwd, we get EPERM
269
# instead of ENOENT, this will raise ENOENT if the old path
267
if e.errno in (errno.EPERM, errno.EACCES, errno.EBUSY, errno.EINVAL):
268
# If we try to rename a non-existant file onto cwd, we get
269
# EPERM or EACCES instead of ENOENT, this will raise ENOENT
270
# if the old path doesn't exist, sometimes we get EACCES
271
# On Linux, we seem to get EBUSY, on Mac we get EINVAL
277
return unicodedata.normalize('NFKC', os.getcwdu())
275
280
# Default is to just use the python builtins, but these can be rebound on
276
281
# particular platforms.
277
282
abspath = _posix_abspath
788
795
return _platform_normalizes_filenames
798
def _accessible_normalized_filename(path):
799
"""Get the unicode normalized path, and if you can access the file.
801
On platforms where the system normalizes filenames (Mac OSX),
802
you can access a file by any path which will normalize correctly.
803
On platforms where the system does not normalize filenames
804
(Windows, Linux), you have to access a file by its exact path.
806
Internally, bzr only supports NFC/NFKC normalization, since that is
807
the standard for XML documents.
809
So return the normalized path, and a flag indicating if the file
810
can be accessed by that path.
813
return unicodedata.normalize('NFKC', unicode(path)), True
816
def _inaccessible_normalized_filename(path):
817
__doc__ = _accessible_normalized_filename.__doc__
819
normalized = unicodedata.normalize('NFKC', unicode(path))
820
return normalized, normalized == path
791
823
if _platform_normalizes_filenames:
792
def unicode_filename(path):
793
"""Make sure 'path' is a properly normalized filename.
795
On platforms where the system normalizes filenames (Mac OSX),
796
you can access a file by any path which will normalize
798
Internally, bzr only supports NFC/NFKC normalization, since
799
that is the standard for XML documents.
800
So we return an normalized path, and indicate this has been
803
:return: (path, is_normalized) Return a path which can
804
access the file, and whether or not this path is
807
return unicodedata.normalize('NFKC', path), True
824
normalized_filename = _accessible_normalized_filename
809
def unicode_filename(path):
810
"""Make sure 'path' is a properly normalized filename.
812
On platforms where the system does not normalize filenames
813
(Windows, Linux), you have to access a file by its exact path.
814
Internally, bzr only supports NFC/NFKC normalization, since
815
that is the standard for XML documents.
816
So we return the original path, and indicate if this is
819
:return: (path, is_normalized) Return a path which can
820
access the file, and whether or not this path is
823
return path, unicodedata.normalize('NFKC', path) == path
826
normalized_filename = _inaccessible_normalized_filename
826
829
def terminal_width():