Open Zodiac1978 opened 1 month ago
The question is, what would we expect in such case?
scandir
fails, in other words we cannot determine the contents of a (sub)directory.
Guess it’s likely to expect that we cannot delete the directory, if we just ignore the error. Probably some kind of permissions issue or the directory being deleted in parallel (with really bad timing, given there is only one line of code between check and scan).
Crashing prevents flushing the cache, leaving some half-flushed directory structure back on disk. So ... double check for existence and continue if the directory really does not exist anymore? Or log the error, propagate the negative result through e.g. return values and try to clean up everything else 🤔
Logic has not changed for years, so I guess no reason to rush into it now. But we should revisit the HDD access anyway and probably move some logic to WP_Filesystem
if reasonable.
I got an error message via mail:
This is the code:
https://github.com/pluginkollektiv/cachify/blob/develop/inc/class-cachify-hdd.php#L244C3-L248C5
It looks like scandir is returning false (maybe just temporarily while updating something else) and therefore the array_diff throws an error because it is expecting an array.
Maybe we can make this more robust?