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

Undefined index: size when trying to get the listing of a directories with subdirectories #2

Closed
cramiro opened this issue Feb 13, 2015 · 2 comments

Comments

@cramiro
Copy link

cramiro commented Feb 13, 2015

Let's say your root has

-- dir1
   |-- some_dir
   |-- file1.txt
   `-- file2.txt
-- dir2

and you connect to that root and ask:

$contents  = $flysystem->listContents('/dir1');

you will get a Notice like this:

PHP Notice:  Undefined index: size in /your_project/vendor/league/flysystem-sftp/src/SftpAdapter.php on line 205

https://github.com/thephpleague/flysystem-sftp/blob/master/src/SftpAdapter.php#L205

Because $object['type'] == 2 doesn't have size index

@cramiro cramiro changed the title Undefined index: size when trying to get the listing of a directories with subdirectories Undefined index: size when trying to get the listing of a directories with subdirectories Feb 13, 2015
@cramiro
Copy link
Author

cramiro commented Feb 13, 2015

I can send a PR with a fix.

cramiro added a commit to cramiro/flysystem-sftp that referenced this issue Feb 19, 2015
What does this Pull Request Do?
-------------------------------
* Modified the `normalizeListingObject()` method. Identify the type of the object to normalize. If it's a 'file' the method will still return the same as before, if it's a 'dir' we take out `visibility` and `size` from the returned array.

How should this be manually tested?
-----------------------------------
A test was included with a similar output you can get in a server, which doesn't include the 'size'.

Any background context you want to provide?
-------------------------------------------
Currently there's a php `Notice` when trying to list the content of a directory with sub-directories.

What are the relevant tickets?
------------------------------
* [Undefined index: size when trying to get the listing of a directories with subdirectories · Issue thephpleague#2 · thephpleague/flysystem-sftp](thephpleague#2)

Any extra info?
---------------
This is a minor bug. Please, give it a try and let me know.
@intrepido
Copy link

The problem still happen, because $object some times doesn't have the key type. A simple fix would be, change the line 329:

$type = ($object['type'] === 1) ? 'file' : 'dir' ;

for this

$type = isset($object['type']) && ($object['type'] === 1) ? 'file' : 'dir' ;

And change the line 310 too:

if ($recursive && $object['type'] === NET_SFTP_TYPE_DIRECTORY) {
      $result = array_merge($result, $this->listDirectoryContents($path));
 }

for this

if (isset($object['type']) && $recursive && $object['type'] === NET_SFTP_TYPE_DIRECTORY) {
      $result = array_merge($result, $this->listDirectoryContents($path));
 }

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

No branches or pull requests

3 participants