mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
added append() to Wrapped/Share as proxy to Native/Share
This commit is contained in:
parent
0a9b035800
commit
1cb1f3f56a
5 changed files with 32 additions and 29 deletions
|
|
@ -325,7 +325,7 @@ class NativeShare extends AbstractShare {
|
|||
* @return INotifyHandler
|
||||
*/
|
||||
public function notify($path) {
|
||||
// php-smbclient does support notify (https://github.com/eduardok/libsmbclient-php/issues/29)
|
||||
// php-smbclient does not support notify (https://github.com/eduardok/libsmbclient-php/issues/29)
|
||||
// so we use the smbclient based backend for this
|
||||
if (!Server::available($this->server->getSystem())) {
|
||||
throw new DependencyException('smbclient not found in path for notify command');
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ use Icewind\SMB\INotifyHandler;
|
|||
use Icewind\SMB\IServer;
|
||||
use Icewind\SMB\ISystem;
|
||||
use Icewind\Streams\CallbackWrapper;
|
||||
use Icewind\SMB\Native\NativeShare;
|
||||
use Icewind\SMB\Native\NativeServer;
|
||||
|
||||
class Share extends AbstractShare {
|
||||
/**
|
||||
|
|
@ -344,14 +346,22 @@ class Share extends AbstractShare {
|
|||
}
|
||||
|
||||
/**
|
||||
* Append on wrapped smbclient not supported
|
||||
* Append to stream
|
||||
* Note: smbclient does not support it so we use php-libsmbclient
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $target
|
||||
*
|
||||
* @throws \Icewind\SMB\Exception\InvalidRequestException
|
||||
*/
|
||||
public function append($source) {
|
||||
throw new InvalidRequestException("Not supported, use Icewind\SMB\Native\NativeShare");
|
||||
* @throws \Icewind\SMB\Exception\DependencyException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function append($target) {
|
||||
if (!NativeServer::available($this->server->getSystem())) {
|
||||
throw new DependencyException('php-libsmbclient not installed');
|
||||
}
|
||||
|
||||
$share = new NativeShare($this->server, $this->getName());
|
||||
return $share->append($target);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -474,6 +474,21 @@ abstract class AbstractShareTest extends TestCase {
|
|||
unlink($tmpFile1);
|
||||
}
|
||||
|
||||
public function testAppendStream() {
|
||||
$fh = $this->share->append($this->root . '/' . $name);
|
||||
fwrite($fh, 'foo');
|
||||
fclose($fh);
|
||||
|
||||
$fh = $this->share->append($this->root . '/' . $name);
|
||||
fwrite($fh, 'bar');
|
||||
fclose($fh);
|
||||
|
||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||
$this->assertEquals('foobar', file_get_contents($tmpFile1));
|
||||
$this->share->del($this->root . '/' . $name);
|
||||
unlink($tmpFile1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
|
|
|
|||
|
|
@ -39,19 +39,4 @@ class NativeShareTest extends AbstractShareTest {
|
|||
}
|
||||
$this->share->mkdir($this->root);
|
||||
}
|
||||
|
||||
public function testAppendStream() {
|
||||
$fh = $this->share->append($this->root . '/' . $name);
|
||||
fwrite($fh, 'foo');
|
||||
fclose($fh);
|
||||
|
||||
$fh = $this->share->append($this->root . '/' . $name);
|
||||
fwrite($fh, 'bar');
|
||||
fclose($fh);
|
||||
|
||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||
$this->assertEquals('foobar', file_get_contents($tmpFile1));
|
||||
$this->share->del($this->root . '/' . $name);
|
||||
unlink($tmpFile1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,11 +57,4 @@ class ShareTest extends AbstractShareTest {
|
|||
$share = $this->server->getShare($this->config->share);
|
||||
$share->dir($this->root);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidRequestException
|
||||
*/
|
||||
public function testAppendStream() {
|
||||
$fh = $this->share->append($this->root . '/' . $name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue