~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2010-10-15 15:05:09 UTC
  • mfrom: (5409.1.25 orphan-config-option)
  • mto: This revision was merged to the branch mainline in revision 5504.
  • Revision ID: v.ladeuil+lp@free.fr-20101015150509-cigmjyo1florh3d7
MergeĀ lp:~vila/bzr/323111-orphan-config-option

Show diffs side-by-side

added added

removed removed

Lines of Context:
2354
2354
        raise errors.BzrError("Can't decode username as %s." % \
2355
2355
                user_encoding)
2356
2356
    return username
 
2357
 
 
2358
 
 
2359
def available_backup_name(base, exists):
 
2360
    """Find a non-existing backup file name.
 
2361
 
 
2362
    This will *not* create anything, this only return a 'free' entry.  This
 
2363
    should be used for checking names in a directory below a locked
 
2364
    tree/branch/repo to avoid race conditions. This is LBYL (Look Before You
 
2365
    Leap) and generally discouraged.
 
2366
 
 
2367
    :param base: The base name.
 
2368
 
 
2369
    :param exists: A callable returning True if the path parameter exists.
 
2370
    """
 
2371
    counter = 1
 
2372
    name = "%s.~%d~" % (base, counter)
 
2373
    while exists(name):
 
2374
        counter += 1
 
2375
        name = "%s.~%d~" % (base, counter)
 
2376
    return name