mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
check if we can find smbclient in path
This commit is contained in:
parent
82f961896f
commit
7ddcd96e47
3 changed files with 24 additions and 3 deletions
|
|
@ -153,7 +153,7 @@ class Server {
|
||||||
* @return \Icewind\SMB\IShare
|
* @return \Icewind\SMB\IShare
|
||||||
*/
|
*/
|
||||||
public function getShare($name) {
|
public function getShare($name) {
|
||||||
return new Share($this, $name);
|
return new Share($this, $name, $this->system);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,22 @@ class Share extends AbstractShare {
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param System $system
|
||||||
*/
|
*/
|
||||||
public function __construct($server, $name) {
|
public function __construct($server, $name, System $system = null) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->system = new System();
|
$this->system = (!is_null($system)) ? $system : new System();
|
||||||
$this->parser = new Parser(new TimeZoneProvider($this->server->getHost(), $this->system));
|
$this->parser = new Parser(new TimeZoneProvider($this->server->getHost(), $this->system));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getConnection() {
|
protected function getConnection() {
|
||||||
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
||||||
|
$smbClientPath = $this->system->getSmbclientPath();
|
||||||
|
if (!$smbClientPath) {
|
||||||
|
throw new DependencyException('Can\'t find smbclient binary in path');
|
||||||
|
}
|
||||||
$command = sprintf('%s%s %s --authentication-file=%s %s',
|
$command = sprintf('%s%s %s --authentication-file=%s %s',
|
||||||
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
|
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
|
||||||
$this->system->getSmbclientPath(),
|
$this->system->getSmbclientPath(),
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,20 @@ class Share extends AbstractShare {
|
||||||
$share = $this->server->getShare($this->config->share);
|
$share = $this->server->getShare($this->config->share);
|
||||||
$share->dir($this->root);
|
$share->dir($this->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Icewind\SMB\Exception\DependencyException
|
||||||
|
*/
|
||||||
|
public function testNoSmbclient() {
|
||||||
|
$system = $this->getMockBuilder('\Icewind\SMB\System')
|
||||||
|
->setMethods(['getSmbclientPath'])
|
||||||
|
->getMock();
|
||||||
|
$share = new \Icewind\SMB\Share($this->server, 'dummy', $system);
|
||||||
|
|
||||||
|
$system->expects($this->any())
|
||||||
|
->method('getSmbclientPath')
|
||||||
|
->will($this->returnValue(''));
|
||||||
|
|
||||||
|
$share->mkdir('');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue