OCC scan misses some folders/files

Nextcloud version 27.0.1
Operating system and version Ubuntu 22.04.2 LTS
Apache or nginx version Apache 2.4.52
PHP version PHP 8.1.2

I’ve a SMB external storage added to NextCloud. When I browse to the folders from Webdav or web, I find some folders empty even though they have folders in them.

When I do an occ scan with this command

sudo -u www-data php --define apc.enable_cli=1 /var/www/html/occ files:scan --all -vvv

Some folders get scanned with subfolders and files in them but some folders don’t get scanned so any subfolders or files are not scanned hence they show as empty.

For example the below two folders there are heaps of folders and files in each of them but they show as empty in the occ scan.

    Folder  /sukafun/files/SUKAFUN Data/SUKAFUN-DATA/SUKAFUN Photos
    Folder  /sukafun/files/SUKAFUN Data/SUKAFUN-DATA/WORK

If I scan with path for example

sudo -u www-data php --define apc.enable_cli=1 /var/www/html/occ files:scan --path=“/sukafun/files/SUKAFUN Data/SUKAFUN-DATA/Work”

occ scans everything inside the folder and I can see them in NextCloud. But the strange thing is they disappear again after few mins and the folder becomes empty.

I’ve had this issue for a while and never figured out a way to fix it.
I tried to remove the external storage and re-added it which did not fix the issue.

I also had this issue. Found a .@__thumb file in two of my folders that was preventing the scan from completing. Removing them allowed me to scan the folders properly.