multitenant: rename whoosh directory before cleaning index (#37291)
This commit is contained in:
parent
a14ced4d18
commit
ef552c210e
|
@ -17,6 +17,8 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
|
@ -35,6 +37,22 @@ class WhooshSearchBackend(haystack.backends.whoosh_backend.WhooshSearchBackend):
|
|||
def use_file_storage(self, value):
|
||||
pass
|
||||
|
||||
def delete_index(self):
|
||||
renamed_path = None
|
||||
if os.path.exists(self.path):
|
||||
# rename existing path instead of removing, so it works on NFS
|
||||
# when there are opened files.
|
||||
renamed_path = self.path + '.deleted-%s' % time.time()
|
||||
os.rename(self.path, renamed_path)
|
||||
super(WhooshSearchBackend, self).delete_index()
|
||||
if renamed_path:
|
||||
# remove afterwards and ignore errors (residual directories will
|
||||
# have to be cleaned manually)
|
||||
try:
|
||||
shutil.rmtree(renamed_path)
|
||||
except (IOError, OSError):
|
||||
pass
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
tenant = connection.get_tenant()
|
||||
|
|
Loading…
Reference in New Issue