mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
Don't watch inotify modify events because they fires on every write()
This commit is contained in:
parent
60f413c1f4
commit
2195acf2ff
@ -130,13 +130,12 @@ class InotifyMask:
|
||||
# | OPEN
|
||||
# )
|
||||
|
||||
# Helper for all modify events
|
||||
ALL_MODIFY_EVENTS = (
|
||||
# Helper for all changes events except MODIFY, because it fires on each write()
|
||||
ALL_CHANGES_EVENTS = (
|
||||
CLOSE_WRITE
|
||||
| CREATE
|
||||
| DELETE
|
||||
| DELETE_SELF
|
||||
| MODIFY
|
||||
| MOVE_SELF
|
||||
| MOVED_FROM
|
||||
| MOVED_TO
|
||||
@ -202,8 +201,8 @@ class Inotify:
|
||||
|
||||
self.__events_queue: "asyncio.Queue[InotifyEvent]" = asyncio.Queue()
|
||||
|
||||
async def watch_all_modify(self, *paths: str) -> None:
|
||||
await self.watch(InotifyMask.ALL_MODIFY_EVENTS, *paths)
|
||||
async def watch_all_changes(self, *paths: str) -> None:
|
||||
await self.watch(InotifyMask.ALL_CHANGES_EVENTS, *paths)
|
||||
|
||||
async def watch(self, mask: int, *paths: str) -> None:
|
||||
for path in paths:
|
||||
@ -237,7 +236,7 @@ class Inotify:
|
||||
except asyncio.TimeoutError:
|
||||
return None
|
||||
|
||||
async def get_series(self, timeout: float) -> list[InotifyEvent]:
|
||||
async def get_series(self, timeout: float, max_series: int=64) -> list[InotifyEvent]:
|
||||
series: list[InotifyEvent] = []
|
||||
event = await self.get_event(timeout)
|
||||
if event:
|
||||
@ -246,6 +245,8 @@ class Inotify:
|
||||
event = await self.get_event(timeout)
|
||||
if event:
|
||||
series.append(event)
|
||||
if len(series) >= max_series:
|
||||
break
|
||||
return series
|
||||
|
||||
def __read_and_queue_events(self) -> None:
|
||||
|
||||
@ -439,8 +439,8 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes
|
||||
await asyncio.sleep(5)
|
||||
|
||||
with Inotify() as inotify:
|
||||
await inotify.watch_all_modify(*self.__storage.get_watchable_paths())
|
||||
await inotify.watch_all_modify(*self.__drive.get_watchable_paths())
|
||||
await inotify.watch_all_changes(*self.__storage.get_watchable_paths())
|
||||
await inotify.watch_all_changes(*self.__drive.get_watchable_paths())
|
||||
|
||||
# После установки вотчеров еще раз проверяем стейт,
|
||||
# чтобы не потерять состояние привода.
|
||||
|
||||
@ -81,8 +81,8 @@ class Plugin(BaseUserGpioDriver):
|
||||
await asyncio.sleep(5)
|
||||
|
||||
with Inotify() as inotify:
|
||||
await inotify.watch_all_modify(os.path.dirname(self.__udc_path))
|
||||
await inotify.watch_all_modify(self.__profile_path)
|
||||
await inotify.watch_all_changes(os.path.dirname(self.__udc_path))
|
||||
await inotify.watch_all_changes(self.__profile_path)
|
||||
self._notifier.notify()
|
||||
while True:
|
||||
need_restart = False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user