From aa6214a2574def6e74b1cdcbd7eb831810a0ec68 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 21 Oct 2019 16:46:46 +0200 Subject: [PATCH] support `append` for smbclient backend --- src/Wrapped/Share.php | 15 ++++++++++++++- tests/ShareTest.php | 7 ------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Wrapped/Share.php b/src/Wrapped/Share.php index 4a21e99..f70eb18 100644 --- a/src/Wrapped/Share.php +++ b/src/Wrapped/Share.php @@ -357,7 +357,20 @@ class Share extends AbstractShare { * @throws \Icewind\SMB\Exception\DependencyException */ public function append($target) { - throw new DependencyException('php-libsmbclient is required for append'); + $target = $this->escapePath($target); + // since returned stream is closed by the caller we need to create a new instance + // since we can't re-use the same file descriptor over multiple calls + $connection = $this->getConnection(); + + $fh = $connection->getFileInputStream(); + $connection->write('reput ' . $this->system->getFD(4) . ' ' . $target); + $connection->write('exit'); + + // use a close callback to ensure the upload is finished before continuing + // this also serves as a way to keep the connection in scope + return CallbackWrapper::wrap($fh, null, null, function () use ($connection, $target) { + $connection->close(false); // dont terminate, give the upload some time + }); } /** diff --git a/tests/ShareTest.php b/tests/ShareTest.php index fc30198..640b6aa 100644 --- a/tests/ShareTest.php +++ b/tests/ShareTest.php @@ -37,13 +37,6 @@ class ShareTest extends AbstractShareTest { $this->share->mkdir($this->root); } - /** - * @expectedException \Icewind\SMB\Exception\DependencyException - */ - public function testAppendStream() { - $this->share->append($this->root . '/foo'); - } - /** * @expectedException \Icewind\SMB\Exception\ConnectException */