Skip to content

Commit

Permalink
Fix a silent fail if path is a file #1034 (Windows only).
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasRzepka committed Jul 28, 2024
1 parent 7503d34 commit 4ffce94
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/watchdog/observers/read_directory_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def __init__(self, event_queue, watch, timeout=DEFAULT_EMITTER_TIMEOUT, event_fi
self._handle = None

def on_thread_start(self):
self._handle = get_directory_handle(self.watch.path)
watch_path = self.watch.path
if os.path.isfile(watch_path):
watch_path = os.path.dirname(watch_path)
self._handle = get_directory_handle(watch_path)

if platform.python_implementation() == "PyPy":

Expand All @@ -73,7 +76,12 @@ def queue_events(self, timeout):
with self._lock:
last_renamed_src_path = ""
for winapi_event in winapi_events:
src_path = os.path.join(self.watch.path, winapi_event.src_path)
if os.path.isfile(self.watch.path):
if os.path.basename(self.watch.path) != winapi_event.src_path:
continue
src_path = self.watch.path
else:
src_path = os.path.join(self.watch.path, winapi_event.src_path)

if winapi_event.is_renamed_old:
last_renamed_src_path = src_path
Expand Down

0 comments on commit 4ffce94

Please sign in to comment.