@@ -44,9 +44,14 @@ def __init__(
4444 super ().__init__ (event_queue , watch , timeout = timeout , event_filter = event_filter )
4545 self ._lock = threading .Lock ()
4646 self ._whandle : HANDLE | None = None
47+ self ._watched_files : dict [str , str ] = {}
4748
4849 def on_thread_start (self ) -> None :
49- self ._whandle = get_directory_handle (self .watch .path )
50+ watch_path = self .watch .path
51+ if os .path .isfile (watch_path ):
52+ watch_path , basename = os .path .split (watch_path )
53+ self ._watched_files [self .watch .path ] = basename
54+ self ._whandle = get_directory_handle (watch_path )
5055
5156 if platform .python_implementation () == "PyPy" :
5257
@@ -71,7 +76,13 @@ def queue_events(self, timeout: float) -> None:
7176 with self ._lock :
7277 last_renamed_src_path = ""
7378 for winapi_event in winapi_events :
74- src_path = os .path .join (self .watch .path , winapi_event .src_path )
79+ try :
80+ basename = self ._watched_files [self .watch .path ] # Is a file?
81+ if basename != winapi_event .src_path :
82+ continue
83+ src_path = self .watch .path
84+ except KeyError :
85+ src_path = os .path .join (self .watch .path , winapi_event .src_path )
7586
7687 if winapi_event .is_renamed_old :
7788 last_renamed_src_path = src_path
0 commit comments