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

Error while calling scanDirectory() with recursive true #29

Open
AyhamAlzoubi opened this issue Jul 8, 2014 · 1 comment
Open

Error while calling scanDirectory() with recursive true #29

AyhamAlzoubi opened this issue Jul 8, 2014 · 1 comment

Comments

@AyhamAlzoubi
Copy link

Hey
I am using this Library for Sftp and calling the function scanDirectory to get a list of files and directories and i found this bug when the directory doesn't contain subDirectories or it's empty

while executing the function:
https://github.com/Herzult/php-ssh/blob/master/src/Ssh/Sftp.php#L267

private function scanDirectory($directory, $recursive)
    {
        if (!$results = @scandir($this->getUrl($directory))) {
            return false;
        }

        $files = array();
        $directories = array();

        foreach ($results as $result) {
            if (in_array($result, array('.', '..'))) {
                continue;
            }

            $filename = sprintf('%s/%s', $directory, $result);

            if (false === @scandir($this->getUrl($filename))) {
                $files[] = $filename;
            } else {
                $directories[] = $filename;

                if ($recursive) {
                    $children = $this->scanDirectory($filename, $recursive);
                    $files = array_merge($files, $children[0]);
                    $directories = array_merge($directories, $children[1]);
                }
            }
        }

        return array($files, $directories);
    }

its giving this error: array_merge(): Argument #2 is not an array
because the function is recursive and can return false (not only array) and we use the function result as array in the line:

$children = $this->scanDirectory($filename, $recursive);
$files = array_merge($files, $children[0]);

Can you please have a look at this issue, And let me know if it can be fixed.

Thanks

@AyhamAlzoubi AyhamAlzoubi changed the title Error while calling scanDirectory() with recurcive true Error while calling scanDirectory() with recursive true Jul 9, 2014
@h4cc
Copy link
Collaborator

h4cc commented Aug 11, 2014

@AyhamAlzoubi Thanks for reporting. But i cant reproduce that error :(
If you could provide a folder structure that will trigger that bug, please show us.

By your error description such a change i made should fix that error.

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

2 participants