/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: Vincent Ladeuil
  • Date: 2010-06-17 14:58:20 UTC
  • mfrom: (5304 +trunk)
  • mto: (5247.1.9 first-try)
  • mto: This revision was merged to the branch mainline in revision 5326.
  • Revision ID: v.ladeuil+lp@free.fr-20100617145820-4c8abuj0e59w6pyz
Merge bzr.dev into cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
918
918
 
919
919
def parent_directories(filename):
920
920
    """Return the list of parent directories, deepest first.
921
 
    
 
921
 
922
922
    For example, parent_directories("a/b/c") -> ["a/b", "a"].
923
923
    """
924
924
    parents = []
948
948
    # NB: This docstring is just an example, not a doctest, because doctest
949
949
    # currently can't cope with the use of lazy imports in this namespace --
950
950
    # mbp 20090729
951
 
    
 
951
 
952
952
    # This currently doesn't report the failure at the time it occurs, because
953
953
    # they tend to happen very early in startup when we can't check config
954
954
    # files etc, and also we want to report all failures but not spam the user
1024
1024
 
1025
1025
 
1026
1026
def delete_any(path):
1027
 
    """Delete a file, symlink or directory.  
1028
 
    
 
1027
    """Delete a file, symlink or directory.
 
1028
 
1029
1029
    Will delete even if readonly.
1030
1030
    """
1031
1031
    try:
1220
1220
    # but for now, we haven't optimized...
1221
1221
    return [canonical_relpath(base, p) for p in paths]
1222
1222
 
 
1223
 
 
1224
def decode_filename(filename):
 
1225
    """Decode the filename using the filesystem encoding
 
1226
 
 
1227
    If it is unicode, it is returned.
 
1228
    Otherwise it is decoded from the the filesystem's encoding. If decoding
 
1229
    fails, a errors.BadFilenameEncoding exception is raised.
 
1230
    """
 
1231
    if type(filename) is unicode:
 
1232
        return filename
 
1233
    try:
 
1234
        return filename.decode(_fs_enc)
 
1235
    except UnicodeDecodeError:
 
1236
        raise errors.BadFilenameEncoding(filename, _fs_enc)
 
1237
 
 
1238
 
1223
1239
def safe_unicode(unicode_or_utf8_string):
1224
1240
    """Coerce unicode_or_utf8_string into unicode.
1225
1241
 
1631
1647
        dirblock = []
1632
1648
        append = dirblock.append
1633
1649
        try:
1634
 
            names = sorted(_listdir(top))
 
1650
            names = sorted(map(decode_filename, _listdir(top)))
1635
1651
        except OSError, e:
1636
1652
            if not _is_error_enotdir(e):
1637
1653
                raise
2007
2023
 
2008
2024
def send_all(sock, bytes, report_activity=None):
2009
2025
    """Send all bytes on a socket.
2010
 
 
 
2026
 
2011
2027
    Breaks large blocks in smaller chunks to avoid buffering limitations on
2012
2028
    some platforms, and catches EINTR which may be thrown if the send is
2013
2029
    interrupted by a signal.
2014
2030
 
2015
2031
    This is preferred to socket.sendall(), because it avoids portability bugs
2016
2032
    and provides activity reporting.
2017
 
 
 
2033
 
2018
2034
    :param report_activity: Call this as bytes are read, see
2019
2035
        Transport._report_activity
2020
2036
    """
2108
2124
 
2109
2125
def until_no_eintr(f, *a, **kw):
2110
2126
    """Run f(*a, **kw), retrying if an EINTR error occurs.
2111
 
    
 
2127
 
2112
2128
    WARNING: you must be certain that it is safe to retry the call repeatedly
2113
2129
    if EINTR does occur.  This is typically only true for low-level operations
2114
2130
    like os.read.  If in any doubt, don't use this.
2245
2261
if sys.platform == 'win32':
2246
2262
    def open_file(filename, mode='r', bufsize=-1):
2247
2263
        """This function is used to override the ``open`` builtin.
2248
 
        
 
2264
 
2249
2265
        But it uses O_NOINHERIT flag so the file handle is not inherited by
2250
2266
        child processes.  Deleting or renaming a closed file opened with this
2251
2267
        function is not blocking child processes.