Esempio n. 1
0
def find_lowest_available_suffix(index_instance, document):
    index_instance_documents = DocumentRenameCount.objects.filter(index_instance=index_instance).filter(document__file_extension=document.file_extension)
    files_list = []
    for index_instance_document in index_instance_documents:
        files_list.append(assemble_document_filename(index_instance_document.document, index_instance_document.suffix))

    for suffix in xrange(MAX_SUFFIX_COUNT):
        if assemble_document_filename(document, suffix) not in files_list:
            return suffix

    raise MaxSuffixCountReached(ugettext(u'Maximum suffix (%s) count reached.') % MAX_SUFFIX_COUNT)
Esempio n. 2
0
def fs_create_document_link(index_instance, document, suffix=0):
    if FILESERVING_ENABLE:
        name_part = assemble_document_filename(document, suffix)
        filename = os.extsep.join([name_part, document.file_extension])
        filepath = os.path.join(FILESERVING_PATH, get_instance_path(index_instance), filename)
        try:
            os.symlink(document.file.path, filepath)
        except OSError, exc:
            if exc.errno == errno.EEXIST:
                # This link should not exist, try to delete it
                try:
                    os.unlink(filepath)
                    # Try again
                    os.symlink(document.file.path, filepath)
                except Exception, exc:
                    raise Exception(_(u'Unable to create symbolic link, file exists and could not be deleted: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc})
            else:
                raise Exception(_(u'Unable to create symbolic link: %(filepath)s; %(exc)s') % {'filepath': filepath, 'exc': exc})