Skip to content

Commit fabffb3

Browse files
committed
Make the dependency on stdbuf optional for everything but notify
1 parent 01b6150 commit fabffb3

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Exception/DependencyException.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2016 Robin Appelman <[email protected]>
4+
* This file is licensed under the Licensed under the MIT license:
5+
* http://opensource.org/licenses/MIT
6+
*/
7+
8+
namespace Icewind\SMB\Exception;
9+
10+
class DependencyException extends Exception {
11+
}

src/Share.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Icewind\SMB;
99

1010
use Icewind\SMB\Exception\ConnectionException;
11+
use Icewind\SMB\Exception\DependencyException;
1112
use Icewind\SMB\Exception\FileInUseException;
1213
use Icewind\SMB\Exception\InvalidTypeException;
1314
use Icewind\SMB\Exception\NotFoundException;
@@ -53,7 +54,8 @@ public function __construct($server, $name) {
5354

5455
protected function getConnection() {
5556
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
56-
$command = sprintf('stdbuf -o0 %s %s --authentication-file=%s %s',
57+
$command = sprintf('%s%s %s --authentication-file=%s %s',
58+
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
5759
$this->system->getSmbclientPath(),
5860
$workgroupArgument,
5961
System::getFD(3),
@@ -353,8 +355,13 @@ public function setMode($path, $mode) {
353355
* @param string $path
354356
* @param callable $callback callable which will be called for each received change
355357
* @return mixed
358+
* @throws ConnectionException
359+
* @throws DependencyException
356360
*/
357361
public function notify($path, callable $callback) {
362+
if (!$this->system->hasStdBuf()) { //stdbuf is required to disable smbclient's output buffering
363+
throw new DependencyException('stdbuf is required for usage of the notify command');
364+
}
358365
$connection = $this->getConnection(); // use a fresh connection since the notify command blocks the process
359366
$command = 'notify ' . $this->escapePath($path);
360367
$connection->write($command . PHP_EOL);

src/System.php

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class System {
1414

1515
private $net;
1616

17+
private $stdbuf;
18+
1719
public static function getFD($num) {
1820
$folders = array(
1921
'/proc/self/fd',
@@ -40,4 +42,14 @@ public function getNetPath() {
4042
}
4143
return $this->net;
4244
}
45+
46+
public function hasStdBuf() {
47+
if (!$this->stdbuf) {
48+
$result = null;
49+
$output = [];
50+
exec('which stdbuf 2>&1', $output, $result);
51+
$this->stdbuf = $result === 0;
52+
}
53+
return $this->stdbuf;
54+
}
4355
}

0 commit comments

Comments
 (0)