/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: Martin Pool
  • Date: 2007-08-20 05:53:39 UTC
  • mfrom: (2727 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2730.
  • Revision ID: mbp@sourcefrog.net-20070820055339-uzei7f7i7jo6tugg
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from bzrlib import symbol_versioning
58
58
from bzrlib.symbol_versioning import (
59
59
    deprecated_function,
60
 
    zero_nine,
61
60
    )
62
61
from bzrlib.trace import mutter
63
62
 
69
68
# OR with 0 on those platforms
70
69
O_BINARY = getattr(os, 'O_BINARY', 0)
71
70
 
 
71
# On posix, use lstat instead of stat so that we can
 
72
# operate on broken symlinks. On Windows revert to stat.
 
73
lstat = getattr(os, 'lstat', os.stat)
72
74
 
73
75
def make_readonly(filename):
74
76
    """Make a filename read-only."""
75
 
    mod = os.stat(filename).st_mode
76
 
    mod = mod & 0777555
77
 
    os.chmod(filename, mod)
 
77
    mod = lstat(filename).st_mode
 
78
    if not stat.S_ISLNK(mod):
 
79
        mod = mod & 0777555
 
80
        os.chmod(filename, mod)
78
81
 
79
82
 
80
83
def make_writable(filename):
81
 
    mod = os.stat(filename).st_mode
82
 
    mod = mod | 0200
83
 
    os.chmod(filename, mod)
 
84
    mod = lstat(filename).st_mode
 
85
    if not stat.S_ISLNK(mod):
 
86
        mod = mod | 0200
 
87
        os.chmod(filename, mod)
84
88
 
85
89
 
86
90
_QUOTE_RE = None
763
767
    return pathjoin(*p)
764
768
 
765
769
 
766
 
@deprecated_function(zero_nine)
767
 
def appendpath(p1, p2):
768
 
    if p1 == '':
769
 
        return p2
770
 
    else:
771
 
        return pathjoin(p1, p2)
772
 
    
773
 
 
774
770
def split_lines(s):
775
771
    """Split s into lines, but without removing the newline characters."""
776
772
    lines = s.split('\n')
1084
1080
    
1085
1081
    The data yielded is of the form:
1086
1082
    ((directory-relpath, directory-path-from-top),
1087
 
    [(directory-relpath, basename, kind, lstat, path-from-top), ...]),
 
1083
    [(relpath, basename, kind, lstat, path-from-top), ...]),
1088
1084
     - directory-relpath is the relative path of the directory being returned
1089
1085
       with respect to top. prefix is prepended to this.
1090
1086
     - directory-path-from-root is the path including top for this directory. 
1149
1145
        path-from-top might be unicode or utf8, but it is the correct path to
1150
1146
        pass to os functions to affect the file in question. (such as os.lstat)
1151
1147
    """
1152
 
    fs_encoding = sys.getfilesystemencoding().upper()
 
1148
    fs_encoding = _fs_enc.upper()
1153
1149
    if (sys.platform == 'win32' or
1154
1150
        fs_encoding not in ('UTF-8', 'US-ASCII', 'ANSI_X3.4-1968')): # ascii
1155
1151
        return _walkdirs_unicode_to_utf8(top, prefix=prefix)