mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
check for revision mismatch errors in notify
This commit is contained in:
parent
f1e17ba6e2
commit
206d6aa118
3 changed files with 34 additions and 0 deletions
|
|
@ -9,6 +9,8 @@
|
|||
namespace Icewind\SMB;
|
||||
|
||||
|
||||
use Icewind\SMB\Exception\Exception;
|
||||
|
||||
class NotifyHandler implements INotifyHandler {
|
||||
/**
|
||||
* @var Connection
|
||||
|
|
@ -22,6 +24,12 @@ class NotifyHandler implements INotifyHandler {
|
|||
|
||||
private $listening = true;
|
||||
|
||||
// todo replace with static once <5.6 support is dropped
|
||||
// see error.h
|
||||
private static $exceptionMap = [
|
||||
ErrorCodes::RevisionMismatch => '\Icewind\SMB\Exception\RevisionMismatchException',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param Connection $connection
|
||||
* @param string $path
|
||||
|
|
@ -43,6 +51,7 @@ class NotifyHandler implements INotifyHandler {
|
|||
stream_set_blocking($this->connection->getOutputStream(), 0);
|
||||
$lines = [];
|
||||
while (($line = $this->connection->readLine())) {
|
||||
$this->checkForError($line);
|
||||
$lines[] = $line;
|
||||
}
|
||||
stream_set_blocking($this->connection->getOutputStream(), 1);
|
||||
|
|
@ -59,6 +68,7 @@ class NotifyHandler implements INotifyHandler {
|
|||
public function listen($callback) {
|
||||
if ($this->listening) {
|
||||
$this->connection->read(function ($line) use ($callback) {
|
||||
$this->checkForError($line);
|
||||
$change = $this->parseChangeLine($line);
|
||||
if ($change) {
|
||||
return $callback($change);
|
||||
|
|
@ -80,6 +90,13 @@ class NotifyHandler implements INotifyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private function checkForError($line) {
|
||||
if (substr($line, 0, 16) === 'notify returned ') {
|
||||
$error = substr($line, 16);
|
||||
throw Exception::fromMap(self::$exceptionMap, $error, 'Notify is not supported with the used smb version');
|
||||
}
|
||||
}
|
||||
|
||||
public function stop() {
|
||||
$this->listening = false;
|
||||
$this->connection->close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue