~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Packman
  • Date: 2011-12-05 14:21:55 UTC
  • mfrom: (6015.44.9 2.4)
  • mto: This revision was merged to the branch mainline in revision 6345.
  • Revision ID: martin.packman@canonical.com-20111205142155-t7s4lr5aau50dp8i
Merge 2.4 into bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
    mod = os.lstat(filename).st_mode
101
101
    if not stat.S_ISLNK(mod):
102
102
        mod = mod & 0777555
103
 
        os.chmod(filename, mod)
 
103
        chmod_if_possible(filename, mod)
104
104
 
105
105
 
106
106
def make_writable(filename):
107
107
    mod = os.lstat(filename).st_mode
108
108
    if not stat.S_ISLNK(mod):
109
109
        mod = mod | 0200
110
 
        os.chmod(filename, mod)
 
110
        chmod_if_possible(filename, mod)
 
111
 
 
112
 
 
113
def chmod_if_possible(filename, mode):
 
114
    # Set file mode if that can be safely done.
 
115
    # Sometimes even on unix the filesystem won't allow it - see
 
116
    # https://bugs.launchpad.net/bzr/+bug/606537
 
117
    try:
 
118
        # It is probably faster to just do the chmod, rather than
 
119
        # doing a stat, and then trying to compare
 
120
        os.chmod(filename, mode)
 
121
    except (IOError, OSError),e:
 
122
        # Permission/access denied seems to commonly happen on smbfs; there's
 
123
        # probably no point warning about it.
 
124
        # <https://bugs.launchpad.net/bzr/+bug/606537>
 
125
        if getattr(e, 'errno') in (errno.EPERM, errno.EACCES):
 
126
            trace.mutter("ignore error on chmod of %r: %r" % (
 
127
                filename, e))
 
128
            return
 
129
        raise
111
130
 
112
131
 
113
132
def minimum_path_selection(paths):
2543
2562
        fn(fileno)
2544
2563
 
2545
2564
 
 
2565
def ensure_empty_directory_exists(path, exception_class):
 
2566
    """Make sure a local directory exists and is empty.
 
2567
    
 
2568
    If it does not exist, it is created.  If it exists and is not empty, an
 
2569
    instance of exception_class is raised.
 
2570
    """
 
2571
    try:
 
2572
        os.mkdir(path)
 
2573
    except OSError, e:
 
2574
        if e.errno != errno.EEXIST:
 
2575
            raise
 
2576
        if os.listdir(path) != []:
 
2577
            raise exception_class(path)
 
2578
 
 
2579
 
2546
2580
def is_environment_error(evalue):
2547
2581
    """True if exception instance is due to a process environment issue
2548
2582