Skip to content

Fix for the isDir function in the FTP Adapter#607

Open
Romain wants to merge 13 commits into
KnpLabs:masterfrom
Romain:master
Open

Fix for the isDir function in the FTP Adapter#607
Romain wants to merge 13 commits into
KnpLabs:masterfrom
Romain:master

Conversation

@Romain

@Romain Romain commented Apr 30, 2019

Copy link
Copy Markdown

The isDir function seems to be broken in the FTP Adapter.
When I try to retrieve a document through a stream, I get this error: ftp_chdir(): /documents/your-file-name.jpg: No such file or directory

Here is the complete trace:

in vendor/knplabs/gaufrette/src/Gaufrette/StreamWrapper.php->stat (line 210) 
in vendor/knplabs/gaufrette/src/Gaufrette/Stream/InMemoryBuffer.php->isDirectory (line 159) 
in vendor/knplabs/gaufrette/src/Gaufrette/Filesystem.php->isDirectory (line 333)
in vendor/knplabs/gaufrette/src/Gaufrette/Adapter/Ftp.php->isDir (line 222)
in vendor/knplabs/gaufrette/src/Gaufrette/Adapter/Ftp.phpftp_chdir (line 369)
in vendor/knplabs/gaufrette/src/Gaufrette/Adapter/Ftp.php (line 369)

Changing the way we perform this test by using the PHP function is_dir instead of the ftp_chdir one fixes this error.

Comment thread src/Gaufrette/Adapter/Ftp.php

@Romain Romain left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a private method for the connection URL.
I also kept the chdir method as the main approach and fallback on is_dir with passive mode set to true if we catch and exception with chdir.

@nicolasmure nicolasmure left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update ;)

Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
@Romain

Romain commented Jun 18, 2019

Copy link
Copy Markdown
Author

@nicolasmure I pushed a fix with your comments applied in it.

@nicolasmure nicolasmure left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also squash your commits please ? :)

Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
@Romain

Romain commented Jun 20, 2019

Copy link
Copy Markdown
Author

@nicolasmure Got it. Pushed a change accordingly to your comment.

@nicolasmure nicolasmure left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes :)

There are also some failing tests, do you mind to fix them ?

phpunit :

There were 2 failures:
1) Gaufrette\Functional\Adapter\FtpTest::shouldCheckIfFileExists
Failed asserting that true is false.
/home/travis/build/KnpLabs/Gaufrette/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php:91

2) Gaufrette\Functional\Adapter\FtpTest::shouldFailWhenTryMtimeForKeyWhichDoesNotExist
Failed asserting that 1561017417 is false.
/home/travis/build/KnpLabs/Gaufrette/tests/Gaufrette/Functional/Adapter/FunctionalTestCase.php:119

and also the phpspec for this adapter.

You can run the specs with

$ docker/run-task php7.2 vendor/bin/phpspec run spec/Gaufrette/Adapter/Ftp.php

and the integration tests with

$ docker/run-task php7.2 vendor/bin/phpunit tests/Gaufrette/Functional/Adapter/FtpTest.php

Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
@Romain

Romain commented Jun 21, 2019

Copy link
Copy Markdown
Author

Your comments have been integrated. These are nice improvements. ;)

@nicolasmure nicolasmure left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also update the tests accordingly please ?

Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
@Romain

Romain commented Jul 26, 2019

Copy link
Copy Markdown
Author

@nicolasmure I'm not sure how to update the tests since they're not checking the way we connect to the server.

Comment thread src/Gaufrette/Adapter/Ftp.php Outdated
@PedroTroller PedroTroller self-assigned this Oct 18, 2024
@FlorianQgb FlorianQgb removed their assignment Mar 31, 2025
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

Successfully merging this pull request may close these issues.

6 participants