258
258
def _win32_rename(old, new):
259
fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
259
"""We expect to be able to atomically replace 'new' with old.
261
On win32, if new exists, it must be moved out of the way first,
265
fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
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())
262
280
# Default is to just use the python builtins, but these can be rebound on
775
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
778
823
if _platform_normalizes_filenames:
779
def unicode_filename(path):
780
"""Make sure 'path' is a properly normalized filename.
782
On platforms where the system normalizes filenames (Mac OSX),
783
you can access a file by any path which will normalize
785
Internally, bzr only supports NFC/NFKC normalization, since
786
that is the standard for XML documents.
787
So we return an normalized path, and indicate this has been
790
:return: (path, is_normalized) Return a path which can
791
access the file, and whether or not this path is
794
return unicodedata.normalize('NFKC', path), True
824
normalized_filename = _accessible_normalized_filename
796
def unicode_filename(path):
797
"""Make sure 'path' is a properly normalized filename.
799
On platforms where the system does not normalize filenames
800
(Windows, Linux), you have to access a file by its exact path.
801
Internally, bzr only supports NFC/NFKC normalization, since
802
that is the standard for XML documents.
803
So we return the original path, and indicate if this is
806
:return: (path, is_normalized) Return a path which can
807
access the file, and whether or not this path is
810
return path, unicodedata.normalize('NFKC', path) == path
826
normalized_filename = _inaccessible_normalized_filename
813
829
def terminal_width():