mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Add INotifyHandler to make notify more flexible
This commit is contained in:
parent
1bf43bf0a3
commit
8c937d6126
8 changed files with 277 additions and 20 deletions
|
|
@ -342,27 +342,18 @@ class Share extends AbstractShare {
|
|||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param callable $callback callable which will be called for each received change
|
||||
* @return mixed
|
||||
* @return INotifyHandler
|
||||
* @throws ConnectionException
|
||||
* @throws DependencyException
|
||||
*/
|
||||
public function notify($path, callable $callback) {
|
||||
public function notify($path) {
|
||||
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
|
||||
$command = 'notify ' . $this->escapePath($path);
|
||||
$connection->write($command . PHP_EOL);
|
||||
$connection->read(function ($line) use ($callback, $path) {
|
||||
$code = (int)substr($line, 0, 4);
|
||||
$subPath = str_replace('\\', '/', substr($line, 5));
|
||||
if ($path === '') {
|
||||
return $callback($code, $subPath);
|
||||
} else {
|
||||
return $callback($code, $path . '/' . $subPath);
|
||||
}
|
||||
});
|
||||
return new NotifyHandler($connection, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue