~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2009-06-19 09:06:56 UTC
  • mfrom: (4463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4464.
  • Revision ID: mbp@sourcefrog.net-20090619090656-d5weqeecyscv8kqp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
927
927
        shutil.copyfile(src, dest)
928
928
 
929
929
 
 
930
# Look Before You Leap (LBYL) is appropriate here instead of Easier to Ask for
 
931
# Forgiveness than Permission (EAFP) because:
 
932
# - root can damage a solaris file system by using unlink,
 
933
# - unlink raises different exceptions on different OSes (linux: EISDIR, win32:
 
934
#   EACCES, OSX: EPERM) when invoked on a directory.
930
935
def delete_any(path):
931
 
    """Delete a file, symlink or directory.  
932
 
    
933
 
    Will delete even if readonly.
934
 
    """
935
 
    try:
936
 
       _delete_file_or_dir(path)
937
 
    except (OSError, IOError), e:
938
 
        if e.errno in (errno.EPERM, errno.EACCES):
939
 
            # make writable and try again
940
 
            try:
941
 
                make_writable(path)
942
 
            except (OSError, IOError):
943
 
                pass
944
 
            _delete_file_or_dir(path)
945
 
        else:
946
 
            raise
947
 
 
948
 
 
949
 
def _delete_file_or_dir(path):
950
 
    # Look Before You Leap (LBYL) is appropriate here instead of Easier to Ask for
951
 
    # Forgiveness than Permission (EAFP) because:
952
 
    # - root can damage a solaris file system by using unlink,
953
 
    # - unlink raises different exceptions on different OSes (linux: EISDIR, win32:
954
 
    #   EACCES, OSX: EPERM) when invoked on a directory.
 
936
    """Delete a file or directory."""
955
937
    if isdir(path): # Takes care of symlinks
956
938
        os.rmdir(path)
957
939
    else: