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():
872
875
to exclude some directories, they are then not descended into.
874
877
The data yielded is of the form:
875
[(relpath, basename, kind, lstat, path_from_top), ...]
878
((directory-relpath, directory-path-from-top),
879
[(relpath, basename, kind, lstat), ...]),
880
- directory-relpath is the relative path of the directory being returned
881
with respect to top. prefix is prepended to this.
882
- directory-path-from-root is the path including top for this directory.
883
It is suitable for use with os functions.
884
- relpath is the relative path within the subtree being walked.
885
- basename is the basename of the path
886
- kind is the kind of the file now. If unknown then the file is not
887
present within the tree - but it may be recorded as versioned. See
889
- lstat is the stat data *if* the file was statted.
890
- planned, not implemented:
891
path_from_tree_root is the path from the root of the tree.
877
893
:param prefix: Prefix the relpaths that are yielded with 'prefix'. This
878
894
allows one to walk a subtree but get paths that are relative to a tree
879
895
rooted higher up.
880
896
:return: an iterator over the dirs.
898
#TODO there is a bit of a smell where the results of the directory-
899
# summary in this, and the path from the root, may not agree
900
# depending on top and prefix - i.e. ./foo and foo as a pair leads to
901
# potentially confusing output. We should make this more robust - but
902
# not at a speed cost. RBC 20060731
884
905
_directory = _directory_kind
896
917
for name in sorted(_listdir(top)):
897
918
abspath = top + '/' + name
898
919
statvalue = lstat(abspath)
899
dirblock.append ((relroot + name, name, file_kind_from_stat_mode(statvalue.st_mode), statvalue, abspath))
920
dirblock.append((relroot + name, name,
921
file_kind_from_stat_mode(statvalue.st_mode),
923
yield (currentdir[0], top), dirblock
901
924
# push the user specified dirs from dirblock
902
925
for dir in reversed(dirblock):
903
926
if dir[2] == _directory: