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
|
|
@ -27,4 +27,5 @@ class ErrorCodes {
|
|||
const NotADirectory = 'NT_STATUS_NOT_A_DIRECTORY';
|
||||
const SharingViolation = 'NT_STATUS_SHARING_VIOLATION';
|
||||
const InvalidParameter = 'NT_STATUS_INVALID_PARAMETER';
|
||||
const RevisionMismatch = 'NT_STATUS_REVISION_MISMATCH';
|
||||
}
|
||||
|
|
|
|||
16
src/Exception/RevisionMismatchException.php
Normal file
16
src/Exception/RevisionMismatchException.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 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;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class RevisionMismatchException extends Exception {
|
||||
public function __construct($message = 'Protocol version mismatch', $code = 0, Throwable $previous = null) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
|
|
@ -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