mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
cleanup system
This commit is contained in:
parent
2f261f868d
commit
55236aaef3
3 changed files with 18 additions and 23 deletions
|
|
@ -49,9 +49,9 @@ interface ISystem {
|
||||||
public function getNetPath();
|
public function getNetPath();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the `stdbuf` command is available in the path
|
* Get the full path to the `stdbuf` binary of false if the binary is not available
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return string|bool
|
||||||
*/
|
*/
|
||||||
public function hasStdBuf();
|
public function getStdBufPath();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@ namespace Icewind\SMB;
|
||||||
use Icewind\SMB\Exception\Exception;
|
use Icewind\SMB\Exception\Exception;
|
||||||
|
|
||||||
class System implements ISystem {
|
class System implements ISystem {
|
||||||
private $smbclient;
|
/** @var (string|bool)[] */
|
||||||
|
private $paths = [];
|
||||||
private $net;
|
|
||||||
|
|
||||||
private $stdbuf;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the path to a file descriptor of the current process
|
* Get the path to a file descriptor of the current process
|
||||||
|
|
@ -37,26 +34,24 @@ class System implements ISystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSmbclientPath() {
|
public function getSmbclientPath() {
|
||||||
if (!$this->smbclient) {
|
return $this->getBinaryPath('smbclient');
|
||||||
$this->smbclient = trim(`which smbclient`);
|
|
||||||
}
|
|
||||||
return $this->smbclient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNetPath() {
|
public function getNetPath() {
|
||||||
if (!$this->net) {
|
return $this->getBinaryPath('net');
|
||||||
$this->net = trim(`which net`);
|
|
||||||
}
|
|
||||||
return $this->net;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasStdBuf() {
|
public function getStdBufPath() {
|
||||||
if (!$this->stdbuf) {
|
return $this->getBinaryPath('stdbuf');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBinaryPath($binary) {
|
||||||
|
if (!isset($this->paths[$binary])) {
|
||||||
$result = null;
|
$result = null;
|
||||||
$output = array();
|
$output = array();
|
||||||
exec('which stdbuf 2>&1', $output, $result);
|
exec("which $binary 2>&1", $output, $result);
|
||||||
$this->stdbuf = $result === 0;
|
$this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : false;
|
||||||
}
|
}
|
||||||
return $this->stdbuf;
|
return $this->paths[$binary];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class Share extends AbstractShare {
|
||||||
|
|
||||||
protected function getConnection() {
|
protected function getConnection() {
|
||||||
$command = sprintf('%s%s -t %s %s %s %s',
|
$command = sprintf('%s%s -t %s %s %s %s',
|
||||||
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
|
$this->system->getStdBufPath() ? $this->system->getStdBufPath() . ' -o0 ' : '',
|
||||||
$this->system->getSmbclientPath(),
|
$this->system->getSmbclientPath(),
|
||||||
$this->server->getOptions()->getTimeout(),
|
$this->server->getOptions()->getTimeout(),
|
||||||
$this->getAuthFileArgument(),
|
$this->getAuthFileArgument(),
|
||||||
|
|
@ -364,7 +364,7 @@ class Share extends AbstractShare {
|
||||||
* @throws DependencyException
|
* @throws DependencyException
|
||||||
*/
|
*/
|
||||||
public function notify($path) {
|
public function notify($path) {
|
||||||
if (!$this->system->hasStdBuf()) { //stdbuf is required to disable smbclient's output buffering
|
if (!$this->system->getStdBufPath()) { //stdbuf is required to disable smbclient's output buffering
|
||||||
throw new DependencyException('stdbuf is required for usage of the notify command');
|
throw new DependencyException('stdbuf is required for usage of the notify command');
|
||||||
}
|
}
|
||||||
$connection = $this->getConnection(); // use a fresh connection since the notify command blocks the process
|
$connection = $this->getConnection(); // use a fresh connection since the notify command blocks the process
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue