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

Fix for the isDir function in the FTP Adapter #607

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
27 changes: 12 additions & 15 deletions src/Gaufrette/Adapter/Ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,30 +378,27 @@ private function isDir($directory)
return true;
}

$chDirResult = false;
try {
$chDirResult = false;
Romain marked this conversation as resolved.
Show resolved Hide resolved
$chDirResult = ftp_chdir($this->getConnection(), $this->directory);

// change directory again to return in the base directory
ftp_chdir($this->getConnection(), $this->directory);
} catch(\Exception $e) {

// Build the FTP URL that will be used to check if the path is a directory or not
$url = $this->createConnectionUrl();

return $chDirResult;
} catch (\Exception $e) {
// is_dir is only available in passive mode.
// See https://php.net/manual/en/wrappers.ftp.php for more details.
if(!$this->passive) {
throw new \BadFunctionCallException('is_dir can only be used in passive mode.');
}

if (!@is_dir($url . $directory)) {
return false;
if (!$this->passive) {
throw new \RuntimeException(
\sprintf('Not able to determine whether "%s" is a directory or not. Please try again using a passive FTP connection if your backend supports it, by setting the "passive" option of this adapter to true.', $directory),
$e->getCode(),
$e
);
}
}

if (!$chDirResult) {
return false;
// Build the FTP URL that will be used to check if the path is a directory or not
$url = $this->createConnectionUrl();
return @is_dir($url . $directory);
}

return true;
Romain marked this conversation as resolved.
Show resolved Hide resolved
Expand Down