spatie / flysystem-dropbox

A flysystem driver for Dropbox that uses the v2 API
https://freek.dev/734-dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application
MIT License
343 stars 50 forks source link

Retriving files/directories from nested path results in empty array. #54

Closed Doomkyn closed 4 years ago

Doomkyn commented 4 years ago

Ok so after a bit of research and breakpoint debugging, I found out where the problem lies. This function inside laravel\vendor\league\flysystem\src\Util\ContentListingFormatter.php is what cause the case sensitivity problem:

private function isDirectChild(array $entry)
{
    return Util::dirname($entry['path']) === $this->directory;
}

this check if the entry is child of the directory but it uses case sensitive comparison, which is wrong in out case cause Dropbox is case insensitive, and the listFolder call returns wrong case on non-last folders.

I fixed editing the function to compare strings ignoring case as it follows:

private function isDirectChild(array $entry)
{
    return (strcasecmp(Util::dirname($entry['path']), $this->directory) == 0);
}

I know this is not a problem related to the spatie/flysystem-dropbox package itself, but it could be useful for it to override that function to prevent this kind of unwanted behaviours.

Hope this helps.

freekmurze commented 4 years ago

Thanks for posting that info here.