Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug: mkdir -p foo/bar,InotifyTree(s) not add watch bar #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 20 additions & 35 deletions inotify/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def event_gen(self, ignore_missing_new_folders=False, **kwargs):
"being recursive): [%s]", full_path)


self._i.add_watch(full_path, self._mask)
self._load_tree(full_path)

if header.mask & inotify.constants.IN_MOVED_FROM:
_LOGGER.debug("A directory has been removed. We're "
Expand Down Expand Up @@ -327,20 +327,7 @@ def event_gen(self, ignore_missing_new_folders=False, **kwargs):
def inotify(self):
return self._i


class InotifyTree(_BaseTree):
"""Recursively watch a path."""

def __init__(self, path, mask=inotify.constants.IN_ALL_EVENTS,
block_duration_s=_DEFAULT_EPOLL_BLOCK_DURATION_S):
super(InotifyTree, self).__init__(mask=mask, block_duration_s=block_duration_s)

self.__root_path = path

self.__load_tree(path)

def __load_tree(self, path):
_LOGGER.debug("Adding initial watches on tree: [%s]", path)
def _load_tree(self, path):

paths = []

Expand All @@ -362,6 +349,22 @@ def __load_tree(self, path):
self._i.add_watch(path, self._mask)


class InotifyTree(_BaseTree):
"""Recursively watch a path."""

def __init__(self, path, mask=inotify.constants.IN_ALL_EVENTS,
block_duration_s=_DEFAULT_EPOLL_BLOCK_DURATION_S):
super(InotifyTree, self).__init__(mask=mask, block_duration_s=block_duration_s)

self.__root_path = path

self.__load_tree(path)

def __load_tree(self, path):
_LOGGER.debug("Adding initial watches on tree: [%s]", path)
return self._load_tree(path)


class InotifyTrees(_BaseTree):
"""Recursively watch over a list of trees."""

Expand All @@ -373,23 +376,5 @@ def __init__(self, paths, mask=inotify.constants.IN_ALL_EVENTS,

def __load_trees(self, paths):
_LOGGER.debug("Adding initial watches on trees: [%s]", ",".join(map(str, paths)))

found = []

q = paths
while q:
current_path = q[0]
del q[0]

found.append(current_path)

for filename in os.listdir(current_path):
entry_filepath = os.path.join(current_path, filename)
if os.path.isdir(entry_filepath) is False:
continue

q.append(entry_filepath)


for path in found:
self._i.add_watch(path, self._mask)
for path in paths:
self._load_tree(path)