Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate sub folders being shown #19

Closed
paulcanning opened this issue Mar 29, 2016 · 7 comments
Closed

Duplicate sub folders being shown #19

paulcanning opened this issue Mar 29, 2016 · 7 comments
Labels

Comments

@paulcanning
Copy link

I have a bucket with some nest folders and I am getting duplication for some reason eg:

  • Main Bucket
  • - Top Folder
  • - - Sub Folder A
  • - - - Another folder
  • - - - Another folder < -- duplicate of above
  • - - Sub Folder B
  • - - - etc
@matthewgoslett
Copy link
Contributor

Can you provide me with some sample code so I can replicate this?
Thanks

@paulcanning
Copy link
Author

My connector:

function googleCloud($bucket)
    {
        $credentials = new \Google_Auth_AssertionCredentials(
            'gcstest@MY_PROJECT.iam.gserviceaccount.com',
            [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL],
            file_get_contents(set_realpath('MY_SECRET.p12')),
            'notasecret'
        );

        $client = new \Google_Client();
        $client->setAssertionCredentials($credentials);
        $client->setDeveloperKey('MY_KEY');

        $service = new \Google_Service_Storage($client);

        $adapter = new GoogleStorageAdapter($service, $bucket);

        return $adapter;
    }

    public function elfinder_init()
    {
        $this->load->helper('path');

        $opts = array(
            'roots' => array(
                array(
                    'id' => 'root',
                    'driver' => 'Flysystem',
                    'alias' => 'CS Root',
                    'URL' => 'https://storage.googleapis.com/MY_BUCKET/',
                    'filesystem' => new Filesystem($this->googleCloud('MY_BUCKET')),
                    'separator' => '/'
                )
            )
        );

        $this->load->library('elfinder_lib', $opts);
    }

@paulcanning
Copy link
Author

Please look at #23 and #24 as I believe it is all connected.

You can replicate this by doing the following:

In the root bucket, create a directory (using the GCS console) then upload a file into the new directory.

In elFinder, you will now see two directories under the main root bucket, with the same name. One will contain the file you uploaded, the other will be empty.

I believe this issue and the two I linked are all related. Basically, the adapter is not recognising directories properly and simply normalises then to be files (if you change the type to directory on line 139 elFinder will list everything as directories (even files obviously) but previously "invisible" directories are now visible.

Clearly some bugs here.

@paulcanning
Copy link
Author

Below is a basic fix for the issue. It will need testing but seems to work for me.

protected function normaliseObject(\Google_Service_Storage_StorageObject $object)
    {
        $type = 'file';

        if ($object->size == '0')
        {
            $type = 'dir';
        }

        return [
            'type' => $type,
            'dirname' => Util::dirname($object->getName()),
            'path' => $type == 'file' ? $object->getName() : rtrim($object->getName(), '/'),
            'timestamp' => strtotime($object->getUpdated()),
            'mimetype' => $object->getContentType(),
            'size' => $object->getSize(),
        ];
    }

@matthewgoslett
Copy link
Contributor

Is this related to #23

With that proposed fix of mine in place, it seems to be resolved:

$filesystem->createDir('zzzz');
$filesystem->put('zzzz', 'hello world');
var_dump($filesystem->listContents());

array(2) {
  [0]=>
  array(8) {
    ["type"]=>
    string(4) "file"
    ["dirname"]=>
    string(0) ""
    ["path"]=>
    string(5) "zzzzz"
    ["timestamp"]=>
    int(1463658746)
    ["mimetype"]=>
    string(10) "text/plain"
    ["size"]=>
    string(2) "11"
    ["basename"]=>
    string(5) "zzzzz"
    ["filename"]=>
    string(5) "zzzzz"
  }
  [1]=>
  array(8) {
    ["type"]=>
    string(3) "dir"
    ["dirname"]=>
    string(0) ""
    ["path"]=>
    string(5) "zzzzz"
    ["timestamp"]=>
    int(1463658744)
    ["mimetype"]=>
    string(10) "text/plain"
    ["size"]=>
    string(1) "0"
    ["basename"]=>
    string(5) "zzzzz"
    ["filename"]=>
    string(5) "zzzzz"
  }
}

@paulcanning
Copy link
Author

Yes, it is related, I didn't realise at the time :)

@matthewgoslett
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants