'Return a filename that\'s free on the target storage system and
available for new content to be written to.'

def get_available_name(self, name, max_length=None):

    (dir_name, file_name) = os.path.split(name)
    (file_root, file_ext) = os.path.splitext(file_name)
    while (self.exists(name) or (max_length and (len(name) > max_length))):
        name = os.path.join(dir_name, ('%s_%s%s' % (file_root, get_random_string(7), file_ext)))
        if (max_length is None):
            continue
        truncation = (len(name) - max_length)
        if (truncation > 0):
            file_root = file_root[:(- truncation)]
            if (not file_root):
                raise SuspiciousFileOperation(('Storage    can    not    find    an    available    filename    for    "%s".    Please    make    sure    that    the    corresponding    file    field    allows    sufficient    "max_length".' % name))
            name = os.path.join(dir_name, ('%s_%s%s' % (file_root, get_random_string(7), file_ext)))
    return name
