mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Make the dependency on stdbuf optional for everything but notify
This commit is contained in:
parent
01b61508a7
commit
2a101e73bc
3 changed files with 31 additions and 1 deletions
11
src/Exception/DependencyException.php
Normal file
11
src/Exception/DependencyException.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2016 Robin Appelman <icewind@owncloud.com>
|
||||||
|
* This file is licensed under the Licensed under the MIT license:
|
||||||
|
* http://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Icewind\SMB\Exception;
|
||||||
|
|
||||||
|
class DependencyException extends Exception {
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Icewind\SMB;
|
namespace Icewind\SMB;
|
||||||
|
|
||||||
use Icewind\SMB\Exception\ConnectionException;
|
use Icewind\SMB\Exception\ConnectionException;
|
||||||
|
use Icewind\SMB\Exception\DependencyException;
|
||||||
use Icewind\SMB\Exception\FileInUseException;
|
use Icewind\SMB\Exception\FileInUseException;
|
||||||
use Icewind\SMB\Exception\InvalidTypeException;
|
use Icewind\SMB\Exception\InvalidTypeException;
|
||||||
use Icewind\SMB\Exception\NotFoundException;
|
use Icewind\SMB\Exception\NotFoundException;
|
||||||
|
|
@ -53,7 +54,8 @@ class Share extends AbstractShare {
|
||||||
|
|
||||||
protected function getConnection() {
|
protected function getConnection() {
|
||||||
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
|
||||||
$command = sprintf('stdbuf -o0 %s %s --authentication-file=%s %s',
|
$command = sprintf('%s%s %s --authentication-file=%s %s',
|
||||||
|
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
|
||||||
$this->system->getSmbclientPath(),
|
$this->system->getSmbclientPath(),
|
||||||
$workgroupArgument,
|
$workgroupArgument,
|
||||||
System::getFD(3),
|
System::getFD(3),
|
||||||
|
|
@ -353,8 +355,13 @@ class Share extends AbstractShare {
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param callable $callback callable which will be called for each received change
|
* @param callable $callback callable which will be called for each received change
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws ConnectionException
|
||||||
|
* @throws DependencyException
|
||||||
*/
|
*/
|
||||||
public function notify($path, callable $callback) {
|
public function notify($path, callable $callback) {
|
||||||
|
if (!$this->system->hasStdBuf()) { //stdbuf is required to disable smbclient's output buffering
|
||||||
|
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
|
||||||
$command = 'notify ' . $this->escapePath($path);
|
$command = 'notify ' . $this->escapePath($path);
|
||||||
$connection->write($command . PHP_EOL);
|
$connection->write($command . PHP_EOL);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ class System {
|
||||||
|
|
||||||
private $net;
|
private $net;
|
||||||
|
|
||||||
|
private $stdbuf;
|
||||||
|
|
||||||
public static function getFD($num) {
|
public static function getFD($num) {
|
||||||
$folders = array(
|
$folders = array(
|
||||||
'/proc/self/fd',
|
'/proc/self/fd',
|
||||||
|
|
@ -40,4 +42,14 @@ class System {
|
||||||
}
|
}
|
||||||
return $this->net;
|
return $this->net;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasStdBuf() {
|
||||||
|
if (!$this->stdbuf) {
|
||||||
|
$result = null;
|
||||||
|
$output = array();
|
||||||
|
exec('which stdbuf 2>&1', $output, $result);
|
||||||
|
$this->stdbuf = $result === 0;
|
||||||
|
}
|
||||||
|
return $this->stdbuf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue