@@ -158,25 +158,29 @@ def _recursive_search(
158158 return result
159159
160160 # Walk through the directories
161- for entry in os .scandir (dirpath ):
162- if entry .is_dir ():
163- # Update dictionary with match and stop recursing for this route
164- if (
165- search_string in entry .name
166- if partial_match
167- else search_string == entry .name
168- ):
169- if result is not None : # MyPy needs this 'is not None' check
170- result [entry .name ] = Path (entry .path )
171- else :
172- # Continue searching down this route until max depth is reached
173- result = _recursive_search (
174- dirpath = entry .path ,
175- search_string = search_string ,
176- partial_match = partial_match ,
177- max_depth = max_depth - 1 ,
178- result = result ,
179- )
161+ try :
162+ for entry in os .scandir (dirpath ):
163+ if entry .is_dir ():
164+ # Update dictionary with match and stop recursing for this route
165+ if (
166+ search_string in entry .name
167+ if partial_match
168+ else search_string == entry .name
169+ ):
170+ if result is not None : # MyPy needs this 'is not None' check
171+ result [entry .name ] = Path (entry .path )
172+ else :
173+ # Continue searching down this route until max depth is reached
174+ result = _recursive_search (
175+ dirpath = entry .path ,
176+ search_string = search_string ,
177+ partial_match = partial_match ,
178+ max_depth = max_depth - 1 ,
179+ result = result ,
180+ )
181+ # Safely skip the directory if it can't access it
182+ except PermissionError :
183+ logger .warning (f"Unable to access { dirpath } ; skipping" , exc_info = True )
180184 return result
181185
182186 murfey_session = db .exec (
0 commit comments