summaryrefslogtreecommitdiff
path: root/kvmd/plugins
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-08-25 01:24:12 +0300
committerMaxim Devaev <[email protected]>2024-08-25 01:24:12 +0300
commit3837e1a1c8d64cccb12c4811a3975949ee904327 (patch)
tree5fa205c8fe5c78dec9850f788ce97f76c601bbdd /kvmd/plugins
parent8569ed406a0d5f1c5da100fb58c49208fd6e1887 (diff)
Simplified inotify API
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/msd/otg/__init__.py10
-rw-r--r--kvmd/plugins/ugpio/otgconf.py7
2 files changed, 8 insertions, 9 deletions
diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py
index 18f2a006..b652cdd0 100644
--- a/kvmd/plugins/msd/otg/__init__.py
+++ b/kvmd/plugins/msd/otg/__init__.py
@@ -30,7 +30,6 @@ from typing import AsyncGenerator
from ....logging import get_logger
-from ....inotify import InotifyMask
from ....inotify import Inotify
from ....yamlconf import Option
@@ -415,8 +414,8 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
await asyncio.sleep(5)
with Inotify() as inotify:
- await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, *self.__storage.get_watchable_paths())
- await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, *self.__drive.get_watchable_paths())
+ await inotify.watch_all_modify(*self.__storage.get_watchable_paths())
+ await inotify.watch_all_modify(*self.__drive.get_watchable_paths())
# После установки вотчеров еще раз проверяем стейт, чтобы ничего не потерять
await self.__reload_state()
@@ -426,8 +425,9 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
need_reload_state = False
for event in (await inotify.get_series(timeout=1)):
need_reload_state = True
- if event.mask & (InotifyMask.DELETE_SELF | InotifyMask.MOVE_SELF | InotifyMask.UNMOUNT | InotifyMask.ISDIR):
- # Если выгрузили OTG, изменили каталоги, что-то отмонтировали или делают еще какую-то странную фигню
+ if event.restart:
+ # Если выгрузили OTG, изменили каталоги, что-то отмонтировали или делают еще какую-то странную фигню.
+ # Проверяется маска InotifyMask.ALL_RESTART_EVENTS
logger.info("Got a big inotify event: %s; reinitializing MSD ...", event)
need_restart = True
break
diff --git a/kvmd/plugins/ugpio/otgconf.py b/kvmd/plugins/ugpio/otgconf.py
index 4b85a3f4..dc255b02 100644
--- a/kvmd/plugins/ugpio/otgconf.py
+++ b/kvmd/plugins/ugpio/otgconf.py
@@ -28,7 +28,6 @@ from typing import Any
from ...logging import get_logger
-from ...inotify import InotifyMask
from ...inotify import Inotify
from ... import aiotools
@@ -82,15 +81,15 @@ class Plugin(BaseUserGpioDriver):
await asyncio.sleep(5)
with Inotify() as inotify:
- await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, os.path.dirname(self.__udc_path))
- await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, self.__profile_path)
+ await inotify.watch_all_modify(os.path.dirname(self.__udc_path))
+ await inotify.watch_all_modify(self.__profile_path)
self._notifier.notify()
while True:
need_restart = False
need_notify = False
for event in (await inotify.get_series(timeout=1)):
need_notify = True
- if event.mask & (InotifyMask.DELETE_SELF | InotifyMask.MOVE_SELF | InotifyMask.UNMOUNT):
+ if event.restart:
logger.warning("Got fatal inotify event: %s; reinitializing OTG-bind ...", event)
need_restart = True
break