0001-multitenant-rename-whoosh-directory-before-cleaning-.patch
hobo/multitenant/haystack.py | ||
---|---|---|
17 | 17 |
from __future__ import absolute_import |
18 | 18 | |
19 | 19 |
import os |
20 |
import shutil |
|
21 |
import time |
|
20 | 22 | |
21 | 23 |
from django.conf import settings |
22 | 24 |
from django.db import connection |
... | ... | |
35 | 37 |
def use_file_storage(self, value): |
36 | 38 |
pass |
37 | 39 | |
40 |
def delete_index(self): |
|
41 |
renamed_path = None |
|
42 |
if os.path.exists(self.path): |
|
43 |
# rename existing path instead of removing, so it works on NFS if |
|
44 |
# when there are opened files. |
|
45 |
renamed_path = self.path + '.deleted-%s' % time.time() |
|
46 |
os.rename(self.path, renamed_path) |
|
47 |
super(WhooshSearchBackend, self).delete_index() |
|
48 |
if renamed_path: |
|
49 |
# remove afterwards and ignore errors (residual directories will |
|
50 |
# have to be cleaned manually) |
|
51 |
try: |
|
52 |
shutil.rmtree(renamed_path) |
|
53 |
except (IOError, OSError): |
|
54 |
pass |
|
55 | ||
38 | 56 |
@property |
39 | 57 |
def path(self): |
40 | 58 |
tenant = connection.get_tenant() |
41 |
- |