Improve index mounting value clean up code to remove the spaces at the starts and at the end of directories. Closes again GitLab issue #520 Thanks to TheOneValen @ for the report.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-10-09 04:48:25 -04:00
parent 838035291d
commit 1e08653b88
4 changed files with 42 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ from time import time
from fuse import FuseOSError, Operations
from django.core.exceptions import MultipleObjectsReturned
from django.db.models import Count, F, Func, Value
from django.db.models import Count, F, Func, Transform, Value
from document_indexing.models import Index, IndexInstanceNode
from documents.models import Document
@@ -23,14 +23,22 @@ from .runtime import cache
logger = logging.getLogger(__name__)
class Trim(Transform):
function = 'TRIM'
lookup_name = 'trim'
class IndexFilesystem(Operations):
@staticmethod
def _clean_queryset(queryset):
# Remove newline carriage return to make multiline indexes
# Remove newline carriage returns and the first and last space
# to make multiline indexes
# valid directoy names
return queryset.annotate(
clean_value=Func(
F('value'), Value('\r\n'), Value(' '), function='replace'
clean_value=Trim(
Func(
F('value'), Value('\r\n'), Value(' '), function='replace'
),
)
)