Skip to content

Commit 4ffce94

Browse files
committed
Fix a silent fail if path is a file #1034 (Windows only).
1 parent 7503d34 commit 4ffce94

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/watchdog/observers/read_directory_changes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ def __init__(self, event_queue, watch, timeout=DEFAULT_EMITTER_TIMEOUT, event_fi
5050
self._handle = None
5151

5252
def on_thread_start(self):
53-
self._handle = get_directory_handle(self.watch.path)
53+
watch_path = self.watch.path
54+
if os.path.isfile(watch_path):
55+
watch_path = os.path.dirname(watch_path)
56+
self._handle = get_directory_handle(watch_path)
5457

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

@@ -73,7 +76,12 @@ def queue_events(self, timeout):
7376
with self._lock:
7477
last_renamed_src_path = ""
7578
for winapi_event in winapi_events:
76-
src_path = os.path.join(self.watch.path, winapi_event.src_path)
79+
if os.path.isfile(self.watch.path):
80+
if os.path.basename(self.watch.path) != winapi_event.src_path:
81+
continue
82+
src_path = self.watch.path
83+
else:
84+
src_path = os.path.join(self.watch.path, winapi_event.src_path)
7785

7886
if winapi_event.is_renamed_old:
7987
last_renamed_src_path = src_path

0 commit comments

Comments
 (0)