/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-06-17 10:33:38 UTC
  • mfrom: (5299.1.2 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100617103338-k4kkjx9fkt5qv33e
(vila) Fix typo in treebuilder docstring

Show diffs side-by-side

added added

removed removed

Lines of Context:
931
931
 
932
932
def parent_directories(filename):
933
933
    """Return the list of parent directories, deepest first.
934
 
    
 
934
 
935
935
    For example, parent_directories("a/b/c") -> ["a/b", "a"].
936
936
    """
937
937
    parents = []
961
961
    # NB: This docstring is just an example, not a doctest, because doctest
962
962
    # currently can't cope with the use of lazy imports in this namespace --
963
963
    # mbp 20090729
964
 
    
 
964
 
965
965
    # This currently doesn't report the failure at the time it occurs, because
966
966
    # they tend to happen very early in startup when we can't check config
967
967
    # files etc, and also we want to report all failures but not spam the user
1037
1037
 
1038
1038
 
1039
1039
def delete_any(path):
1040
 
    """Delete a file, symlink or directory.  
1041
 
    
 
1040
    """Delete a file, symlink or directory.
 
1041
 
1042
1042
    Will delete even if readonly.
1043
1043
    """
1044
1044
    try:
1233
1233
    # but for now, we haven't optimized...
1234
1234
    return [canonical_relpath(base, p) for p in paths]
1235
1235
 
 
1236
 
 
1237
def decode_filename(filename):
 
1238
    """Decode the filename using the filesystem encoding
 
1239
 
 
1240
    If it is unicode, it is returned.
 
1241
    Otherwise it is decoded from the the filesystem's encoding. If decoding
 
1242
    fails, a errors.BadFilenameEncoding exception is raised.
 
1243
    """
 
1244
    if type(filename) is unicode:
 
1245
        return filename
 
1246
    try:
 
1247
        return filename.decode(_fs_enc)
 
1248
    except UnicodeDecodeError:
 
1249
        raise errors.BadFilenameEncoding(filename, _fs_enc)
 
1250
 
 
1251
 
1236
1252
def safe_unicode(unicode_or_utf8_string):
1237
1253
    """Coerce unicode_or_utf8_string into unicode.
1238
1254
 
1644
1660
        dirblock = []
1645
1661
        append = dirblock.append
1646
1662
        try:
1647
 
            names = sorted(_listdir(top))
 
1663
            names = sorted(map(decode_filename, _listdir(top)))
1648
1664
        except OSError, e:
1649
1665
            if not _is_error_enotdir(e):
1650
1666
                raise
2020
2036
 
2021
2037
def send_all(sock, bytes, report_activity=None):
2022
2038
    """Send all bytes on a socket.
2023
 
 
 
2039
 
2024
2040
    Breaks large blocks in smaller chunks to avoid buffering limitations on
2025
2041
    some platforms, and catches EINTR which may be thrown if the send is
2026
2042
    interrupted by a signal.
2027
2043
 
2028
2044
    This is preferred to socket.sendall(), because it avoids portability bugs
2029
2045
    and provides activity reporting.
2030
 
 
 
2046
 
2031
2047
    :param report_activity: Call this as bytes are read, see
2032
2048
        Transport._report_activity
2033
2049
    """
2121
2137
 
2122
2138
def until_no_eintr(f, *a, **kw):
2123
2139
    """Run f(*a, **kw), retrying if an EINTR error occurs.
2124
 
    
 
2140
 
2125
2141
    WARNING: you must be certain that it is safe to retry the call repeatedly
2126
2142
    if EINTR does occur.  This is typically only true for low-level operations
2127
2143
    like os.read.  If in any doubt, don't use this.
2258
2274
if sys.platform == 'win32':
2259
2275
    def open_file(filename, mode='r', bufsize=-1):
2260
2276
        """This function is used to override the ``open`` builtin.
2261
 
        
 
2277
 
2262
2278
        But it uses O_NOINHERIT flag so the file handle is not inherited by
2263
2279
        child processes.  Deleting or renaming a closed file opened with this
2264
2280
        function is not blocking child processes.