Fix pipe deletion check

This commit is contained in:
R. Richard 2019-09-02 10:46:18 +02:00
parent 517684e84a
commit 57ce35d99d
2 changed files with 8 additions and 8 deletions

View File

@ -28,13 +28,12 @@ class PipeConnector:
def _on_any_event(self, event): def _on_any_event(self, event):
path = event.src_path path = event.src_path
if self._is_pipe(path): if self._is_pipe(path) and isinstance(event, InotifyFileCreatedEvent):
if isinstance(event, InotifyFileCreatedEvent): self._on_create_pipe(path)
self._on_create_pipe(path) LOG.debug('Connected to new pipe "%s"', path)
LOG.debug('Connected to new pipe "%s"', path) elif isinstance(event, InotifyFileDeletedEvent):
elif isinstance(event, InotifyFileDeletedEvent): self._on_delete_pipe(path)
self._on_delete_pipe(path) LOG.debug('Disconnected from deleted pipe "%s"', path)
LOG.debug('Disconnected from deleted pipe "%s"', path)
@staticmethod @staticmethod
def _is_pipe(path): def _is_pipe(path):

View File

@ -3,7 +3,7 @@ from enum import Enum
from dataclasses import dataclass from dataclasses import dataclass
from json import dumps from json import dumps
from secrets import token_urlsafe from secrets import token_urlsafe
from os import urandom, mkfifo, mkdir from os import urandom, mkfifo, mkdir, remove
from os.path import join from os.path import join
from pathlib import Path from pathlib import Path
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
@ -117,6 +117,7 @@ def test_pipe_creation_deletion(mock_context):
path = mock_context.emit_pipe_creation_event(action, mkfifo) path = mock_context.emit_pipe_creation_event(action, mkfifo)
assert events[-1] == path assert events[-1] == path
assert path in pipes.keys() assert path in pipes.keys()
remove(path)
mock_context.pipes.observer.on_any_event(InotifyFileDeletedEvent(path)) mock_context.pipes.observer.on_any_event(InotifyFileDeletedEvent(path))
assert path not in pipes.keys() assert path not in pipes.keys()