diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-07-14 14:46:01 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-07-14 14:46:01 +0200 |
commit | e1fa314b18b8606ddfe219ee66b43e586b7d8651 (patch) | |
tree | 53fe18cfd8a99863b80a995fabcbb6b130b0723e /apps/files_external/lib/Lib | |
parent | 29eeeb2273782b72219c603e084a1d459514c361 (diff) | |
download | nextcloud-server-e1fa314b18b8606ddfe219ee66b43e586b7d8651.tar.gz nextcloud-server-e1fa314b18b8606ddfe219ee66b43e586b7d8651.zip |
add notify support to smb storage
Diffstat (limited to 'apps/files_external/lib/Lib')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SMB.php | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index e677f8c9eba..6a24c6b17d9 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -34,15 +34,18 @@ use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\ForbiddenException; use Icewind\SMB\Exception\NotFoundException; +use Icewind\SMB\IShare; use Icewind\SMB\NativeServer; use Icewind\SMB\Server; use Icewind\Streams\CallbackWrapper; use Icewind\Streams\IteratorDirectory; use OC\Cache\CappedMemoryCache; use OC\Files\Filesystem; +use OC\Files\Storage\Common; +use OCP\Files\Storage\INotifyStorage; use OCP\Files\StorageNotAvailableException; -class SMB extends \OC\Files\Storage\Common { +class SMB extends Common implements INotifyStorage { /** * @var \Icewind\SMB\Server */ @@ -103,6 +106,16 @@ class SMB extends \OC\Files\Storage\Common { return Filesystem::normalizePath($this->root . '/' . $path, true, false, true); } + protected function relativePath($fullPath) { + if ($fullPath === $this->root) { + return ''; + } else if (substr($fullPath, 0, strlen($this->root)) === $this->root) { + return substr($fullPath, strlen($this->root)); + } else { + return null; + } + } + /** * @param string $path * @return \Icewind\SMB\IFileInfo @@ -413,4 +426,48 @@ class SMB extends \OC\Files\Storage\Common { return false; } } + + public function listen($path, callable $callback) { + $fullPath = $this->buildPath($path); + $oldRenamePath = null; + $this->share->notify($fullPath, function ($smbType, $fullPath) use (&$oldRenamePath, $callback) { + $path = $this->relativePath($fullPath); + if (is_null($path)) { + return true; + } + if ($smbType === IShare::NOTIFY_RENAMED_OLD) { + $oldRenamePath = $path; + return true; + } + $type = $this->mapNotifyType($smbType); + if (is_null($type)) { + return true; + } + if ($type === INotifyStorage::NOTIFY_RENAMED && !is_null($oldRenamePath)) { + $result = $callback($type, $path, $oldRenamePath); + $oldRenamePath = null; + } else { + $result = $callback($type, $path); + } + return $result; + }); + } + + private function mapNotifyType($smbType) { + switch ($smbType) { + case IShare::NOTIFY_ADDED: + return INotifyStorage::NOTIFY_ADDED; + case IShare::NOTIFY_REMOVED: + return INotifyStorage::NOTIFY_REMOVED; + case IShare::NOTIFY_MODIFIED: + case IShare::NOTIFY_ADDED_STREAM: + case IShare::NOTIFY_MODIFIED_STREAM: + case IShare::NOTIFY_REMOVED_STREAM: + return INotifyStorage::NOTIFY_MODIFIED; + case IShare::NOTIFY_RENAMED_NEW: + return INotifyStorage::NOTIFY_RENAMED; + default: + return null; + } + } } |