Osc files:scan does not honor blacklists

I am running a NextCloud 20 server instance in a virtual machine (Ubuntu/Snap), using a whole drive of the Windows host as external storage, which is made available as shared folder.

Unfortunately some users have deleted files on the Windows side (host), so that this drive contains a trash bin ($RECYCLE.BIN). This causes a problem, because files:scan produces an exception when it hits the subfolders of $RECYCLE.BIN, which belong to some other users, and aborts the scan :frowning:

Exception during scan: opendir(/media/NextCloud/$RECYCLE.BIN/S-1-5-18): failed to open dir: Operation not permitted
#0 [internal function]: OCA\Files\Command\Scan->exceptionErrorHandler(2, ‘opendir(/media/…’, ‘/snap/nextcloud…’, 132, Array)
#1 /snap/nextcloud/24940/htdocs/lib/private/Files/Storage/Local.php(132): opendir(’/media/NextClou…’)
#2 /snap/nextcloud/24940/htdocs/lib/private/Files/Storage/Common.php(877): OC\Files\Storage\Local->opendir(’$RECYCLE.BIN/S-…’)
#3 [internal function]: OC\Files\Storage\Common->getDirectoryContent(’$RECYCLE.BIN/S-…’)
#4 /snap/nextcloud/24940/htdocs/lib/private/Files/Cache/Scanner.php(408): iterator_to_array(Object(Generator))
#5 /snap/nextcloud/24940/htdocs/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren(’$RECYCLE.BIN/S-…’, true, 3, 2383849, true, 0)
#6 /snap/nextcloud/24940/htdocs/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren(’$RECYCLE.BIN/S-…’, true, 3, 2383849, true)
#7 /snap/nextcloud/24940/htdocs/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren(’$RECYCLE.BIN’, true, 3, 2383756, true)
#8 /snap/nextcloud/24940/htdocs/lib/private/Files/Cache/Scanner.php(340): OC\Files\Cache\Scanner->scanChildren(’’, true, 3, 2383755, true)
#9 /snap/nextcloud/24940/htdocs/lib/private/Files/Utils/Scanner.php(260): OC\Files\Cache\Scanner->scan(’’, true, 3)

IMHO the scanner should be more robust in such cases: either the function scanChildren() in Scanner.php should check the first parameter against isFileBlacklisted(), or the function opendir() in Local.php should use some try/catch to (silently) ignore this situation.

For the moment I worked around by doing a bind-mount of an empty local directory over the $RECYCLE.BIN, but that is a hack only and no “solution”…

[small update: the same applies for the reserved folder “System Volume Information”]