Open Vringe opened 9 months ago
Regardless of the issue here; there's always the possibility for a race condition where you remove all files but before you can remove the directory another process adds a new one.
A clean solution to this could be to rename the folder first (to something random) and then remove the file as you propose. Of course this then leads to questions of whether we have permissions to rename the file..
Would calling $iterator->rewind()
also solve your issue, without requiring us to load the whole directory tree in memory?
Bug Report
Summary
I would like to bring up again the discussions from #1135 and #1136 . I think this only affects BSD-based systems. This is especially a problem in environments, where NFS is used (NAS and also some webhosting providers)
There are old discussions about that:
In the past, we had several customers with different applications complaining about folders, that are not getting properly deleted. This often breaks built-in updaters, but also addons/modules or even core functions of an application. For example, Shopware uses flysystem to delete folders when installing an update.
This combined with NFS leads leads to some very unpredictable problems as explained above.
I made a PoC to reproduce it. I took the relevant parts from
flysystem-local/LocalFilesystemAdapter.php
For testing, I created a folder with 400 files in it
After executing it, there are still a lot of files left in the directory and an exception is thrown because the
poc
folder is not empty.Now, If I wrap
iterator_to_array()
around the return value oflistDirectoryRecursively
, the problems disappear, because all the files in the directory are first discovered and then deleted. This may not be the best solution to work around this problem. I think it would be better to sort of read for example 20 entries in that directory, delete them and then read the next 20 entries until it is empty.I would be very grateful if we can implement a solution for BSD-based systems as this library is widely used in many applications. Of course, I'm happy to help where I can if you need to test something.
Nextcloud also had some recent changes related to this, if you want to get some inspiration. https://github.com/nextcloud/updater/pull/515