Skip to content

Commit

Permalink
Support LocalDatastore gets auto-update on CIFS mounts (#1325)
Browse files Browse the repository at this point in the history
* support watching datastore on mounted file systems

Signed-off-by: Janis Vahldiek <[email protected]>

* change imports

Signed-off-by: Janis Vahldiek <[email protected]>

* fix params

Signed-off-by: Janis Vahldiek <[email protected]>

---------

Signed-off-by: Janis Vahldiek <[email protected]>
  • Loading branch information
jlvahldiek authored Feb 25, 2023
1 parent b50fde6 commit 5d2ae1f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion monailabel/datastore/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pydantic import BaseModel
from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer
from watchdog.observers.polling import PollingObserver

from monailabel.interfaces.datastore import Datastore, DefaultLabelTag
from monailabel.interfaces.exception import ImageNotFoundException, LabelNotFoundException
Expand Down Expand Up @@ -169,7 +170,7 @@ def __init__(
try:
self._ignore_event_count = 0
self._ignore_event_config = False
self._observer = Observer()
self._observer = PollingObserver() if self._is_on_mount(self._datastore.image_path()) else Observer()
self._observer.schedule(self._handler, recursive=True, path=self._datastore_path)
self._observer.start()
except OSError as e:
Expand Down Expand Up @@ -694,6 +695,14 @@ def _write_to_file():
else:
_write_to_file()

def _is_on_mount(self, path):
while True:
if path == os.path.dirname(path):
return False
elif os.path.ismount(path):
return True
path = os.path.dirname(path)

def status(self) -> Dict[str, Any]:
tags: dict = {}
for obj in self._datastore.objects.values():
Expand Down

0 comments on commit 5d2ae1f

Please sign in to comment.