-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from DigitalSlideArchive/remove-delete-locks
Add an option to remove stale deletelock files
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,22 @@ def preprovision(opts): | |
subprocess.check_call(cmd, shell=True) | ||
|
||
|
||
def clean_delete_locks(): | ||
from girder.constants import AssetstoreType | ||
from girder.models.assetstore import Assetstore | ||
|
||
for assetstore in Assetstore().find(): | ||
if assetstore['type'] != AssetstoreType.FILESYSTEM: | ||
continue | ||
rootpath = assetstore['root'] | ||
cmd = ['find', rootpath, '-name', '*.deleteLock', '-delete'] | ||
logger.info(f'Removing old delete locks: {cmd}') | ||
try: | ||
subprocess.check_call(cmd, shell=False) | ||
except Exception: | ||
logger.info(f'Failed trying to remove old delete locks: {cmd}') | ||
|
||
|
||
def provision(opts): # noqa | ||
""" | ||
Provision the instance. | ||
|
@@ -268,6 +284,10 @@ def provision(opts): # noqa | |
method = params.pop('method', 'createFilesystemAssetstore') | ||
getattr(Assetstore(), method)(**params) | ||
|
||
# Clean up old deleteLocks | ||
if getattr(opts, 'clean-delete-locks', None): | ||
clean_delete_locks() | ||
|
||
# Make sure we have a demo collection and download some demo files | ||
if getattr(opts, 'samples', None): | ||
get_sample_data( | ||
|
@@ -450,6 +470,8 @@ def merge_default_opts(opts): | |
'email': '[email protected]', | ||
'public': True, | ||
} | ||
if getattr(opts, 'clean-delete-locks', None) is None: | ||
setattr(opts, 'clean-delete-locks', True) | ||
resources = opts.resources or [] | ||
resources.extend([{ | ||
'model': 'collection', | ||
|
@@ -490,6 +512,13 @@ def __call__(self, parser, namespace, values, option_string=None): | |
parser.add_argument( | ||
'--samples', '--data', '--sample-data', | ||
action='store_true', help='Download sample data') | ||
parser.add_argument( | ||
'--clean-delete-locks', action='store_true', | ||
help='Remove assetstore delete locks on start') | ||
parser.add_argument( | ||
'--no-clean-delete-locks', action='store_false', | ||
dest='clean-delete-locks', | ||
help='Do not remove assetstore delete locks on start') | ||
parser.add_argument( | ||
'--sample-collection', dest='sample-collection', default='Samples', | ||
help='Sample data collection name') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters