refactoring

This commit is contained in:
Maxim Devaev 2023-03-17 23:41:59 +02:00
parent 166cb8e3b7
commit dbb9eda341
3 changed files with 13 additions and 15 deletions

View File

@ -190,14 +190,15 @@ class Inotify:
self.__events_queue: "asyncio.Queue[InotifyEvent]" = asyncio.Queue() self.__events_queue: "asyncio.Queue[InotifyEvent]" = asyncio.Queue()
async def watch(self, path: str, mask: int) -> None: async def watch(self, mask: int, *paths: str) -> None:
path = os.path.normpath(path) for path in paths:
assert path not in self.__wd_by_path, path path = os.path.normpath(path)
get_logger().info("Watching for %s", path) assert path not in self.__wd_by_path, path
# Асинхронно, чтобы не висло на NFS get_logger().info("Watching for %s", path)
wd = _inotify_check(await aiotools.run_async(libc.inotify_add_watch, self.__fd, _fs_encode(path), mask)) # Асинхронно, чтобы не висло на NFS
self.__wd_by_path[path] = wd wd = _inotify_check(await aiotools.run_async(libc.inotify_add_watch, self.__fd, _fs_encode(path), mask))
self.__path_by_wd[wd] = path self.__wd_by_path[path] = wd
self.__path_by_wd[wd] = path
# def unwatch(self, path: str) -> None: # def unwatch(self, path: str) -> None:
# path = os.path.normpath(path) # path = os.path.normpath(path)

View File

@ -417,11 +417,8 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
await asyncio.sleep(5) await asyncio.sleep(5)
with Inotify() as inotify: with Inotify() as inotify:
for path in [ await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, *self.__storage.get_watchable_paths())
*self.__storage.get_watchable_paths(), await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, *self.__drive.get_watchable_paths())
*self.__drive.get_watchable_paths(),
]:
await inotify.watch(path, InotifyMask.ALL_MODIFY_EVENTS)
# После установки вотчеров еще раз проверяем стейт, чтобы ничего не потерять # После установки вотчеров еще раз проверяем стейт, чтобы ничего не потерять
await self.__reload_state() await self.__reload_state()

View File

@ -82,8 +82,8 @@ class Plugin(BaseUserGpioDriver):
await asyncio.sleep(5) await asyncio.sleep(5)
with Inotify() as inotify: with Inotify() as inotify:
await inotify.watch(os.path.dirname(self.__udc_path), InotifyMask.ALL_MODIFY_EVENTS) await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, os.path.dirname(self.__udc_path))
await inotify.watch(self.__profile_path, InotifyMask.ALL_MODIFY_EVENTS) await inotify.watch(InotifyMask.ALL_MODIFY_EVENTS, self.__profile_path)
self._notifier.notify() self._notifier.notify()
while True: while True:
need_restart = False need_restart = False