@@ -29,53 +29,53 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Mount extends MountPoint implements MoveableMount { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var \OCA\Files_Sharing\External\Manager |
|
| 34 | - */ |
|
| 35 | - protected $manager; |
|
| 32 | + /** |
|
| 33 | + * @var \OCA\Files_Sharing\External\Manager |
|
| 34 | + */ |
|
| 35 | + protected $manager; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string|\OC\Files\Storage\Storage $storage |
|
| 39 | - * @param string $mountpoint |
|
| 40 | - * @param array $options |
|
| 41 | - * @param \OCA\Files_Sharing\External\Manager $manager |
|
| 42 | - * @param \OC\Files\Storage\StorageFactory $loader |
|
| 43 | - */ |
|
| 44 | - public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
| 45 | - parent::__construct($storage, $mountpoint, $options, $loader, null, null, MountProvider::class); |
|
| 46 | - $this->manager = $manager; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string|\OC\Files\Storage\Storage $storage |
|
| 39 | + * @param string $mountpoint |
|
| 40 | + * @param array $options |
|
| 41 | + * @param \OCA\Files_Sharing\External\Manager $manager |
|
| 42 | + * @param \OC\Files\Storage\StorageFactory $loader |
|
| 43 | + */ |
|
| 44 | + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
| 45 | + parent::__construct($storage, $mountpoint, $options, $loader, null, null, MountProvider::class); |
|
| 46 | + $this->manager = $manager; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Move the mount point to $target |
|
| 51 | - * |
|
| 52 | - * @param string $target the target mount point |
|
| 53 | - * @return bool |
|
| 54 | - */ |
|
| 55 | - public function moveMount($target) { |
|
| 56 | - $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
| 57 | - $this->setMountPoint($target); |
|
| 49 | + /** |
|
| 50 | + * Move the mount point to $target |
|
| 51 | + * |
|
| 52 | + * @param string $target the target mount point |
|
| 53 | + * @return bool |
|
| 54 | + */ |
|
| 55 | + public function moveMount($target) { |
|
| 56 | + $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
| 57 | + $this->setMountPoint($target); |
|
| 58 | 58 | |
| 59 | - return $result; |
|
| 60 | - } |
|
| 59 | + return $result; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Remove the mount points |
|
| 64 | - * |
|
| 65 | - * @return mixed |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public function removeMount() { |
|
| 69 | - return $this->manager->removeShare($this->mountPoint); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Remove the mount points |
|
| 64 | + * |
|
| 65 | + * @return mixed |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public function removeMount() { |
|
| 69 | + return $this->manager->removeShare($this->mountPoint); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get the type of mount point, used to distinguish things like shares and external storage |
|
| 74 | - * in the web interface |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getMountType() { |
|
| 79 | - return 'shared'; |
|
| 80 | - } |
|
| 72 | + /** |
|
| 73 | + * Get the type of mount point, used to distinguish things like shares and external storage |
|
| 74 | + * in the web interface |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getMountType() { |
|
| 79 | + return 'shared'; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -41,228 +41,228 @@ |
||
| 41 | 41 | * Shared mount points can be moved by the user |
| 42 | 42 | */ |
| 43 | 43 | class SharedMount extends MountPoint implements MoveableMount { |
| 44 | - /** |
|
| 45 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 46 | - */ |
|
| 47 | - protected $storage = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var \OC\Files\View |
|
| 51 | - */ |
|
| 52 | - private $recipientView; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - private $user; |
|
| 58 | - |
|
| 59 | - /** @var \OCP\Share\IShare */ |
|
| 60 | - private $superShare; |
|
| 61 | - |
|
| 62 | - /** @var \OCP\Share\IShare[] */ |
|
| 63 | - private $groupedShares; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param string $storage |
|
| 67 | - * @param SharedMount[] $mountpoints |
|
| 68 | - * @param array $arguments |
|
| 69 | - * @param IStorageFactory $loader |
|
| 70 | - * @param View $recipientView |
|
| 71 | - */ |
|
| 72 | - public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { |
|
| 73 | - $this->user = $arguments['user']; |
|
| 74 | - $this->recipientView = $recipientView; |
|
| 75 | - |
|
| 76 | - $this->superShare = $arguments['superShare']; |
|
| 77 | - $this->groupedShares = $arguments['groupedShares']; |
|
| 78 | - |
|
| 79 | - $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
|
| 80 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 81 | - parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * check if the parent folder exists otherwise move the mount point up |
|
| 86 | - * |
|
| 87 | - * @param \OCP\Share\IShare $share |
|
| 88 | - * @param SharedMount[] $mountpoints |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { |
|
| 92 | - $mountPoint = basename($share->getTarget()); |
|
| 93 | - $parent = dirname($share->getTarget()); |
|
| 94 | - |
|
| 95 | - $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); |
|
| 96 | - /** @var IEventDispatcher $dispatcher */ |
|
| 97 | - $dispatcher = \OC::$server->query(IEventDispatcher::class); |
|
| 98 | - $dispatcher->dispatchTyped($event); |
|
| 99 | - $parent = $event->getParent(); |
|
| 100 | - |
|
| 101 | - if ($folderExistCache->hasKey($parent)) { |
|
| 102 | - $parentExists = $folderExistCache->get($parent); |
|
| 103 | - } else { |
|
| 104 | - $parentExists = $this->recipientView->is_dir($parent); |
|
| 105 | - $folderExistCache->set($parent, $parentExists); |
|
| 106 | - } |
|
| 107 | - if (!$parentExists) { |
|
| 108 | - $parent = Helper::getShareFolder($this->recipientView, $this->user); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $newMountPoint = $this->generateUniqueTarget( |
|
| 112 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 113 | - $this->recipientView, |
|
| 114 | - $mountpoints |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - if ($newMountPoint !== $share->getTarget()) { |
|
| 118 | - $this->updateFileTarget($newMountPoint, $share); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $newMountPoint; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * update fileTarget in the database if the mount point changed |
|
| 126 | - * |
|
| 127 | - * @param string $newPath |
|
| 128 | - * @param \OCP\Share\IShare $share |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - private function updateFileTarget($newPath, &$share) { |
|
| 132 | - $share->setTarget($newPath); |
|
| 133 | - |
|
| 134 | - foreach ($this->groupedShares as $tmpShare) { |
|
| 135 | - $tmpShare->setTarget($newPath); |
|
| 136 | - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param string $path |
|
| 143 | - * @param View $view |
|
| 144 | - * @param SharedMount[] $mountpoints |
|
| 145 | - * @return mixed |
|
| 146 | - */ |
|
| 147 | - private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 148 | - $pathinfo = pathinfo($path); |
|
| 149 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 150 | - $name = $pathinfo['filename']; |
|
| 151 | - $dir = $pathinfo['dirname']; |
|
| 152 | - |
|
| 153 | - $i = 2; |
|
| 154 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 155 | - while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
|
| 156 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 157 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 158 | - $i++; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $path; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Format a path to be relative to the /user/files/ directory |
|
| 166 | - * |
|
| 167 | - * @param string $path the absolute path |
|
| 168 | - * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 169 | - * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 170 | - */ |
|
| 171 | - protected function stripUserFilesPath($path) { |
|
| 172 | - $trimmed = ltrim($path, '/'); |
|
| 173 | - $split = explode('/', $trimmed); |
|
| 174 | - |
|
| 175 | - // it is not a file relative to data/user/files |
|
| 176 | - if (count($split) < 3 || $split[1] !== 'files') { |
|
| 177 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 178 | - throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // skip 'user' and 'files' |
|
| 182 | - $sliced = array_slice($split, 2); |
|
| 183 | - $relPath = implode('/', $sliced); |
|
| 184 | - |
|
| 185 | - return '/' . $relPath; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Move the mount point to $target |
|
| 190 | - * |
|
| 191 | - * @param string $target the target mount point |
|
| 192 | - * @return bool |
|
| 193 | - */ |
|
| 194 | - public function moveMount($target) { |
|
| 195 | - $relTargetPath = $this->stripUserFilesPath($target); |
|
| 196 | - $share = $this->storage->getShare(); |
|
| 197 | - |
|
| 198 | - $result = true; |
|
| 199 | - |
|
| 200 | - try { |
|
| 201 | - $this->updateFileTarget($relTargetPath, $share); |
|
| 202 | - $this->setMountPoint($target); |
|
| 203 | - $this->storage->setMountPoint($relTargetPath); |
|
| 204 | - } catch (\Exception $e) { |
|
| 205 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $result; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Remove the mount points |
|
| 213 | - * |
|
| 214 | - * @return bool |
|
| 215 | - */ |
|
| 216 | - public function removeMount() { |
|
| 217 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 218 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 219 | - $storage = $this->getStorage(); |
|
| 220 | - $result = $storage->unshareStorage(); |
|
| 221 | - $mountManager->removeMount($this->mountPoint); |
|
| 222 | - |
|
| 223 | - return $result; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return \OCP\Share\IShare |
|
| 228 | - */ |
|
| 229 | - public function getShare() { |
|
| 230 | - return $this->superShare; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Get the file id of the root of the storage |
|
| 235 | - * |
|
| 236 | - * @return int |
|
| 237 | - */ |
|
| 238 | - public function getStorageRootId() { |
|
| 239 | - return $this->getShare()->getNodeId(); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return int |
|
| 244 | - */ |
|
| 245 | - public function getNumericStorageId() { |
|
| 246 | - if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 247 | - return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 248 | - } else { |
|
| 249 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 250 | - |
|
| 251 | - $query = $builder->select('storage') |
|
| 252 | - ->from('filecache') |
|
| 253 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 254 | - |
|
| 255 | - $result = $query->execute(); |
|
| 256 | - $row = $result->fetch(); |
|
| 257 | - $result->closeCursor(); |
|
| 258 | - if ($row) { |
|
| 259 | - return (int)$row['storage']; |
|
| 260 | - } |
|
| 261 | - return -1; |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - public function getMountType() { |
|
| 266 | - return 'shared'; |
|
| 267 | - } |
|
| 44 | + /** |
|
| 45 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 46 | + */ |
|
| 47 | + protected $storage = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var \OC\Files\View |
|
| 51 | + */ |
|
| 52 | + private $recipientView; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + private $user; |
|
| 58 | + |
|
| 59 | + /** @var \OCP\Share\IShare */ |
|
| 60 | + private $superShare; |
|
| 61 | + |
|
| 62 | + /** @var \OCP\Share\IShare[] */ |
|
| 63 | + private $groupedShares; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param string $storage |
|
| 67 | + * @param SharedMount[] $mountpoints |
|
| 68 | + * @param array $arguments |
|
| 69 | + * @param IStorageFactory $loader |
|
| 70 | + * @param View $recipientView |
|
| 71 | + */ |
|
| 72 | + public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { |
|
| 73 | + $this->user = $arguments['user']; |
|
| 74 | + $this->recipientView = $recipientView; |
|
| 75 | + |
|
| 76 | + $this->superShare = $arguments['superShare']; |
|
| 77 | + $this->groupedShares = $arguments['groupedShares']; |
|
| 78 | + |
|
| 79 | + $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
|
| 80 | + $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 81 | + parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * check if the parent folder exists otherwise move the mount point up |
|
| 86 | + * |
|
| 87 | + * @param \OCP\Share\IShare $share |
|
| 88 | + * @param SharedMount[] $mountpoints |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { |
|
| 92 | + $mountPoint = basename($share->getTarget()); |
|
| 93 | + $parent = dirname($share->getTarget()); |
|
| 94 | + |
|
| 95 | + $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); |
|
| 96 | + /** @var IEventDispatcher $dispatcher */ |
|
| 97 | + $dispatcher = \OC::$server->query(IEventDispatcher::class); |
|
| 98 | + $dispatcher->dispatchTyped($event); |
|
| 99 | + $parent = $event->getParent(); |
|
| 100 | + |
|
| 101 | + if ($folderExistCache->hasKey($parent)) { |
|
| 102 | + $parentExists = $folderExistCache->get($parent); |
|
| 103 | + } else { |
|
| 104 | + $parentExists = $this->recipientView->is_dir($parent); |
|
| 105 | + $folderExistCache->set($parent, $parentExists); |
|
| 106 | + } |
|
| 107 | + if (!$parentExists) { |
|
| 108 | + $parent = Helper::getShareFolder($this->recipientView, $this->user); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $newMountPoint = $this->generateUniqueTarget( |
|
| 112 | + \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 113 | + $this->recipientView, |
|
| 114 | + $mountpoints |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + if ($newMountPoint !== $share->getTarget()) { |
|
| 118 | + $this->updateFileTarget($newMountPoint, $share); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $newMountPoint; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * update fileTarget in the database if the mount point changed |
|
| 126 | + * |
|
| 127 | + * @param string $newPath |
|
| 128 | + * @param \OCP\Share\IShare $share |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + private function updateFileTarget($newPath, &$share) { |
|
| 132 | + $share->setTarget($newPath); |
|
| 133 | + |
|
| 134 | + foreach ($this->groupedShares as $tmpShare) { |
|
| 135 | + $tmpShare->setTarget($newPath); |
|
| 136 | + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param string $path |
|
| 143 | + * @param View $view |
|
| 144 | + * @param SharedMount[] $mountpoints |
|
| 145 | + * @return mixed |
|
| 146 | + */ |
|
| 147 | + private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 148 | + $pathinfo = pathinfo($path); |
|
| 149 | + $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 150 | + $name = $pathinfo['filename']; |
|
| 151 | + $dir = $pathinfo['dirname']; |
|
| 152 | + |
|
| 153 | + $i = 2; |
|
| 154 | + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 155 | + while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
|
| 156 | + $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 157 | + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 158 | + $i++; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $path; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Format a path to be relative to the /user/files/ directory |
|
| 166 | + * |
|
| 167 | + * @param string $path the absolute path |
|
| 168 | + * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 169 | + * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 170 | + */ |
|
| 171 | + protected function stripUserFilesPath($path) { |
|
| 172 | + $trimmed = ltrim($path, '/'); |
|
| 173 | + $split = explode('/', $trimmed); |
|
| 174 | + |
|
| 175 | + // it is not a file relative to data/user/files |
|
| 176 | + if (count($split) < 3 || $split[1] !== 'files') { |
|
| 177 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 178 | + throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // skip 'user' and 'files' |
|
| 182 | + $sliced = array_slice($split, 2); |
|
| 183 | + $relPath = implode('/', $sliced); |
|
| 184 | + |
|
| 185 | + return '/' . $relPath; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Move the mount point to $target |
|
| 190 | + * |
|
| 191 | + * @param string $target the target mount point |
|
| 192 | + * @return bool |
|
| 193 | + */ |
|
| 194 | + public function moveMount($target) { |
|
| 195 | + $relTargetPath = $this->stripUserFilesPath($target); |
|
| 196 | + $share = $this->storage->getShare(); |
|
| 197 | + |
|
| 198 | + $result = true; |
|
| 199 | + |
|
| 200 | + try { |
|
| 201 | + $this->updateFileTarget($relTargetPath, $share); |
|
| 202 | + $this->setMountPoint($target); |
|
| 203 | + $this->storage->setMountPoint($relTargetPath); |
|
| 204 | + } catch (\Exception $e) { |
|
| 205 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $result; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Remove the mount points |
|
| 213 | + * |
|
| 214 | + * @return bool |
|
| 215 | + */ |
|
| 216 | + public function removeMount() { |
|
| 217 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 218 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 219 | + $storage = $this->getStorage(); |
|
| 220 | + $result = $storage->unshareStorage(); |
|
| 221 | + $mountManager->removeMount($this->mountPoint); |
|
| 222 | + |
|
| 223 | + return $result; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return \OCP\Share\IShare |
|
| 228 | + */ |
|
| 229 | + public function getShare() { |
|
| 230 | + return $this->superShare; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Get the file id of the root of the storage |
|
| 235 | + * |
|
| 236 | + * @return int |
|
| 237 | + */ |
|
| 238 | + public function getStorageRootId() { |
|
| 239 | + return $this->getShare()->getNodeId(); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return int |
|
| 244 | + */ |
|
| 245 | + public function getNumericStorageId() { |
|
| 246 | + if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 247 | + return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 248 | + } else { |
|
| 249 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 250 | + |
|
| 251 | + $query = $builder->select('storage') |
|
| 252 | + ->from('filecache') |
|
| 253 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 254 | + |
|
| 255 | + $result = $query->execute(); |
|
| 256 | + $row = $result->fetch(); |
|
| 257 | + $result->closeCursor(); |
|
| 258 | + if ($row) { |
|
| 259 | + return (int)$row['storage']; |
|
| 260 | + } |
|
| 261 | + return -1; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + public function getMountType() { |
|
| 266 | + return 'shared'; |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $this->groupedShares = $arguments['groupedShares']; |
| 78 | 78 | |
| 79 | 79 | $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
| 80 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 80 | + $absMountPoint = '/'.$this->user.'/files'.$newMountPoint; |
|
| 81 | 81 | parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class); |
| 82 | 82 | } |
| 83 | 83 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | $newMountPoint = $this->generateUniqueTarget( |
| 112 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 112 | + \OC\Files\Filesystem::normalizePath($parent.'/'.$mountPoint), |
|
| 113 | 113 | $this->recipientView, |
| 114 | 114 | $mountpoints |
| 115 | 115 | ); |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
| 148 | 148 | $pathinfo = pathinfo($path); |
| 149 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 149 | + $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : ''; |
|
| 150 | 150 | $name = $pathinfo['filename']; |
| 151 | 151 | $dir = $pathinfo['dirname']; |
| 152 | 152 | |
| 153 | 153 | $i = 2; |
| 154 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 154 | + $absolutePath = $this->recipientView->getAbsolutePath($path).'/'; |
|
| 155 | 155 | while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
| 156 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 157 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 156 | + $path = Filesystem::normalizePath($dir.'/'.$name.' ('.$i.')'.$ext); |
|
| 157 | + $absolutePath = $this->recipientView->getAbsolutePath($path).'/'; |
|
| 158 | 158 | $i++; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | // it is not a file relative to data/user/files |
| 176 | 176 | if (count($split) < 3 || $split[1] !== 'files') { |
| 177 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 177 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: '.$path, ['app' => 'files_sharing']); |
|
| 178 | 178 | throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $sliced = array_slice($split, 2); |
| 183 | 183 | $relPath = implode('/', $sliced); |
| 184 | 184 | |
| 185 | - return '/' . $relPath; |
|
| 185 | + return '/'.$relPath; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $this->setMountPoint($target); |
| 203 | 203 | $this->storage->setMountPoint($relTargetPath); |
| 204 | 204 | } catch (\Exception $e) { |
| 205 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 205 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "'.$this->getMountPoint().'" to "'.$target.'"']); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | return $result; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | $row = $result->fetch(); |
| 257 | 257 | $result->closeCursor(); |
| 258 | 258 | if ($row) { |
| 259 | - return (int)$row['storage']; |
|
| 259 | + return (int) $row['storage']; |
|
| 260 | 260 | } |
| 261 | 261 | return -1; |
| 262 | 262 | } |
@@ -29,15 +29,15 @@ |
||
| 29 | 29 | |
| 30 | 30 | class ExternalMountPoint extends MountPoint { |
| 31 | 31 | |
| 32 | - /** @var StorageConfig */ |
|
| 33 | - protected $storageConfig; |
|
| 32 | + /** @var StorageConfig */ |
|
| 33 | + protected $storageConfig; |
|
| 34 | 34 | |
| 35 | - public function __construct(StorageConfig $storageConfig, $storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { |
|
| 36 | - $this->storageConfig = $storageConfig; |
|
| 37 | - parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, ConfigAdapter::class); |
|
| 38 | - } |
|
| 35 | + public function __construct(StorageConfig $storageConfig, $storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { |
|
| 36 | + $this->storageConfig = $storageConfig; |
|
| 37 | + parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, ConfigAdapter::class); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function getMountType() { |
|
| 41 | - return ($this->storageConfig->getAuthMechanism() instanceof SessionCredentials) ? 'external-session' : 'external'; |
|
| 42 | - } |
|
| 40 | + public function getMountType() { |
|
| 41 | + return ($this->storageConfig->getAuthMechanism() instanceof SessionCredentials) ? 'external-session' : 'external'; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -46,404 +46,404 @@ |
||
| 46 | 46 | * Cache mounts points per user in the cache so we can easilly look them up |
| 47 | 47 | */ |
| 48 | 48 | class UserMountCache implements IUserMountCache { |
| 49 | - /** |
|
| 50 | - * @var IDBConnection |
|
| 51 | - */ |
|
| 52 | - private $connection; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var IUserManager |
|
| 56 | - */ |
|
| 57 | - private $userManager; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Cached mount info. |
|
| 61 | - * Map of $userId to ICachedMountInfo. |
|
| 62 | - * |
|
| 63 | - * @var ICache |
|
| 64 | - **/ |
|
| 65 | - private $mountsForUsers; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var ILogger |
|
| 69 | - */ |
|
| 70 | - private $logger; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var ICache |
|
| 74 | - */ |
|
| 75 | - private $cacheInfoCache; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * UserMountCache constructor. |
|
| 79 | - * |
|
| 80 | - * @param IDBConnection $connection |
|
| 81 | - * @param IUserManager $userManager |
|
| 82 | - * @param ILogger $logger |
|
| 83 | - */ |
|
| 84 | - public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { |
|
| 85 | - $this->connection = $connection; |
|
| 86 | - $this->userManager = $userManager; |
|
| 87 | - $this->logger = $logger; |
|
| 88 | - $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 89 | - $this->mountsForUsers = new CappedMemoryCache(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function registerMounts(IUser $user, array $mounts) { |
|
| 93 | - // filter out non-proper storages coming from unit tests |
|
| 94 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 95 | - return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
|
| 96 | - }); |
|
| 97 | - /** @var ICachedMountInfo[] $newMounts */ |
|
| 98 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 99 | - // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
| 100 | - if ($mount->getStorageRootId() === -1) { |
|
| 101 | - return null; |
|
| 102 | - } else { |
|
| 103 | - return new LazyStorageMountInfo($user, $mount); |
|
| 104 | - } |
|
| 105 | - }, $mounts); |
|
| 106 | - $newMounts = array_values(array_filter($newMounts)); |
|
| 107 | - $newMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
| 108 | - return $mount->getRootId(); |
|
| 109 | - }, $newMounts); |
|
| 110 | - $newMounts = array_combine($newMountRootIds, $newMounts); |
|
| 111 | - |
|
| 112 | - $cachedMounts = $this->getMountsForUser($user); |
|
| 113 | - $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
| 114 | - return $mount->getRootId(); |
|
| 115 | - }, $cachedMounts); |
|
| 116 | - $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); |
|
| 117 | - |
|
| 118 | - $addedMounts = []; |
|
| 119 | - $removedMounts = []; |
|
| 120 | - |
|
| 121 | - foreach ($newMounts as $rootId => $newMount) { |
|
| 122 | - if (!isset($cachedMounts[$rootId])) { |
|
| 123 | - $addedMounts[] = $newMount; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - foreach ($cachedMounts as $rootId => $cachedMount) { |
|
| 128 | - if (!isset($newMounts[$rootId])) { |
|
| 129 | - $removedMounts[] = $cachedMount; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
| 134 | - |
|
| 135 | - foreach ($addedMounts as $mount) { |
|
| 136 | - $this->addToCache($mount); |
|
| 137 | - $this->mountsForUsers[$user->getUID()][] = $mount; |
|
| 138 | - } |
|
| 139 | - foreach ($removedMounts as $mount) { |
|
| 140 | - $this->removeFromCache($mount); |
|
| 141 | - $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
| 142 | - unset($this->mountsForUsers[$user->getUID()][$index]); |
|
| 143 | - } |
|
| 144 | - foreach ($changedMounts as $mount) { |
|
| 145 | - $this->updateCachedMount($mount); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param ICachedMountInfo[] $newMounts |
|
| 151 | - * @param ICachedMountInfo[] $cachedMounts |
|
| 152 | - * @return ICachedMountInfo[] |
|
| 153 | - */ |
|
| 154 | - private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
| 155 | - $new = []; |
|
| 156 | - foreach ($newMounts as $mount) { |
|
| 157 | - $new[$mount->getRootId()] = $mount; |
|
| 158 | - } |
|
| 159 | - $changed = []; |
|
| 160 | - foreach ($cachedMounts as $cachedMount) { |
|
| 161 | - $rootId = $cachedMount->getRootId(); |
|
| 162 | - if (isset($new[$rootId])) { |
|
| 163 | - $newMount = $new[$rootId]; |
|
| 164 | - if ( |
|
| 165 | - $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
| 166 | - $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
| 167 | - $newMount->getMountId() !== $cachedMount->getMountId() || |
|
| 168 | - $newMount->getMountProvider() !== $cachedMount->getMountProvider() |
|
| 169 | - ) { |
|
| 170 | - $changed[] = $newMount; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - return $changed; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - private function addToCache(ICachedMountInfo $mount) { |
|
| 178 | - if ($mount->getStorageId() !== -1) { |
|
| 179 | - $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
| 180 | - 'storage_id' => $mount->getStorageId(), |
|
| 181 | - 'root_id' => $mount->getRootId(), |
|
| 182 | - 'user_id' => $mount->getUser()->getUID(), |
|
| 183 | - 'mount_point' => $mount->getMountPoint(), |
|
| 184 | - 'mount_id' => $mount->getMountId(), |
|
| 185 | - 'mount_provider_class' => $mount->getMountProvider(), |
|
| 186 | - ], ['root_id', 'user_id']); |
|
| 187 | - } else { |
|
| 188 | - // in some cases this is legitimate, like orphaned shares |
|
| 189 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - private function updateCachedMount(ICachedMountInfo $mount) { |
|
| 194 | - $builder = $this->connection->getQueryBuilder(); |
|
| 195 | - |
|
| 196 | - $query = $builder->update('mounts') |
|
| 197 | - ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
| 198 | - ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
| 199 | - ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
| 200 | - ->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider())) |
|
| 201 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 202 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 203 | - |
|
| 204 | - $query->execute(); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - private function removeFromCache(ICachedMountInfo $mount) { |
|
| 208 | - $builder = $this->connection->getQueryBuilder(); |
|
| 209 | - |
|
| 210 | - $query = $builder->delete('mounts') |
|
| 211 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 212 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 213 | - $query->execute(); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - private function dbRowToMountInfo(array $row) { |
|
| 217 | - $user = $this->userManager->get($row['user_id']); |
|
| 218 | - if (is_null($user)) { |
|
| 219 | - return null; |
|
| 220 | - } |
|
| 221 | - $mount_id = $row['mount_id']; |
|
| 222 | - if (!is_null($mount_id)) { |
|
| 223 | - $mount_id = (int)$mount_id; |
|
| 224 | - } |
|
| 225 | - return new CachedMountInfo( |
|
| 226 | - $user, |
|
| 227 | - (int)$row['storage_id'], |
|
| 228 | - (int)$row['root_id'], |
|
| 229 | - $row['mount_point'], |
|
| 230 | - $row['mount_provider_class'] ?? '', |
|
| 231 | - $mount_id, |
|
| 232 | - isset($row['path']) ? $row['path'] : '', |
|
| 233 | - ); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param IUser $user |
|
| 238 | - * @return ICachedMountInfo[] |
|
| 239 | - */ |
|
| 240 | - public function getMountsForUser(IUser $user) { |
|
| 241 | - if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
| 242 | - $builder = $this->connection->getQueryBuilder(); |
|
| 243 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 244 | - ->from('mounts', 'm') |
|
| 245 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 246 | - ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
| 247 | - |
|
| 248 | - $result = $query->execute(); |
|
| 249 | - $rows = $result->fetchAll(); |
|
| 250 | - $result->closeCursor(); |
|
| 251 | - |
|
| 252 | - $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 253 | - } |
|
| 254 | - return $this->mountsForUsers[$user->getUID()]; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param int $numericStorageId |
|
| 259 | - * @param string|null $user limit the results to a single user |
|
| 260 | - * @return CachedMountInfo[] |
|
| 261 | - */ |
|
| 262 | - public function getMountsForStorageId($numericStorageId, $user = null) { |
|
| 263 | - $builder = $this->connection->getQueryBuilder(); |
|
| 264 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 265 | - ->from('mounts', 'm') |
|
| 266 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 267 | - ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
| 268 | - |
|
| 269 | - if ($user) { |
|
| 270 | - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - $result = $query->execute(); |
|
| 274 | - $rows = $result->fetchAll(); |
|
| 275 | - $result->closeCursor(); |
|
| 276 | - |
|
| 277 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param int $rootFileId |
|
| 282 | - * @return CachedMountInfo[] |
|
| 283 | - */ |
|
| 284 | - public function getMountsForRootId($rootFileId) { |
|
| 285 | - $builder = $this->connection->getQueryBuilder(); |
|
| 286 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 287 | - ->from('mounts', 'm') |
|
| 288 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 289 | - ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
| 290 | - |
|
| 291 | - $result = $query->execute(); |
|
| 292 | - $rows = $result->fetchAll(); |
|
| 293 | - $result->closeCursor(); |
|
| 294 | - |
|
| 295 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @param $fileId |
|
| 300 | - * @return array{int, string, int} |
|
| 301 | - * @throws \OCP\Files\NotFoundException |
|
| 302 | - */ |
|
| 303 | - private function getCacheInfoFromFileId($fileId): array { |
|
| 304 | - if (!isset($this->cacheInfoCache[$fileId])) { |
|
| 305 | - $builder = $this->connection->getQueryBuilder(); |
|
| 306 | - $query = $builder->select('storage', 'path', 'mimetype') |
|
| 307 | - ->from('filecache') |
|
| 308 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
| 309 | - |
|
| 310 | - $result = $query->execute(); |
|
| 311 | - $row = $result->fetch(); |
|
| 312 | - $result->closeCursor(); |
|
| 313 | - |
|
| 314 | - if (is_array($row)) { |
|
| 315 | - $this->cacheInfoCache[$fileId] = [ |
|
| 316 | - (int)$row['storage'], |
|
| 317 | - (string)$row['path'], |
|
| 318 | - (int)$row['mimetype'] |
|
| 319 | - ]; |
|
| 320 | - } else { |
|
| 321 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - return $this->cacheInfoCache[$fileId]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @param int $fileId |
|
| 329 | - * @param string|null $user optionally restrict the results to a single user |
|
| 330 | - * @return ICachedMountFileInfo[] |
|
| 331 | - * @since 9.0.0 |
|
| 332 | - */ |
|
| 333 | - public function getMountsForFileId($fileId, $user = null) { |
|
| 334 | - try { |
|
| 335 | - [$storageId, $internalPath] = $this->getCacheInfoFromFileId($fileId); |
|
| 336 | - } catch (NotFoundException $e) { |
|
| 337 | - return []; |
|
| 338 | - } |
|
| 339 | - $builder = $this->connection->getQueryBuilder(); |
|
| 340 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 341 | - ->from('mounts', 'm') |
|
| 342 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 343 | - ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 344 | - |
|
| 345 | - if ($user) { |
|
| 346 | - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $result = $query->execute(); |
|
| 350 | - $rows = $result->fetchAll(); |
|
| 351 | - $result->closeCursor(); |
|
| 352 | - // filter mounts that are from the same storage but a different directory |
|
| 353 | - $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { |
|
| 354 | - if ($fileId === (int)$row['root_id']) { |
|
| 355 | - return true; |
|
| 356 | - } |
|
| 357 | - $internalMountPath = $row['path'] ?? ''; |
|
| 358 | - |
|
| 359 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 360 | - }); |
|
| 361 | - |
|
| 362 | - $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); |
|
| 363 | - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
| 364 | - return new CachedMountFileInfo( |
|
| 365 | - $mount->getUser(), |
|
| 366 | - $mount->getStorageId(), |
|
| 367 | - $mount->getRootId(), |
|
| 368 | - $mount->getMountPoint(), |
|
| 369 | - $mount->getMountId(), |
|
| 370 | - $mount->getMountProvider(), |
|
| 371 | - $mount->getRootInternalPath(), |
|
| 372 | - $internalPath |
|
| 373 | - ); |
|
| 374 | - }, $filteredMounts); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Remove all cached mounts for a user |
|
| 379 | - * |
|
| 380 | - * @param IUser $user |
|
| 381 | - */ |
|
| 382 | - public function removeUserMounts(IUser $user) { |
|
| 383 | - $builder = $this->connection->getQueryBuilder(); |
|
| 384 | - |
|
| 385 | - $query = $builder->delete('mounts') |
|
| 386 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
| 387 | - $query->execute(); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - public function removeUserStorageMount($storageId, $userId) { |
|
| 391 | - $builder = $this->connection->getQueryBuilder(); |
|
| 392 | - |
|
| 393 | - $query = $builder->delete('mounts') |
|
| 394 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
| 395 | - ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 396 | - $query->execute(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - public function remoteStorageMounts($storageId) { |
|
| 400 | - $builder = $this->connection->getQueryBuilder(); |
|
| 401 | - |
|
| 402 | - $query = $builder->delete('mounts') |
|
| 403 | - ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 404 | - $query->execute(); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @param array $users |
|
| 409 | - * @return array |
|
| 410 | - */ |
|
| 411 | - public function getUsedSpaceForUsers(array $users) { |
|
| 412 | - $builder = $this->connection->getQueryBuilder(); |
|
| 413 | - |
|
| 414 | - $slash = $builder->createNamedParameter('/'); |
|
| 415 | - |
|
| 416 | - $mountPoint = $builder->func()->concat( |
|
| 417 | - $builder->func()->concat($slash, 'user_id'), |
|
| 418 | - $slash |
|
| 419 | - ); |
|
| 420 | - |
|
| 421 | - $userIds = array_map(function (IUser $user) { |
|
| 422 | - return $user->getUID(); |
|
| 423 | - }, $users); |
|
| 424 | - |
|
| 425 | - $query = $builder->select('m.user_id', 'f.size') |
|
| 426 | - ->from('mounts', 'm') |
|
| 427 | - ->innerJoin('m', 'filecache', 'f', |
|
| 428 | - $builder->expr()->andX( |
|
| 429 | - $builder->expr()->eq('m.storage_id', 'f.storage'), |
|
| 430 | - $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files'))) |
|
| 431 | - )) |
|
| 432 | - ->where($builder->expr()->eq('m.mount_point', $mountPoint)) |
|
| 433 | - ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 434 | - |
|
| 435 | - $result = $query->execute(); |
|
| 436 | - |
|
| 437 | - $results = []; |
|
| 438 | - while ($row = $result->fetch()) { |
|
| 439 | - $results[$row['user_id']] = $row['size']; |
|
| 440 | - } |
|
| 441 | - $result->closeCursor(); |
|
| 442 | - return $results; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - public function clear(): void { |
|
| 446 | - $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 447 | - $this->mountsForUsers = new CappedMemoryCache(); |
|
| 448 | - } |
|
| 49 | + /** |
|
| 50 | + * @var IDBConnection |
|
| 51 | + */ |
|
| 52 | + private $connection; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var IUserManager |
|
| 56 | + */ |
|
| 57 | + private $userManager; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Cached mount info. |
|
| 61 | + * Map of $userId to ICachedMountInfo. |
|
| 62 | + * |
|
| 63 | + * @var ICache |
|
| 64 | + **/ |
|
| 65 | + private $mountsForUsers; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var ILogger |
|
| 69 | + */ |
|
| 70 | + private $logger; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var ICache |
|
| 74 | + */ |
|
| 75 | + private $cacheInfoCache; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * UserMountCache constructor. |
|
| 79 | + * |
|
| 80 | + * @param IDBConnection $connection |
|
| 81 | + * @param IUserManager $userManager |
|
| 82 | + * @param ILogger $logger |
|
| 83 | + */ |
|
| 84 | + public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { |
|
| 85 | + $this->connection = $connection; |
|
| 86 | + $this->userManager = $userManager; |
|
| 87 | + $this->logger = $logger; |
|
| 88 | + $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 89 | + $this->mountsForUsers = new CappedMemoryCache(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function registerMounts(IUser $user, array $mounts) { |
|
| 93 | + // filter out non-proper storages coming from unit tests |
|
| 94 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 95 | + return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
|
| 96 | + }); |
|
| 97 | + /** @var ICachedMountInfo[] $newMounts */ |
|
| 98 | + $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 99 | + // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
| 100 | + if ($mount->getStorageRootId() === -1) { |
|
| 101 | + return null; |
|
| 102 | + } else { |
|
| 103 | + return new LazyStorageMountInfo($user, $mount); |
|
| 104 | + } |
|
| 105 | + }, $mounts); |
|
| 106 | + $newMounts = array_values(array_filter($newMounts)); |
|
| 107 | + $newMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
| 108 | + return $mount->getRootId(); |
|
| 109 | + }, $newMounts); |
|
| 110 | + $newMounts = array_combine($newMountRootIds, $newMounts); |
|
| 111 | + |
|
| 112 | + $cachedMounts = $this->getMountsForUser($user); |
|
| 113 | + $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
| 114 | + return $mount->getRootId(); |
|
| 115 | + }, $cachedMounts); |
|
| 116 | + $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); |
|
| 117 | + |
|
| 118 | + $addedMounts = []; |
|
| 119 | + $removedMounts = []; |
|
| 120 | + |
|
| 121 | + foreach ($newMounts as $rootId => $newMount) { |
|
| 122 | + if (!isset($cachedMounts[$rootId])) { |
|
| 123 | + $addedMounts[] = $newMount; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + foreach ($cachedMounts as $rootId => $cachedMount) { |
|
| 128 | + if (!isset($newMounts[$rootId])) { |
|
| 129 | + $removedMounts[] = $cachedMount; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
| 134 | + |
|
| 135 | + foreach ($addedMounts as $mount) { |
|
| 136 | + $this->addToCache($mount); |
|
| 137 | + $this->mountsForUsers[$user->getUID()][] = $mount; |
|
| 138 | + } |
|
| 139 | + foreach ($removedMounts as $mount) { |
|
| 140 | + $this->removeFromCache($mount); |
|
| 141 | + $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
| 142 | + unset($this->mountsForUsers[$user->getUID()][$index]); |
|
| 143 | + } |
|
| 144 | + foreach ($changedMounts as $mount) { |
|
| 145 | + $this->updateCachedMount($mount); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param ICachedMountInfo[] $newMounts |
|
| 151 | + * @param ICachedMountInfo[] $cachedMounts |
|
| 152 | + * @return ICachedMountInfo[] |
|
| 153 | + */ |
|
| 154 | + private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
| 155 | + $new = []; |
|
| 156 | + foreach ($newMounts as $mount) { |
|
| 157 | + $new[$mount->getRootId()] = $mount; |
|
| 158 | + } |
|
| 159 | + $changed = []; |
|
| 160 | + foreach ($cachedMounts as $cachedMount) { |
|
| 161 | + $rootId = $cachedMount->getRootId(); |
|
| 162 | + if (isset($new[$rootId])) { |
|
| 163 | + $newMount = $new[$rootId]; |
|
| 164 | + if ( |
|
| 165 | + $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
| 166 | + $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
| 167 | + $newMount->getMountId() !== $cachedMount->getMountId() || |
|
| 168 | + $newMount->getMountProvider() !== $cachedMount->getMountProvider() |
|
| 169 | + ) { |
|
| 170 | + $changed[] = $newMount; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + return $changed; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + private function addToCache(ICachedMountInfo $mount) { |
|
| 178 | + if ($mount->getStorageId() !== -1) { |
|
| 179 | + $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
| 180 | + 'storage_id' => $mount->getStorageId(), |
|
| 181 | + 'root_id' => $mount->getRootId(), |
|
| 182 | + 'user_id' => $mount->getUser()->getUID(), |
|
| 183 | + 'mount_point' => $mount->getMountPoint(), |
|
| 184 | + 'mount_id' => $mount->getMountId(), |
|
| 185 | + 'mount_provider_class' => $mount->getMountProvider(), |
|
| 186 | + ], ['root_id', 'user_id']); |
|
| 187 | + } else { |
|
| 188 | + // in some cases this is legitimate, like orphaned shares |
|
| 189 | + $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + private function updateCachedMount(ICachedMountInfo $mount) { |
|
| 194 | + $builder = $this->connection->getQueryBuilder(); |
|
| 195 | + |
|
| 196 | + $query = $builder->update('mounts') |
|
| 197 | + ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
| 198 | + ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
| 199 | + ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
| 200 | + ->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider())) |
|
| 201 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 202 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 203 | + |
|
| 204 | + $query->execute(); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + private function removeFromCache(ICachedMountInfo $mount) { |
|
| 208 | + $builder = $this->connection->getQueryBuilder(); |
|
| 209 | + |
|
| 210 | + $query = $builder->delete('mounts') |
|
| 211 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
| 212 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
| 213 | + $query->execute(); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + private function dbRowToMountInfo(array $row) { |
|
| 217 | + $user = $this->userManager->get($row['user_id']); |
|
| 218 | + if (is_null($user)) { |
|
| 219 | + return null; |
|
| 220 | + } |
|
| 221 | + $mount_id = $row['mount_id']; |
|
| 222 | + if (!is_null($mount_id)) { |
|
| 223 | + $mount_id = (int)$mount_id; |
|
| 224 | + } |
|
| 225 | + return new CachedMountInfo( |
|
| 226 | + $user, |
|
| 227 | + (int)$row['storage_id'], |
|
| 228 | + (int)$row['root_id'], |
|
| 229 | + $row['mount_point'], |
|
| 230 | + $row['mount_provider_class'] ?? '', |
|
| 231 | + $mount_id, |
|
| 232 | + isset($row['path']) ? $row['path'] : '', |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param IUser $user |
|
| 238 | + * @return ICachedMountInfo[] |
|
| 239 | + */ |
|
| 240 | + public function getMountsForUser(IUser $user) { |
|
| 241 | + if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
| 242 | + $builder = $this->connection->getQueryBuilder(); |
|
| 243 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 244 | + ->from('mounts', 'm') |
|
| 245 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 246 | + ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
| 247 | + |
|
| 248 | + $result = $query->execute(); |
|
| 249 | + $rows = $result->fetchAll(); |
|
| 250 | + $result->closeCursor(); |
|
| 251 | + |
|
| 252 | + $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 253 | + } |
|
| 254 | + return $this->mountsForUsers[$user->getUID()]; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param int $numericStorageId |
|
| 259 | + * @param string|null $user limit the results to a single user |
|
| 260 | + * @return CachedMountInfo[] |
|
| 261 | + */ |
|
| 262 | + public function getMountsForStorageId($numericStorageId, $user = null) { |
|
| 263 | + $builder = $this->connection->getQueryBuilder(); |
|
| 264 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 265 | + ->from('mounts', 'm') |
|
| 266 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 267 | + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
| 268 | + |
|
| 269 | + if ($user) { |
|
| 270 | + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + $result = $query->execute(); |
|
| 274 | + $rows = $result->fetchAll(); |
|
| 275 | + $result->closeCursor(); |
|
| 276 | + |
|
| 277 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param int $rootFileId |
|
| 282 | + * @return CachedMountInfo[] |
|
| 283 | + */ |
|
| 284 | + public function getMountsForRootId($rootFileId) { |
|
| 285 | + $builder = $this->connection->getQueryBuilder(); |
|
| 286 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 287 | + ->from('mounts', 'm') |
|
| 288 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 289 | + ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
| 290 | + |
|
| 291 | + $result = $query->execute(); |
|
| 292 | + $rows = $result->fetchAll(); |
|
| 293 | + $result->closeCursor(); |
|
| 294 | + |
|
| 295 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @param $fileId |
|
| 300 | + * @return array{int, string, int} |
|
| 301 | + * @throws \OCP\Files\NotFoundException |
|
| 302 | + */ |
|
| 303 | + private function getCacheInfoFromFileId($fileId): array { |
|
| 304 | + if (!isset($this->cacheInfoCache[$fileId])) { |
|
| 305 | + $builder = $this->connection->getQueryBuilder(); |
|
| 306 | + $query = $builder->select('storage', 'path', 'mimetype') |
|
| 307 | + ->from('filecache') |
|
| 308 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
| 309 | + |
|
| 310 | + $result = $query->execute(); |
|
| 311 | + $row = $result->fetch(); |
|
| 312 | + $result->closeCursor(); |
|
| 313 | + |
|
| 314 | + if (is_array($row)) { |
|
| 315 | + $this->cacheInfoCache[$fileId] = [ |
|
| 316 | + (int)$row['storage'], |
|
| 317 | + (string)$row['path'], |
|
| 318 | + (int)$row['mimetype'] |
|
| 319 | + ]; |
|
| 320 | + } else { |
|
| 321 | + throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + return $this->cacheInfoCache[$fileId]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @param int $fileId |
|
| 329 | + * @param string|null $user optionally restrict the results to a single user |
|
| 330 | + * @return ICachedMountFileInfo[] |
|
| 331 | + * @since 9.0.0 |
|
| 332 | + */ |
|
| 333 | + public function getMountsForFileId($fileId, $user = null) { |
|
| 334 | + try { |
|
| 335 | + [$storageId, $internalPath] = $this->getCacheInfoFromFileId($fileId); |
|
| 336 | + } catch (NotFoundException $e) { |
|
| 337 | + return []; |
|
| 338 | + } |
|
| 339 | + $builder = $this->connection->getQueryBuilder(); |
|
| 340 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') |
|
| 341 | + ->from('mounts', 'm') |
|
| 342 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
| 343 | + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 344 | + |
|
| 345 | + if ($user) { |
|
| 346 | + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $result = $query->execute(); |
|
| 350 | + $rows = $result->fetchAll(); |
|
| 351 | + $result->closeCursor(); |
|
| 352 | + // filter mounts that are from the same storage but a different directory |
|
| 353 | + $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { |
|
| 354 | + if ($fileId === (int)$row['root_id']) { |
|
| 355 | + return true; |
|
| 356 | + } |
|
| 357 | + $internalMountPath = $row['path'] ?? ''; |
|
| 358 | + |
|
| 359 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 360 | + }); |
|
| 361 | + |
|
| 362 | + $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); |
|
| 363 | + return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
| 364 | + return new CachedMountFileInfo( |
|
| 365 | + $mount->getUser(), |
|
| 366 | + $mount->getStorageId(), |
|
| 367 | + $mount->getRootId(), |
|
| 368 | + $mount->getMountPoint(), |
|
| 369 | + $mount->getMountId(), |
|
| 370 | + $mount->getMountProvider(), |
|
| 371 | + $mount->getRootInternalPath(), |
|
| 372 | + $internalPath |
|
| 373 | + ); |
|
| 374 | + }, $filteredMounts); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Remove all cached mounts for a user |
|
| 379 | + * |
|
| 380 | + * @param IUser $user |
|
| 381 | + */ |
|
| 382 | + public function removeUserMounts(IUser $user) { |
|
| 383 | + $builder = $this->connection->getQueryBuilder(); |
|
| 384 | + |
|
| 385 | + $query = $builder->delete('mounts') |
|
| 386 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
| 387 | + $query->execute(); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + public function removeUserStorageMount($storageId, $userId) { |
|
| 391 | + $builder = $this->connection->getQueryBuilder(); |
|
| 392 | + |
|
| 393 | + $query = $builder->delete('mounts') |
|
| 394 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
| 395 | + ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 396 | + $query->execute(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + public function remoteStorageMounts($storageId) { |
|
| 400 | + $builder = $this->connection->getQueryBuilder(); |
|
| 401 | + |
|
| 402 | + $query = $builder->delete('mounts') |
|
| 403 | + ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
| 404 | + $query->execute(); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @param array $users |
|
| 409 | + * @return array |
|
| 410 | + */ |
|
| 411 | + public function getUsedSpaceForUsers(array $users) { |
|
| 412 | + $builder = $this->connection->getQueryBuilder(); |
|
| 413 | + |
|
| 414 | + $slash = $builder->createNamedParameter('/'); |
|
| 415 | + |
|
| 416 | + $mountPoint = $builder->func()->concat( |
|
| 417 | + $builder->func()->concat($slash, 'user_id'), |
|
| 418 | + $slash |
|
| 419 | + ); |
|
| 420 | + |
|
| 421 | + $userIds = array_map(function (IUser $user) { |
|
| 422 | + return $user->getUID(); |
|
| 423 | + }, $users); |
|
| 424 | + |
|
| 425 | + $query = $builder->select('m.user_id', 'f.size') |
|
| 426 | + ->from('mounts', 'm') |
|
| 427 | + ->innerJoin('m', 'filecache', 'f', |
|
| 428 | + $builder->expr()->andX( |
|
| 429 | + $builder->expr()->eq('m.storage_id', 'f.storage'), |
|
| 430 | + $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files'))) |
|
| 431 | + )) |
|
| 432 | + ->where($builder->expr()->eq('m.mount_point', $mountPoint)) |
|
| 433 | + ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 434 | + |
|
| 435 | + $result = $query->execute(); |
|
| 436 | + |
|
| 437 | + $results = []; |
|
| 438 | + while ($row = $result->fetch()) { |
|
| 439 | + $results[$row['user_id']] = $row['size']; |
|
| 440 | + } |
|
| 441 | + $result->closeCursor(); |
|
| 442 | + return $results; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + public function clear(): void { |
|
| 446 | + $this->cacheInfoCache = new CappedMemoryCache(); |
|
| 447 | + $this->mountsForUsers = new CappedMemoryCache(); |
|
| 448 | + } |
|
| 449 | 449 | } |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function registerMounts(IUser $user, array $mounts) { |
| 93 | 93 | // filter out non-proper storages coming from unit tests |
| 94 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 94 | + $mounts = array_filter($mounts, function(IMountPoint $mount) { |
|
| 95 | 95 | return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
| 96 | 96 | }); |
| 97 | 97 | /** @var ICachedMountInfo[] $newMounts */ |
| 98 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
| 98 | + $newMounts = array_map(function(IMountPoint $mount) use ($user) { |
|
| 99 | 99 | // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
| 100 | 100 | if ($mount->getStorageRootId() === -1) { |
| 101 | 101 | return null; |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | }, $mounts); |
| 106 | 106 | $newMounts = array_values(array_filter($newMounts)); |
| 107 | - $newMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
| 107 | + $newMountRootIds = array_map(function(ICachedMountInfo $mount) { |
|
| 108 | 108 | return $mount->getRootId(); |
| 109 | 109 | }, $newMounts); |
| 110 | 110 | $newMounts = array_combine($newMountRootIds, $newMounts); |
| 111 | 111 | |
| 112 | 112 | $cachedMounts = $this->getMountsForUser($user); |
| 113 | - $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
| 113 | + $cachedMountRootIds = array_map(function(ICachedMountInfo $mount) { |
|
| 114 | 114 | return $mount->getRootId(); |
| 115 | 115 | }, $cachedMounts); |
| 116 | 116 | $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | ], ['root_id', 'user_id']); |
| 187 | 187 | } else { |
| 188 | 188 | // in some cases this is legitimate, like orphaned shares |
| 189 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
| 189 | + $this->logger->debug('Could not get storage info for mount at '.$mount->getMountPoint()); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | $mount_id = $row['mount_id']; |
| 222 | 222 | if (!is_null($mount_id)) { |
| 223 | - $mount_id = (int)$mount_id; |
|
| 223 | + $mount_id = (int) $mount_id; |
|
| 224 | 224 | } |
| 225 | 225 | return new CachedMountInfo( |
| 226 | 226 | $user, |
| 227 | - (int)$row['storage_id'], |
|
| 228 | - (int)$row['root_id'], |
|
| 227 | + (int) $row['storage_id'], |
|
| 228 | + (int) $row['root_id'], |
|
| 229 | 229 | $row['mount_point'], |
| 230 | 230 | $row['mount_provider_class'] ?? '', |
| 231 | 231 | $mount_id, |
@@ -313,12 +313,12 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | if (is_array($row)) { |
| 315 | 315 | $this->cacheInfoCache[$fileId] = [ |
| 316 | - (int)$row['storage'], |
|
| 317 | - (string)$row['path'], |
|
| 318 | - (int)$row['mimetype'] |
|
| 316 | + (int) $row['storage'], |
|
| 317 | + (string) $row['path'], |
|
| 318 | + (int) $row['mimetype'] |
|
| 319 | 319 | ]; |
| 320 | 320 | } else { |
| 321 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
| 321 | + throw new NotFoundException('File with id "'.$fileId.'" not found'); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | return $this->cacheInfoCache[$fileId]; |
@@ -350,17 +350,17 @@ discard block |
||
| 350 | 350 | $rows = $result->fetchAll(); |
| 351 | 351 | $result->closeCursor(); |
| 352 | 352 | // filter mounts that are from the same storage but a different directory |
| 353 | - $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { |
|
| 354 | - if ($fileId === (int)$row['root_id']) { |
|
| 353 | + $filteredMounts = array_filter($rows, function(array $row) use ($internalPath, $fileId) { |
|
| 354 | + if ($fileId === (int) $row['root_id']) { |
|
| 355 | 355 | return true; |
| 356 | 356 | } |
| 357 | 357 | $internalMountPath = $row['path'] ?? ''; |
| 358 | 358 | |
| 359 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
| 359 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath.'/'; |
|
| 360 | 360 | }); |
| 361 | 361 | |
| 362 | 362 | $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); |
| 363 | - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
| 363 | + return array_map(function(ICachedMountInfo $mount) use ($internalPath) { |
|
| 364 | 364 | return new CachedMountFileInfo( |
| 365 | 365 | $mount->getUser(), |
| 366 | 366 | $mount->getStorageId(), |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | $slash |
| 419 | 419 | ); |
| 420 | 420 | |
| 421 | - $userIds = array_map(function (IUser $user) { |
|
| 421 | + $userIds = array_map(function(IUser $user) { |
|
| 422 | 422 | return $user->getUID(); |
| 423 | 423 | }, $users); |
| 424 | 424 | |
@@ -25,64 +25,64 @@ |
||
| 25 | 25 | use OCP\IUser; |
| 26 | 26 | |
| 27 | 27 | class LazyStorageMountInfo extends CachedMountInfo { |
| 28 | - /** @var IMountPoint */ |
|
| 29 | - private $mount; |
|
| 28 | + /** @var IMountPoint */ |
|
| 29 | + private $mount; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * CachedMountInfo constructor. |
|
| 33 | - * |
|
| 34 | - * @param IUser $user |
|
| 35 | - * @param IMountPoint $mount |
|
| 36 | - */ |
|
| 37 | - public function __construct(IUser $user, IMountPoint $mount) { |
|
| 38 | - $this->user = $user; |
|
| 39 | - $this->mount = $mount; |
|
| 40 | - } |
|
| 31 | + /** |
|
| 32 | + * CachedMountInfo constructor. |
|
| 33 | + * |
|
| 34 | + * @param IUser $user |
|
| 35 | + * @param IMountPoint $mount |
|
| 36 | + */ |
|
| 37 | + public function __construct(IUser $user, IMountPoint $mount) { |
|
| 38 | + $this->user = $user; |
|
| 39 | + $this->mount = $mount; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return int the numeric storage id of the mount |
|
| 44 | - */ |
|
| 45 | - public function getStorageId() { |
|
| 46 | - if (!$this->storageId) { |
|
| 47 | - $this->storageId = $this->mount->getNumericStorageId(); |
|
| 48 | - } |
|
| 49 | - return parent::getStorageId(); |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * @return int the numeric storage id of the mount |
|
| 44 | + */ |
|
| 45 | + public function getStorageId() { |
|
| 46 | + if (!$this->storageId) { |
|
| 47 | + $this->storageId = $this->mount->getNumericStorageId(); |
|
| 48 | + } |
|
| 49 | + return parent::getStorageId(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return int the fileid of the root of the mount |
|
| 54 | - */ |
|
| 55 | - public function getRootId() { |
|
| 56 | - if (!$this->rootId) { |
|
| 57 | - $this->rootId = $this->mount->getStorageRootId(); |
|
| 58 | - } |
|
| 59 | - return parent::getRootId(); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * @return int the fileid of the root of the mount |
|
| 54 | + */ |
|
| 55 | + public function getRootId() { |
|
| 56 | + if (!$this->rootId) { |
|
| 57 | + $this->rootId = $this->mount->getStorageRootId(); |
|
| 58 | + } |
|
| 59 | + return parent::getRootId(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return string the mount point of the mount for the user |
|
| 64 | - */ |
|
| 65 | - public function getMountPoint() { |
|
| 66 | - if (!$this->mountPoint) { |
|
| 67 | - $this->mountPoint = $this->mount->getMountPoint(); |
|
| 68 | - } |
|
| 69 | - return parent::getMountPoint(); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * @return string the mount point of the mount for the user |
|
| 64 | + */ |
|
| 65 | + public function getMountPoint() { |
|
| 66 | + if (!$this->mountPoint) { |
|
| 67 | + $this->mountPoint = $this->mount->getMountPoint(); |
|
| 68 | + } |
|
| 69 | + return parent::getMountPoint(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function getMountId() { |
|
| 73 | - return $this->mount->getMountId(); |
|
| 74 | - } |
|
| 72 | + public function getMountId() { |
|
| 73 | + return $this->mount->getMountId(); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Get the internal path (within the storage) of the root of the mount |
|
| 78 | - * |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function getRootInternalPath() { |
|
| 82 | - return $this->mount->getInternalPath($this->mount->getMountPoint()); |
|
| 83 | - } |
|
| 76 | + /** |
|
| 77 | + * Get the internal path (within the storage) of the root of the mount |
|
| 78 | + * |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function getRootInternalPath() { |
|
| 82 | + return $this->mount->getInternalPath($this->mount->getMountPoint()); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function getMountProvider(): string { |
|
| 86 | - return $this->mount->getMountProvider(); |
|
| 87 | - } |
|
| 85 | + public function getMountProvider(): string { |
|
| 86 | + return $this->mount->getMountProvider(); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -28,133 +28,133 @@ |
||
| 28 | 28 | use OCP\IUser; |
| 29 | 29 | |
| 30 | 30 | class CachedMountInfo implements ICachedMountInfo { |
| 31 | - /** |
|
| 32 | - * @var IUser |
|
| 33 | - */ |
|
| 34 | - protected $user; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var int |
|
| 38 | - */ |
|
| 39 | - protected $storageId; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var int |
|
| 43 | - */ |
|
| 44 | - protected $rootId; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $mountPoint; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var int|null |
|
| 53 | - */ |
|
| 54 | - protected $mountId; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $rootInternalPath; |
|
| 60 | - |
|
| 61 | - /** @var string */ |
|
| 62 | - protected $mountProvider; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * CachedMountInfo constructor. |
|
| 66 | - * |
|
| 67 | - * @param IUser $user |
|
| 68 | - * @param int $storageId |
|
| 69 | - * @param int $rootId |
|
| 70 | - * @param string $mountPoint |
|
| 71 | - * @param int|null $mountId |
|
| 72 | - * @param string $rootInternalPath |
|
| 73 | - */ |
|
| 74 | - public function __construct( |
|
| 75 | - IUser $user, |
|
| 76 | - int $storageId, |
|
| 77 | - int $rootId, |
|
| 78 | - string $mountPoint, |
|
| 79 | - string $mountProvider, |
|
| 80 | - int $mountId = null, |
|
| 81 | - string $rootInternalPath = '' |
|
| 82 | - ) { |
|
| 83 | - $this->user = $user; |
|
| 84 | - $this->storageId = $storageId; |
|
| 85 | - $this->rootId = $rootId; |
|
| 86 | - $this->mountPoint = $mountPoint; |
|
| 87 | - $this->mountId = $mountId; |
|
| 88 | - $this->rootInternalPath = $rootInternalPath; |
|
| 89 | - if (strlen($mountProvider) > 128) { |
|
| 90 | - throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters"); |
|
| 91 | - } |
|
| 92 | - $this->mountProvider = $mountProvider; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return IUser |
|
| 97 | - */ |
|
| 98 | - public function getUser() { |
|
| 99 | - return $this->user; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return int the numeric storage id of the mount |
|
| 104 | - */ |
|
| 105 | - public function getStorageId() { |
|
| 106 | - return $this->storageId; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return int the fileid of the root of the mount |
|
| 111 | - */ |
|
| 112 | - public function getRootId() { |
|
| 113 | - return $this->rootId; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @return Node the root node of the mount |
|
| 118 | - */ |
|
| 119 | - public function getMountPointNode() { |
|
| 120 | - // TODO injection etc |
|
| 121 | - Filesystem::initMountPoints($this->getUser()->getUID()); |
|
| 122 | - $userNode = \OC::$server->getUserFolder($this->getUser()->getUID()); |
|
| 123 | - $nodes = $userNode->getParent()->getById($this->getRootId()); |
|
| 124 | - if (count($nodes) > 0) { |
|
| 125 | - return $nodes[0]; |
|
| 126 | - } else { |
|
| 127 | - return null; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return string the mount point of the mount for the user |
|
| 133 | - */ |
|
| 134 | - public function getMountPoint() { |
|
| 135 | - return $this->mountPoint; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Get the id of the configured mount |
|
| 140 | - * |
|
| 141 | - * @return int|null mount id or null if not applicable |
|
| 142 | - * @since 9.1.0 |
|
| 143 | - */ |
|
| 144 | - public function getMountId() { |
|
| 145 | - return $this->mountId; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Get the internal path (within the storage) of the root of the mount |
|
| 150 | - * |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function getRootInternalPath() { |
|
| 154 | - return $this->rootInternalPath; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function getMountProvider(): string { |
|
| 158 | - return $this->mountProvider; |
|
| 159 | - } |
|
| 31 | + /** |
|
| 32 | + * @var IUser |
|
| 33 | + */ |
|
| 34 | + protected $user; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var int |
|
| 38 | + */ |
|
| 39 | + protected $storageId; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var int |
|
| 43 | + */ |
|
| 44 | + protected $rootId; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $mountPoint; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var int|null |
|
| 53 | + */ |
|
| 54 | + protected $mountId; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $rootInternalPath; |
|
| 60 | + |
|
| 61 | + /** @var string */ |
|
| 62 | + protected $mountProvider; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * CachedMountInfo constructor. |
|
| 66 | + * |
|
| 67 | + * @param IUser $user |
|
| 68 | + * @param int $storageId |
|
| 69 | + * @param int $rootId |
|
| 70 | + * @param string $mountPoint |
|
| 71 | + * @param int|null $mountId |
|
| 72 | + * @param string $rootInternalPath |
|
| 73 | + */ |
|
| 74 | + public function __construct( |
|
| 75 | + IUser $user, |
|
| 76 | + int $storageId, |
|
| 77 | + int $rootId, |
|
| 78 | + string $mountPoint, |
|
| 79 | + string $mountProvider, |
|
| 80 | + int $mountId = null, |
|
| 81 | + string $rootInternalPath = '' |
|
| 82 | + ) { |
|
| 83 | + $this->user = $user; |
|
| 84 | + $this->storageId = $storageId; |
|
| 85 | + $this->rootId = $rootId; |
|
| 86 | + $this->mountPoint = $mountPoint; |
|
| 87 | + $this->mountId = $mountId; |
|
| 88 | + $this->rootInternalPath = $rootInternalPath; |
|
| 89 | + if (strlen($mountProvider) > 128) { |
|
| 90 | + throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters"); |
|
| 91 | + } |
|
| 92 | + $this->mountProvider = $mountProvider; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return IUser |
|
| 97 | + */ |
|
| 98 | + public function getUser() { |
|
| 99 | + return $this->user; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return int the numeric storage id of the mount |
|
| 104 | + */ |
|
| 105 | + public function getStorageId() { |
|
| 106 | + return $this->storageId; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return int the fileid of the root of the mount |
|
| 111 | + */ |
|
| 112 | + public function getRootId() { |
|
| 113 | + return $this->rootId; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @return Node the root node of the mount |
|
| 118 | + */ |
|
| 119 | + public function getMountPointNode() { |
|
| 120 | + // TODO injection etc |
|
| 121 | + Filesystem::initMountPoints($this->getUser()->getUID()); |
|
| 122 | + $userNode = \OC::$server->getUserFolder($this->getUser()->getUID()); |
|
| 123 | + $nodes = $userNode->getParent()->getById($this->getRootId()); |
|
| 124 | + if (count($nodes) > 0) { |
|
| 125 | + return $nodes[0]; |
|
| 126 | + } else { |
|
| 127 | + return null; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return string the mount point of the mount for the user |
|
| 133 | + */ |
|
| 134 | + public function getMountPoint() { |
|
| 135 | + return $this->mountPoint; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Get the id of the configured mount |
|
| 140 | + * |
|
| 141 | + * @return int|null mount id or null if not applicable |
|
| 142 | + * @since 9.1.0 |
|
| 143 | + */ |
|
| 144 | + public function getMountId() { |
|
| 145 | + return $this->mountId; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Get the internal path (within the storage) of the root of the mount |
|
| 150 | + * |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function getRootInternalPath() { |
|
| 154 | + return $this->rootInternalPath; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function getMountProvider(): string { |
|
| 158 | + return $this->mountProvider; |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -27,32 +27,32 @@ |
||
| 27 | 27 | use OCP\IUser; |
| 28 | 28 | |
| 29 | 29 | class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInfo { |
| 30 | - /** @var string */ |
|
| 31 | - private $internalPath; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $internalPath; |
|
| 32 | 32 | |
| 33 | - public function __construct( |
|
| 34 | - IUser $user, |
|
| 35 | - int $storageId, |
|
| 36 | - int $rootId, |
|
| 37 | - string $mountPoint, |
|
| 38 | - ?int $mountId, |
|
| 39 | - string $mountProvider, |
|
| 40 | - string $rootInternalPath, |
|
| 41 | - string $internalPath |
|
| 42 | - ) { |
|
| 43 | - parent::__construct($user, $storageId, $rootId, $mountPoint, $mountProvider, $mountId, $rootInternalPath); |
|
| 44 | - $this->internalPath = $internalPath; |
|
| 45 | - } |
|
| 33 | + public function __construct( |
|
| 34 | + IUser $user, |
|
| 35 | + int $storageId, |
|
| 36 | + int $rootId, |
|
| 37 | + string $mountPoint, |
|
| 38 | + ?int $mountId, |
|
| 39 | + string $mountProvider, |
|
| 40 | + string $rootInternalPath, |
|
| 41 | + string $internalPath |
|
| 42 | + ) { |
|
| 43 | + parent::__construct($user, $storageId, $rootId, $mountPoint, $mountProvider, $mountId, $rootInternalPath); |
|
| 44 | + $this->internalPath = $internalPath; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getInternalPath(): string { |
|
| 48 | - if ($this->getRootInternalPath()) { |
|
| 49 | - return substr($this->internalPath, strlen($this->getRootInternalPath()) + 1); |
|
| 50 | - } else { |
|
| 51 | - return $this->internalPath; |
|
| 52 | - } |
|
| 53 | - } |
|
| 47 | + public function getInternalPath(): string { |
|
| 48 | + if ($this->getRootInternalPath()) { |
|
| 49 | + return substr($this->internalPath, strlen($this->getRootInternalPath()) + 1); |
|
| 50 | + } else { |
|
| 51 | + return $this->internalPath; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function getPath(): string { |
|
| 56 | - return $this->getMountPoint() . $this->getInternalPath(); |
|
| 57 | - } |
|
| 55 | + public function getPath(): string { |
|
| 56 | + return $this->getMountPoint() . $this->getInternalPath(); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -53,6 +53,6 @@ |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | public function getPath(): string { |
| 56 | - return $this->getMountPoint() . $this->getInternalPath(); |
|
| 56 | + return $this->getMountPoint().$this->getInternalPath(); |
|
| 57 | 57 | } |
| 58 | 58 | } |
@@ -38,275 +38,275 @@ |
||
| 38 | 38 | use OCP\ILogger; |
| 39 | 39 | |
| 40 | 40 | class MountPoint implements IMountPoint { |
| 41 | - /** |
|
| 42 | - * @var \OC\Files\Storage\Storage|null $storage |
|
| 43 | - */ |
|
| 44 | - protected $storage = null; |
|
| 45 | - protected $class; |
|
| 46 | - protected $storageId; |
|
| 47 | - protected $rootId = null; |
|
| 41 | + /** |
|
| 42 | + * @var \OC\Files\Storage\Storage|null $storage |
|
| 43 | + */ |
|
| 44 | + protected $storage = null; |
|
| 45 | + protected $class; |
|
| 46 | + protected $storageId; |
|
| 47 | + protected $rootId = null; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Configuration options for the storage backend |
|
| 51 | - * |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $arguments = []; |
|
| 55 | - protected $mountPoint; |
|
| 49 | + /** |
|
| 50 | + * Configuration options for the storage backend |
|
| 51 | + * |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $arguments = []; |
|
| 55 | + protected $mountPoint; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Mount specific options |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - protected $mountOptions = []; |
|
| 57 | + /** |
|
| 58 | + * Mount specific options |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + protected $mountOptions = []; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var \OC\Files\Storage\StorageFactory $loader |
|
| 66 | - */ |
|
| 67 | - private $loader; |
|
| 64 | + /** |
|
| 65 | + * @var \OC\Files\Storage\StorageFactory $loader |
|
| 66 | + */ |
|
| 67 | + private $loader; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Specified whether the storage is invalid after failing to |
|
| 71 | - * instantiate it. |
|
| 72 | - * |
|
| 73 | - * @var bool |
|
| 74 | - */ |
|
| 75 | - private $invalidStorage = false; |
|
| 69 | + /** |
|
| 70 | + * Specified whether the storage is invalid after failing to |
|
| 71 | + * instantiate it. |
|
| 72 | + * |
|
| 73 | + * @var bool |
|
| 74 | + */ |
|
| 75 | + private $invalidStorage = false; |
|
| 76 | 76 | |
| 77 | - /** @var int|null */ |
|
| 78 | - protected $mountId; |
|
| 77 | + /** @var int|null */ |
|
| 78 | + protected $mountId; |
|
| 79 | 79 | |
| 80 | - /** @var string */ |
|
| 81 | - protected $mountProvider; |
|
| 80 | + /** @var string */ |
|
| 81 | + protected $mountProvider; |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @param string|\OC\Files\Storage\Storage $storage |
|
| 85 | - * @param string $mountpoint |
|
| 86 | - * @param array $arguments (optional) configuration for the storage backend |
|
| 87 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 88 | - * @param array $mountOptions mount specific options |
|
| 89 | - * @param int|null $mountId |
|
| 90 | - * @param string|null $mountProvider |
|
| 91 | - * @throws \Exception |
|
| 92 | - */ |
|
| 93 | - public function __construct( |
|
| 94 | - $storage, |
|
| 95 | - string $mountpoint, |
|
| 96 | - array $arguments = null, |
|
| 97 | - IStorageFactory $loader = null, |
|
| 98 | - array $mountOptions = null, |
|
| 99 | - int $mountId = null, |
|
| 100 | - string $mountProvider = null |
|
| 101 | - ) { |
|
| 102 | - if (is_null($arguments)) { |
|
| 103 | - $arguments = []; |
|
| 104 | - } |
|
| 105 | - if (is_null($loader)) { |
|
| 106 | - $this->loader = new StorageFactory(); |
|
| 107 | - } else { |
|
| 108 | - $this->loader = $loader; |
|
| 109 | - } |
|
| 83 | + /** |
|
| 84 | + * @param string|\OC\Files\Storage\Storage $storage |
|
| 85 | + * @param string $mountpoint |
|
| 86 | + * @param array $arguments (optional) configuration for the storage backend |
|
| 87 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 88 | + * @param array $mountOptions mount specific options |
|
| 89 | + * @param int|null $mountId |
|
| 90 | + * @param string|null $mountProvider |
|
| 91 | + * @throws \Exception |
|
| 92 | + */ |
|
| 93 | + public function __construct( |
|
| 94 | + $storage, |
|
| 95 | + string $mountpoint, |
|
| 96 | + array $arguments = null, |
|
| 97 | + IStorageFactory $loader = null, |
|
| 98 | + array $mountOptions = null, |
|
| 99 | + int $mountId = null, |
|
| 100 | + string $mountProvider = null |
|
| 101 | + ) { |
|
| 102 | + if (is_null($arguments)) { |
|
| 103 | + $arguments = []; |
|
| 104 | + } |
|
| 105 | + if (is_null($loader)) { |
|
| 106 | + $this->loader = new StorageFactory(); |
|
| 107 | + } else { |
|
| 108 | + $this->loader = $loader; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - if (!is_null($mountOptions)) { |
|
| 112 | - $this->mountOptions = $mountOptions; |
|
| 113 | - } |
|
| 111 | + if (!is_null($mountOptions)) { |
|
| 112 | + $this->mountOptions = $mountOptions; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - $mountpoint = $this->formatPath($mountpoint); |
|
| 116 | - $this->mountPoint = $mountpoint; |
|
| 117 | - $this->mountId = $mountId; |
|
| 118 | - if ($storage instanceof Storage) { |
|
| 119 | - $this->class = get_class($storage); |
|
| 120 | - $this->storage = $this->loader->wrap($this, $storage); |
|
| 121 | - } else { |
|
| 122 | - // Update old classes to new namespace |
|
| 123 | - if (strpos($storage, 'OC_Filestorage_') !== false) { |
|
| 124 | - $storage = '\OC\Files\Storage\\' . substr($storage, 15); |
|
| 125 | - } |
|
| 126 | - $this->class = $storage; |
|
| 127 | - $this->arguments = $arguments; |
|
| 128 | - } |
|
| 129 | - if ($mountProvider) { |
|
| 130 | - if (strlen($mountProvider) > 128) { |
|
| 131 | - throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters"); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - $this->mountProvider = $mountProvider ?? ''; |
|
| 135 | - } |
|
| 115 | + $mountpoint = $this->formatPath($mountpoint); |
|
| 116 | + $this->mountPoint = $mountpoint; |
|
| 117 | + $this->mountId = $mountId; |
|
| 118 | + if ($storage instanceof Storage) { |
|
| 119 | + $this->class = get_class($storage); |
|
| 120 | + $this->storage = $this->loader->wrap($this, $storage); |
|
| 121 | + } else { |
|
| 122 | + // Update old classes to new namespace |
|
| 123 | + if (strpos($storage, 'OC_Filestorage_') !== false) { |
|
| 124 | + $storage = '\OC\Files\Storage\\' . substr($storage, 15); |
|
| 125 | + } |
|
| 126 | + $this->class = $storage; |
|
| 127 | + $this->arguments = $arguments; |
|
| 128 | + } |
|
| 129 | + if ($mountProvider) { |
|
| 130 | + if (strlen($mountProvider) > 128) { |
|
| 131 | + throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters"); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + $this->mountProvider = $mountProvider ?? ''; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * get complete path to the mount point, relative to data/ |
|
| 139 | - * |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function getMountPoint() { |
|
| 143 | - return $this->mountPoint; |
|
| 144 | - } |
|
| 137 | + /** |
|
| 138 | + * get complete path to the mount point, relative to data/ |
|
| 139 | + * |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function getMountPoint() { |
|
| 143 | + return $this->mountPoint; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Sets the mount point path, relative to data/ |
|
| 148 | - * |
|
| 149 | - * @param string $mountPoint new mount point |
|
| 150 | - */ |
|
| 151 | - public function setMountPoint($mountPoint) { |
|
| 152 | - $this->mountPoint = $this->formatPath($mountPoint); |
|
| 153 | - } |
|
| 146 | + /** |
|
| 147 | + * Sets the mount point path, relative to data/ |
|
| 148 | + * |
|
| 149 | + * @param string $mountPoint new mount point |
|
| 150 | + */ |
|
| 151 | + public function setMountPoint($mountPoint) { |
|
| 152 | + $this->mountPoint = $this->formatPath($mountPoint); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * create the storage that is mounted |
|
| 157 | - */ |
|
| 158 | - private function createStorage() { |
|
| 159 | - if ($this->invalidStorage) { |
|
| 160 | - return; |
|
| 161 | - } |
|
| 155 | + /** |
|
| 156 | + * create the storage that is mounted |
|
| 157 | + */ |
|
| 158 | + private function createStorage() { |
|
| 159 | + if ($this->invalidStorage) { |
|
| 160 | + return; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - if (class_exists($this->class)) { |
|
| 164 | - try { |
|
| 165 | - $class = $this->class; |
|
| 166 | - // prevent recursion by setting the storage before applying wrappers |
|
| 167 | - $this->storage = new $class($this->arguments); |
|
| 168 | - $this->storage = $this->loader->wrap($this, $this->storage); |
|
| 169 | - } catch (\Exception $exception) { |
|
| 170 | - $this->storage = null; |
|
| 171 | - $this->invalidStorage = true; |
|
| 172 | - if ($this->mountPoint === '/') { |
|
| 173 | - // the root storage could not be initialized, show the user! |
|
| 174 | - throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception); |
|
| 175 | - } else { |
|
| 176 | - \OC::$server->getLogger()->logException($exception, ['level' => ILogger::ERROR]); |
|
| 177 | - } |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - } else { |
|
| 181 | - \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', ILogger::ERROR); |
|
| 182 | - $this->invalidStorage = true; |
|
| 183 | - return; |
|
| 184 | - } |
|
| 185 | - } |
|
| 163 | + if (class_exists($this->class)) { |
|
| 164 | + try { |
|
| 165 | + $class = $this->class; |
|
| 166 | + // prevent recursion by setting the storage before applying wrappers |
|
| 167 | + $this->storage = new $class($this->arguments); |
|
| 168 | + $this->storage = $this->loader->wrap($this, $this->storage); |
|
| 169 | + } catch (\Exception $exception) { |
|
| 170 | + $this->storage = null; |
|
| 171 | + $this->invalidStorage = true; |
|
| 172 | + if ($this->mountPoint === '/') { |
|
| 173 | + // the root storage could not be initialized, show the user! |
|
| 174 | + throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception); |
|
| 175 | + } else { |
|
| 176 | + \OC::$server->getLogger()->logException($exception, ['level' => ILogger::ERROR]); |
|
| 177 | + } |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + } else { |
|
| 181 | + \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', ILogger::ERROR); |
|
| 182 | + $this->invalidStorage = true; |
|
| 183 | + return; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * @return \OC\Files\Storage\Storage|null |
|
| 189 | - */ |
|
| 190 | - public function getStorage() { |
|
| 191 | - if (is_null($this->storage)) { |
|
| 192 | - $this->createStorage(); |
|
| 193 | - } |
|
| 194 | - return $this->storage; |
|
| 195 | - } |
|
| 187 | + /** |
|
| 188 | + * @return \OC\Files\Storage\Storage|null |
|
| 189 | + */ |
|
| 190 | + public function getStorage() { |
|
| 191 | + if (is_null($this->storage)) { |
|
| 192 | + $this->createStorage(); |
|
| 193 | + } |
|
| 194 | + return $this->storage; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public function getStorageId() { |
|
| 201 | - if (!$this->storageId) { |
|
| 202 | - if (is_null($this->storage)) { |
|
| 203 | - $storage = $this->createStorage(); //FIXME: start using exceptions |
|
| 204 | - if (is_null($storage)) { |
|
| 205 | - return null; |
|
| 206 | - } |
|
| 197 | + /** |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public function getStorageId() { |
|
| 201 | + if (!$this->storageId) { |
|
| 202 | + if (is_null($this->storage)) { |
|
| 203 | + $storage = $this->createStorage(); //FIXME: start using exceptions |
|
| 204 | + if (is_null($storage)) { |
|
| 205 | + return null; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - $this->storage = $storage; |
|
| 209 | - } |
|
| 210 | - $this->storageId = $this->storage->getId(); |
|
| 211 | - if (strlen($this->storageId) > 64) { |
|
| 212 | - $this->storageId = md5($this->storageId); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - return $this->storageId; |
|
| 216 | - } |
|
| 208 | + $this->storage = $storage; |
|
| 209 | + } |
|
| 210 | + $this->storageId = $this->storage->getId(); |
|
| 211 | + if (strlen($this->storageId) > 64) { |
|
| 212 | + $this->storageId = md5($this->storageId); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + return $this->storageId; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * @return int |
|
| 220 | - */ |
|
| 221 | - public function getNumericStorageId() { |
|
| 222 | - return $this->getStorage()->getStorageCache()->getNumericId(); |
|
| 223 | - } |
|
| 218 | + /** |
|
| 219 | + * @return int |
|
| 220 | + */ |
|
| 221 | + public function getNumericStorageId() { |
|
| 222 | + return $this->getStorage()->getStorageCache()->getNumericId(); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * @param string $path |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function getInternalPath($path) { |
|
| 230 | - $path = Filesystem::normalizePath($path, true, false, true); |
|
| 231 | - if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) { |
|
| 232 | - $internalPath = ''; |
|
| 233 | - } else { |
|
| 234 | - $internalPath = substr($path, strlen($this->mountPoint)); |
|
| 235 | - } |
|
| 236 | - // substr returns false instead of an empty string, we always want a string |
|
| 237 | - return (string)$internalPath; |
|
| 238 | - } |
|
| 225 | + /** |
|
| 226 | + * @param string $path |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function getInternalPath($path) { |
|
| 230 | + $path = Filesystem::normalizePath($path, true, false, true); |
|
| 231 | + if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) { |
|
| 232 | + $internalPath = ''; |
|
| 233 | + } else { |
|
| 234 | + $internalPath = substr($path, strlen($this->mountPoint)); |
|
| 235 | + } |
|
| 236 | + // substr returns false instead of an empty string, we always want a string |
|
| 237 | + return (string)$internalPath; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * @param string $path |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - private function formatPath($path) { |
|
| 245 | - $path = Filesystem::normalizePath($path); |
|
| 246 | - if (strlen($path) > 1) { |
|
| 247 | - $path .= '/'; |
|
| 248 | - } |
|
| 249 | - return $path; |
|
| 250 | - } |
|
| 240 | + /** |
|
| 241 | + * @param string $path |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + private function formatPath($path) { |
|
| 245 | + $path = Filesystem::normalizePath($path); |
|
| 246 | + if (strlen($path) > 1) { |
|
| 247 | + $path .= '/'; |
|
| 248 | + } |
|
| 249 | + return $path; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * @param callable $wrapper |
|
| 254 | - */ |
|
| 255 | - public function wrapStorage($wrapper) { |
|
| 256 | - $storage = $this->getStorage(); |
|
| 257 | - // storage can be null if it couldn't be initialized |
|
| 258 | - if ($storage != null) { |
|
| 259 | - $this->storage = $wrapper($this->mountPoint, $storage, $this); |
|
| 260 | - } |
|
| 261 | - } |
|
| 252 | + /** |
|
| 253 | + * @param callable $wrapper |
|
| 254 | + */ |
|
| 255 | + public function wrapStorage($wrapper) { |
|
| 256 | + $storage = $this->getStorage(); |
|
| 257 | + // storage can be null if it couldn't be initialized |
|
| 258 | + if ($storage != null) { |
|
| 259 | + $this->storage = $wrapper($this->mountPoint, $storage, $this); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Get a mount option |
|
| 265 | - * |
|
| 266 | - * @param string $name Name of the mount option to get |
|
| 267 | - * @param mixed $default Default value for the mount option |
|
| 268 | - * @return mixed |
|
| 269 | - */ |
|
| 270 | - public function getOption($name, $default) { |
|
| 271 | - return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; |
|
| 272 | - } |
|
| 263 | + /** |
|
| 264 | + * Get a mount option |
|
| 265 | + * |
|
| 266 | + * @param string $name Name of the mount option to get |
|
| 267 | + * @param mixed $default Default value for the mount option |
|
| 268 | + * @return mixed |
|
| 269 | + */ |
|
| 270 | + public function getOption($name, $default) { |
|
| 271 | + return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Get all options for the mount |
|
| 276 | - * |
|
| 277 | - * @return array |
|
| 278 | - */ |
|
| 279 | - public function getOptions() { |
|
| 280 | - return $this->mountOptions; |
|
| 281 | - } |
|
| 274 | + /** |
|
| 275 | + * Get all options for the mount |
|
| 276 | + * |
|
| 277 | + * @return array |
|
| 278 | + */ |
|
| 279 | + public function getOptions() { |
|
| 280 | + return $this->mountOptions; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * Get the file id of the root of the storage |
|
| 285 | - * |
|
| 286 | - * @return int |
|
| 287 | - */ |
|
| 288 | - public function getStorageRootId() { |
|
| 289 | - if (is_null($this->rootId) || $this->rootId === -1) { |
|
| 290 | - $storage = $this->getStorage(); |
|
| 291 | - // if we can't create the storage return -1 as root id, this is then handled the same as if the root isn't scanned yet |
|
| 292 | - if ($storage === null) { |
|
| 293 | - $this->rootId = -1; |
|
| 294 | - } else { |
|
| 295 | - $this->rootId = (int)$storage->getCache()->getId(''); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - return $this->rootId; |
|
| 299 | - } |
|
| 283 | + /** |
|
| 284 | + * Get the file id of the root of the storage |
|
| 285 | + * |
|
| 286 | + * @return int |
|
| 287 | + */ |
|
| 288 | + public function getStorageRootId() { |
|
| 289 | + if (is_null($this->rootId) || $this->rootId === -1) { |
|
| 290 | + $storage = $this->getStorage(); |
|
| 291 | + // if we can't create the storage return -1 as root id, this is then handled the same as if the root isn't scanned yet |
|
| 292 | + if ($storage === null) { |
|
| 293 | + $this->rootId = -1; |
|
| 294 | + } else { |
|
| 295 | + $this->rootId = (int)$storage->getCache()->getId(''); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + return $this->rootId; |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - public function getMountId() { |
|
| 302 | - return $this->mountId; |
|
| 303 | - } |
|
| 301 | + public function getMountId() { |
|
| 302 | + return $this->mountId; |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - public function getMountType() { |
|
| 306 | - return ''; |
|
| 307 | - } |
|
| 305 | + public function getMountType() { |
|
| 306 | + return ''; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - public function getMountProvider(): string { |
|
| 310 | - return $this->mountProvider; |
|
| 311 | - } |
|
| 309 | + public function getMountProvider(): string { |
|
| 310 | + return $this->mountProvider; |
|
| 311 | + } |
|
| 312 | 312 | } |
@@ -30,42 +30,42 @@ |
||
| 30 | 30 | * Mount provider for custom cache storages |
| 31 | 31 | */ |
| 32 | 32 | class CacheMountProvider implements IMountProvider { |
| 33 | - /** |
|
| 34 | - * @var IConfig |
|
| 35 | - */ |
|
| 36 | - private $config; |
|
| 33 | + /** |
|
| 34 | + * @var IConfig |
|
| 35 | + */ |
|
| 36 | + private $config; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * ObjectStoreHomeMountProvider constructor. |
|
| 40 | - * |
|
| 41 | - * @param IConfig $config |
|
| 42 | - */ |
|
| 43 | - public function __construct(IConfig $config) { |
|
| 44 | - $this->config = $config; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * ObjectStoreHomeMountProvider constructor. |
|
| 40 | + * |
|
| 41 | + * @param IConfig $config |
|
| 42 | + */ |
|
| 43 | + public function __construct(IConfig $config) { |
|
| 44 | + $this->config = $config; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get the cache mount for a user |
|
| 49 | - * |
|
| 50 | - * @param IUser $user |
|
| 51 | - * @param IStorageFactory $loader |
|
| 52 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 53 | - */ |
|
| 54 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
| 55 | - $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
|
| 56 | - if ($cacheBaseDir !== '') { |
|
| 57 | - $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
| 58 | - if (!file_exists($cacheDir)) { |
|
| 59 | - mkdir($cacheDir, 0770, true); |
|
| 60 | - mkdir($cacheDir . '/uploads', 0770, true); |
|
| 61 | - } |
|
| 47 | + /** |
|
| 48 | + * Get the cache mount for a user |
|
| 49 | + * |
|
| 50 | + * @param IUser $user |
|
| 51 | + * @param IStorageFactory $loader |
|
| 52 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 53 | + */ |
|
| 54 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
| 55 | + $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
|
| 56 | + if ($cacheBaseDir !== '') { |
|
| 57 | + $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
| 58 | + if (!file_exists($cacheDir)) { |
|
| 59 | + mkdir($cacheDir, 0770, true); |
|
| 60 | + mkdir($cacheDir . '/uploads', 0770, true); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return [ |
|
| 64 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class), |
|
| 65 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class) |
|
| 66 | - ]; |
|
| 67 | - } else { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - } |
|
| 63 | + return [ |
|
| 64 | + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class), |
|
| 65 | + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class) |
|
| 66 | + ]; |
|
| 67 | + } else { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -54,15 +54,15 @@ |
||
| 54 | 54 | public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
| 55 | 55 | $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
| 56 | 56 | if ($cacheBaseDir !== '') { |
| 57 | - $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
| 57 | + $cacheDir = rtrim($cacheBaseDir, '/').'/'.$user->getUID(); |
|
| 58 | 58 | if (!file_exists($cacheDir)) { |
| 59 | 59 | mkdir($cacheDir, 0770, true); |
| 60 | - mkdir($cacheDir . '/uploads', 0770, true); |
|
| 60 | + mkdir($cacheDir.'/uploads', 0770, true); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | return [ |
| 64 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir], $loader, null, null, self::class), |
|
| 65 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads'], $loader, null, null, self::class) |
|
| 64 | + new MountPoint('\OC\Files\Storage\Local', '/'.$user->getUID().'/cache', ['datadir' => $cacheDir], $loader, null, null, self::class), |
|
| 65 | + new MountPoint('\OC\Files\Storage\Local', '/'.$user->getUID().'/uploads', ['datadir' => $cacheDir.'/uploads'], $loader, null, null, self::class) |
|
| 66 | 66 | ]; |
| 67 | 67 | } else { |
| 68 | 68 | return []; |