Repository navigation
Conversation
A verbatim copy of src/PhpseclibV3 with only the namespaces (League\Flysystem\PhpseclibV4, phpseclib4) and the package metadata (league/flysystem-sftp-v4, phpseclib/phpseclib ^4.0, php ^8.1) changed, published to a new thephpleague/flysystem-sftp-v4 sub-split, the same way PhpseclibV3 was added next to PhpseclibV2. The phpseclib 4 API changes follow in the next commit, so that they can be reviewed on their own.
phpseclib 4 throws exceptions where phpseclib 3 returned false, so every SFTP call that used to be checked for false now translates the exception into the matching Flysystem exception, keeping the original as the previous exception: - put(), mkdir(), get(), chmod(), stat() and rename() throw instead of returning false. get() into a stream returns null on success, so it can no longer be checked for truthiness. - rawlist() throws for a missing directory, which still yields an empty listing. - The recursive delete() removes the directory itself, so the rmdir() in deleteDirectory() now throws. Its failure is ignored, as phpseclib 3's false was. - chmod() takes the filename first, and NET_SFTP_TYPE_DIRECTORY is replaced by FileType::DIRECTORY. - getLastError() is gone, so UnableToAuthenticate::connectionError() stays null. - login() only accepts a PrivateKey, so keys are loaded with PublicKeyLoader::loadPrivateKey(), which also rejects a public key with NoKeyLoadedException. - getServerPublicHostKey() returns null instead of false. SftpStub follows the new typed signatures and throws a FileSystemException on a tripwire, like phpseclib 4 does. Co-authored-by: Rik van der Heijden <mail@rikvanderheijden.com>
Both phpseclib majors share the phpseclib/phpseclib package name, so only one of them can be installed per run: - The root composer.json allows ^3.0.36 || ^4.0, so the existing matrix resolves phpseclib 4 and tests src/PhpseclibV4, and a new matrix entry pins phpseclib 3 with --with to keep src/PhpseclibV3 covered. - The SFTP tests skip instead of marking themselves incomplete when their phpseclib major is missing, as PHPUnit 10 reports markTestIncomplete() in setUpBeforeClass() as an error. - wait_for_sftp.php uses the V4 or V3 connection provider, depending on the installed major. phpseclib 2 cannot be installed next to them, so the V2 fallback is gone. - phpstan.neon excludes src/PhpseclibV4, like src/PhpseclibV2 and src/PhpseclibV3.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1921.
This adds
src/PhpseclibV4, published asleague/flysystem-sftp-v4, as suggested in #1921: a new directory plus a new sub-split, likePhpseclibV3was added next toPhpseclibV2.league/flysystem-sftp-v3keeps working unchanged with phpseclib 3.It builds on #1929 by @rikvdh, who is credited as co-author of the port. I opened a new PR because #1929's CI fails, and its author mentioned they could not run the SFTP tests locally. Running it against the repo's Docker SFTP servers shows three problems: the V4 adapter lets raw phpseclib exceptions through,
readStream()anddeleteDirectory()fail, and the V3 suite cannot run, because the rootcomposer.jsononly allows phpseclib 4.Commits
The three commits are meant to be reviewed one by one:
src/PhpseclibV3tosrc/PhpseclibV4. A verbatim copy, with only the namespaces (League\Flysystem\PhpseclibV4,phpseclib4) and the package metadata (league/flysystem-sftp-v4,phpseclib/phpseclib: ^4.0,php: ^8.1) changed, plus theconfig.subsplit-publish.jsonand.gitattributesentries.put(),mkdir(),get(),chmod(),stat()andrename()throw instead of returningfalse. Each call now translates the exception into the matching Flysystem exception and keeps the original as$previous.get()into a stream returnsnullon success, so it is no longer checked for truthiness.rawlist()throws for a missing directory, which still yields an empty listing.delete()removes the directory itself, so thermdir()that follows indeleteDirectory()throws. That failure is ignored, as phpseclib 3'sfalsewas.chmod()takes the filename first, andNET_SFTP_TYPE_DIRECTORYbecomesFileType::DIRECTORY.login()only accepts aPrivateKey, so keys are loaded withPublicKeyLoader::loadPrivateKey().getServerPublicHostKey()returnsnullinstead offalse.SftpStubfollows the new typed signatures and throws on a tripwire, as phpseclib 4 does.composer.jsonallows^3.0.36 || ^4.0, so the existing matrix resolves phpseclib 4, and one new matrix entry pins phpseclib 3 with--with phpseclib/phpseclib:^3.0.36.markTestIncomplete()insetUpBeforeClass(), which PHPUnit 10 reports as an error.wait_for_sftp.phppicks the V4 or V3 provider.phpstan.neonexcludessrc/PhpseclibV4, like V2 and V3.Testing
The CI run is waiting for approval, so I replayed both jobs locally with the workflow's own
composer updatecommands. The tests ran againstdocker compose up sftp sftp_eddsa_only toxiproxy, withCOMPOSER_OPTS=''and the test key in an ssh-agent, so the agent test runs too:src/PhpseclibV4src/PhpseclibV3composer update)--with phpseclib/phpseclib:^3.0.36)^4.0is an honest lower bound. These were installed with--no-blocking, because Composer blocks releases before 4.0.4 over security advisories.Behavior differences from the V3 adapter
SSH2::getLastError(), soUnableToAuthenticate::connectionError()is alwaysnullhere.UnableTo*exceptions now carry phpseclib's message (for exampleError from server (SSH_FX_NO_SUCH_FILE): No such file) as their reason, and the phpseclib exception as$previous.Left for a maintainer
thephpleague/flysystem-sftp-v4and register it on Packagist, so the sub-split can publish.docs/adapter/sftp-v4/. I'm happy to send agh-pagesPR that mirrorssftp-v3.mdonce this direction is fine with you.