nao-pon/flysystem-google-drive

`getFileObject` by name works only if file is in `cacheFileObjectsByName`

matancohen365 opened this issue · 1 comments

Hey,

I'm trying to determine if a file exists by its name.

Thats is my code:

<?php 

$gdrive = Storage::disk('google');

    if( ! $gdrive->exists('file.txt')) {

        $gdrive->put('file.txt', 'hello world!');
        
        var_dump($gdrive->exists('file.txt')); // true

    }

Every time I refresh the page, a new file created in my drive folder *** even if it already exists ***

After some debugging, I found the reason:

protected function getFileObject($path, $checkDir = false)

getFileObject by name works only if file is in cacheFileObjectsByName

So $gdrive->exists('file.txt') will work with a filename only after a $gdrive->put('file.txt',.. request.

My workaround:
I'm using cache (filename => file key) but it's not reliable in the case of the file changed/deleted/removed.

Any idea how to fix it?

Of course you can't use exists with original file name. Google drive has its own file name and path (google allowed file with the same name), you need to use that to check your file exists or not.