@@ -296,7 +296,16 @@ def _dir_model(self, path, content=True):
296296 model ["size" ] = None
297297 os_dir = self ._get_os_path (path )
298298 dir_contents = os .listdir (os_dir )
299- model ["item_count" ] = len (dir_contents )
299+ filtered_count = 0
300+ for name in dir_contents :
301+ try :
302+ os_path = os .path .join (os_dir , name )
303+ if self .should_list (name ) and (self .allow_hidden or not is_file_hidden (os_path )):
304+ filtered_count += 1
305+ except OSError as e :
306+ self .log .warning ("Error accessing %s: %s" , os .path .join (os_dir , name ), e )
307+
308+ model ["item_count" ] = filtered_count
300309 if content :
301310 model ["content" ] = contents = []
302311 for name in os .listdir (os_dir ):
@@ -770,7 +779,16 @@ async def _dir_model(self, path, content=True):
770779 model ["size" ] = None
771780 os_dir = self ._get_os_path (path )
772781 dir_contents = await run_sync (os .listdir , os_dir )
773- model ["item_count" ] = len (dir_contents )
782+ filtered_count = 0
783+ for name in dir_contents :
784+ try :
785+ os_path = os .path .join (os_dir , name )
786+ if self .should_list (name ) and (self .allow_hidden or not is_file_hidden (os_path )):
787+ filtered_count += 1
788+ except OSError as e :
789+ self .log .warning ("Error accessing %s: %s" , os .path .join (os_dir , name ), e )
790+
791+ model ["item_count" ] = filtered_count
774792 if content :
775793 model ["content" ] = contents = []
776794 for name in dir_contents :
0 commit comments