From da1976936208c0a0528031cb989777a65b85e0a2 Mon Sep 17 00:00:00 2001 From: "R. Richard" Date: Thu, 27 Jun 2019 16:15:22 +0200 Subject: [PATCH] Fix file observer --- lib/tfw/components/history_monitor.py | 9 --------- lib/tfw/components/inotify/inotify.py | 12 ++++++------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/tfw/components/history_monitor.py b/lib/tfw/components/history_monitor.py index d8c5587..9855f57 100644 --- a/lib/tfw/components/history_monitor.py +++ b/lib/tfw/components/history_monitor.py @@ -1,10 +1,6 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. -from pwd import getpwnam -from grp import getgrnam -from pathlib import Path -from os import chown from re import findall from re import compile as compileregex from abc import ABC, abstractmethod @@ -30,11 +26,6 @@ class HistoryMonitor(ABC, InotifyObserver): self.history = [] self._last_length = len(self.history) self.uplink = uplink - uid = getpwnam('user').pw_uid - gid = getgrnam('users').gr_gid - path = Path(self.histfile) - path.touch() - chown(self.histfile, uid, gid) super().__init__(self.histfile) @property diff --git a/lib/tfw/components/inotify/inotify.py b/lib/tfw/components/inotify/inotify.py index 3bbefee..4e2d1dd 100644 --- a/lib/tfw/components/inotify/inotify.py +++ b/lib/tfw/components/inotify/inotify.py @@ -2,7 +2,7 @@ from typing import Iterable from time import time -from os.path import abspath, dirname, isfile +from os.path import abspath, dirname, isdir from watchdog.observers import Observer from watchdog.events import FileSystemMovedEvent, PatternMatchingEventHandler @@ -66,10 +66,10 @@ class InotifyDirDeletedEvent(InotifyEvent): class InotifyObserver: - def __init__(self, path, patterns=[], exclude=None, recursive=False): + def __init__(self, path, patterns=None, exclude=None, recursive=False): self._files = [] self._paths = path - self._patterns = patterns + self._patterns = patterns or [] self._exclude = exclude self._recursive = recursive self._observer = Observer() @@ -97,12 +97,12 @@ class InotifyObserver: def _extract_files_from_paths(self): files, paths = [], [] for path in self._paths: - if isfile(path): + if isdir(path): + paths.append(path) + else: new_file = abspath(path) files.append(new_file) paths.append(dirname(new_file)) - else: - paths.append(path) self._files, self._paths = files, paths @property