Skip to content

Commit 5d2ae1f

Browse files
authored
Support LocalDatastore gets auto-update on CIFS mounts (#1325)
* 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]>
1 parent b50fde6 commit 5d2ae1f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

monailabel/datastore/local.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pydantic import BaseModel
2727
from watchdog.events import PatternMatchingEventHandler
2828
from watchdog.observers import Observer
29+
from watchdog.observers.polling import PollingObserver
2930

3031
from monailabel.interfaces.datastore import Datastore, DefaultLabelTag
3132
from monailabel.interfaces.exception import ImageNotFoundException, LabelNotFoundException
@@ -169,7 +170,7 @@ def __init__(
169170
try:
170171
self._ignore_event_count = 0
171172
self._ignore_event_config = False
172-
self._observer = Observer()
173+
self._observer = PollingObserver() if self._is_on_mount(self._datastore.image_path()) else Observer()
173174
self._observer.schedule(self._handler, recursive=True, path=self._datastore_path)
174175
self._observer.start()
175176
except OSError as e:
@@ -694,6 +695,14 @@ def _write_to_file():
694695
else:
695696
_write_to_file()
696697

698+
def _is_on_mount(self, path):
699+
while True:
700+
if path == os.path.dirname(path):
701+
return False
702+
elif os.path.ismount(path):
703+
return True
704+
path = os.path.dirname(path)
705+
697706
def status(self) -> Dict[str, Any]:
698707
tags: dict = {}
699708
for obj in self._datastore.objects.values():

0 commit comments

Comments
 (0)