~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2011-11-29 20:20:02 UTC
  • mto: (6015.44.7 2.4)
  • mto: This revision was merged to the branch mainline in revision 6345.
  • Revision ID: mbp@canonical.com-20111129202002-qulub0xwmun0fri0
Tolerate empty limbo and pending-deletion directories

Show diffs side-by-side

added added

removed removed

Lines of Context:
2532
2532
    fn = getattr(os, 'fdatasync', getattr(os, 'fsync', None))
2533
2533
    if fn is not None:
2534
2534
        fn(fileno)
 
2535
 
 
2536
 
 
2537
def ensure_empty_directory_exists(path, exception_class):
 
2538
    """Make sure a local directory exists and is empty.
 
2539
    
 
2540
    If it does not exist, it is created.  If it exists and is not empty, an
 
2541
    instance of exception_class is raised.
 
2542
    """
 
2543
    try:
 
2544
        os.mkdir(path)
 
2545
    except OSError, e:
 
2546
        if e.errno != errno.EEXIST:
 
2547
            raise
 
2548
        if os.listdir(path) != []:
 
2549
            raise exception_class(path)