make the index dir if it does not exist.

This commit is contained in:
Jonas Winkler 2020-11-20 11:21:09 +01:00
parent 1655d85a53
commit 2c9555015b

View File

@ -1,6 +1,8 @@
import logging import logging
import os
from contextlib import contextmanager from contextlib import contextmanager
from django.conf import settings
from whoosh import highlight from whoosh import highlight
from whoosh.fields import Schema, TEXT, NUMERIC from whoosh.fields import Schema, TEXT, NUMERIC
from whoosh.highlight import Formatter, get_text from whoosh.highlight import Formatter, get_text
@ -8,7 +10,6 @@ from whoosh.index import create_in, exists_in, open_dir
from whoosh.qparser import MultifieldParser from whoosh.qparser import MultifieldParser
from whoosh.writing import AsyncWriter from whoosh.writing import AsyncWriter
from paperless import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -69,6 +70,8 @@ def open_index(recreate=False):
# TODO: this is not thread safe. If 2 instances try to create the index # TODO: this is not thread safe. If 2 instances try to create the index
# at the same time, this fails. This currently prevents parallel # at the same time, this fails. This currently prevents parallel
# tests. # tests.
if not os.path.isdir(settings.INDEX_DIR):
os.makedirs(settings.INDEX_DIR, exist_ok=True)
return create_in(settings.INDEX_DIR, get_schema()) return create_in(settings.INDEX_DIR, get_schema())