Local files deleted if External Storage fails to mount

Nextcloud version: 23.0.4
Operating system and version: Debian 11.3
Apache or nginx version: Apache/2.4.53
PHP version: 7.4.28

The issue you are facing:
If Local type External storage gets dismounted (or not mounted correctly on server restart) than the local copy of the folder gets deleted when the folder is refreshed (for example trying to write new file into that folder).

Steps to replicate it:

  1. mount SMB/NFS share to /mnt/external
  2. add External storage type “Local”
  3. synchronize added folder with Windows NextCloud client
  4. unmount SMB/NFS share
  5. trigger an update (example: create a new file in the external folder in web client or upload file from mobile) or just wait for update to happen
  6. Windows NextCloud client will delete local copy of the folder / subfolder

The output of your Nextcloud log in Admin > Logging:

Error	index	OCP\Files\NotFoundException: /peter/files/Test/Peter

    /var/www/cloud/lib/private/Files/Node/Node.php - line 286:

    OC\Files\Node\Root->get()

    /var/www/cloud/apps/recommendations/lib/Service/RecentlyEditedFilesSource.php - line 57:

    OC\Files\Node\Node->getParent()

    <<closure>>

    OCA\Recommendations\Service\RecentlyEditedFilesSource->OCA\Recommendations\Service\{closure}("*** sensiti ... *")

    /var/www/cloud/apps/recommendations/lib/Service/RecentlyEditedFilesSource.php - line 65:

    array_map()

    /var/www/cloud/apps/recommendations/lib/Service/RecommendationService.php - line 90:

    OCA\Recommendations\Service\RecentlyEditedFilesSource->getMostRecentRecommendation()

    <<closure>>

    OCA\Recommendations\Service\RecommendationService->OCA\Recommendations\Service\{closure}("*** sensiti ... *")

    /var/www/cloud/apps/recommendations/lib/Service/RecommendationService.php - line 91:

    array_reduce()

    /var/www/cloud/apps/recommendations/lib/Controller/RecommendationController.php - line 70:

    OCA\Recommendations\Service\RecommendationService->getRecommendations()

    /var/www/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 217:

    OCA\Recommendations\Controller\RecommendationController->index()

    /var/www/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 126:

    OC\AppFramework\Http\Dispatcher->executeController()

    /var/www/cloud/lib/private/AppFramework/App.php - line 157:

    OC\AppFramework\Http\Dispatcher->dispatch()

    /var/www/cloud/lib/private/Route/Router.php - line 302:

    OC\AppFramework\App::main()

    /var/www/cloud/lib/base.php - line 1008:

    OC\Route\Router->match()

    /var/www/cloud/index.php - line 36:

    OC::handleRequest()

No errors in apache logs.