diff options
author | Robin Appelman <robin@icewind.nl> | 2017-01-06 15:39:01 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-01-27 10:44:33 +0100 |
commit | 269747985e1f17ab5cafa0ff02d811433683f7e8 (patch) | |
tree | 499a75038209518b9fa24cfc1a4c53c0447ea519 /apps/files_external/lib/Lib/Storage/SMB.php | |
parent | 0aa211eefb4fd8d007f07d720825b9aa86e3c6ea (diff) | |
download | nextcloud-server-269747985e1f17ab5cafa0ff02d811433683f7e8.tar.gz nextcloud-server-269747985e1f17ab5cafa0ff02d811433683f7e8.zip |
Add a more powerful notify mechanism
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external/lib/Lib/Storage/SMB.php')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SMB.php | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 7ffc078df6f..c73288f8cc2 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -46,6 +46,9 @@ use Icewind\Streams\IteratorDirectory; use OC\Cache\CappedMemoryCache; use OC\Files\Filesystem; use OC\Files\Storage\Common; +use OCA\Files_External\Lib\Notify\SMBNotifyHandler; +use OCP\Files\Notify\IChange; +use OCP\Files\Notify\IRenameChange; use OCP\Files\Storage\INotifyStorage; use OCP\Files\StorageNotAvailableException; @@ -149,7 +152,7 @@ class SMB extends Common implements INotifyStorage { foreach ($files as $file) { $this->statCache[$path . '/' . $file->getName()] = $file; } - return array_filter($files, function(IFileInfo $file) { + return array_filter($files, function (IFileInfo $file) { return !$file->isHidden(); }); } catch (ConnectException $e) { @@ -486,48 +489,17 @@ class SMB extends Common implements INotifyStorage { } public function listen($path, callable $callback) { - $fullPath = $this->buildPath($path); - $oldRenamePath = null; - $this->share->notify($fullPath)->listen(function (Change $change) use (&$oldRenamePath, $callback) { - $path = $this->relativePath($change->getPath()); - if (is_null($path)) { - return true; - } - if ($change->getCode() === INotifyHandler::NOTIFY_RENAMED_OLD) { - $oldRenamePath = $path; - return true; - } - $type = $this->mapNotifyType($change->getCode()); - if (is_null($type)) { - return true; - } - if ($type === INotifyStorage::NOTIFY_RENAMED) { - if (!is_null($oldRenamePath)) { - $result = $callback($type, $oldRenamePath, $path); - $oldRenamePath = null; - } + $this->notify($path)->listen(function (IChange $change) use ($callback) { + if ($change instanceof IRenameChange) { + return $callback($change->getType(), $change->getPath(), $change->getTargetPath()); } else { - $result = $callback($type, $path); + return $callback($change->getType(), $change->getPath()); } - return $result; }); } - private function mapNotifyType($smbType) { - switch ($smbType) { - case INotifyHandler::NOTIFY_ADDED: - return INotifyStorage::NOTIFY_ADDED; - case INotifyHandler::NOTIFY_REMOVED: - return INotifyStorage::NOTIFY_REMOVED; - case INotifyHandler::NOTIFY_MODIFIED: - case INotifyHandler::NOTIFY_ADDED_STREAM: - case INotifyHandler::NOTIFY_MODIFIED_STREAM: - case INotifyHandler::NOTIFY_REMOVED_STREAM: - return INotifyStorage::NOTIFY_MODIFIED; - case INotifyHandler::NOTIFY_RENAMED_NEW: - return INotifyStorage::NOTIFY_RENAMED; - default: - return null; - } + public function notify($path) { + $shareNotifyHandler = $this->share->notify($this->buildPath($path)); + return new SMBNotifyHandler($shareNotifyHandler, $this->root); } } |