support append for smbclient backend

This commit is contained in:
Robin Appelman 2019-10-21 16:46:46 +02:00
commit aa6214a257
2 changed files with 14 additions and 8 deletions

View file

@ -357,7 +357,20 @@ class Share extends AbstractShare {
* @throws \Icewind\SMB\Exception\DependencyException * @throws \Icewind\SMB\Exception\DependencyException
*/ */
public function append($target) { 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
});
} }
/** /**

View file

@ -37,13 +37,6 @@ class ShareTest extends AbstractShareTest {
$this->share->mkdir($this->root); $this->share->mkdir($this->root);
} }
/**
* @expectedException \Icewind\SMB\Exception\DependencyException
*/
public function testAppendStream() {
$this->share->append($this->root . '/foo');
}
/** /**
* @expectedException \Icewind\SMB\Exception\ConnectException * @expectedException \Icewind\SMB\Exception\ConnectException
*/ */