Manipulates a filename until it's unique. This can be disabled by
    setting meta['avoid_name_collision'] to any falsey value.

def avoid_name_collisions(filehandle, meta):
    """Manipulates a filename until it's unique. This can be disabled by
    setting meta['avoid_name_collision'] to any falsey value.
    """
    if meta.get('avoid_name_collision', True):
        filename = filehandle.filename
        original, ext = os.path.splitext(filehandle.filename)
        counter = count()
        while os.path.exists(get_save_path(filename)):
            fixer = str(next(counter))
            filename = '{}_{}{}'.format(original, fixer, ext)
        filehandle.filename = filename
    return filehandle