@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | */ |
184 | 184 | public function getId() { |
185 | - return 'shared::' . $this->getMountPoint(); |
|
185 | + return 'shared::'.$this->getMountPoint(); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | } |
286 | 286 | } |
287 | 287 | $info = array( |
288 | - 'target' => $this->getMountPoint() . $path, |
|
288 | + 'target' => $this->getMountPoint().$path, |
|
289 | 289 | 'source' => $source, |
290 | 290 | 'mode' => $mode, |
291 | 291 | ); |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | if (!$storage) { |
379 | 379 | $storage = $this; |
380 | 380 | } |
381 | - $sourceRoot = $this->getSourceRootInfo(); |
|
381 | + $sourceRoot = $this->getSourceRootInfo(); |
|
382 | 382 | if ($this->storage instanceof FailedStorage) { |
383 | 383 | return new FailedCache(); |
384 | 384 | } |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | |
485 | 485 | public function file_get_contents($path) { |
486 | 486 | $info = [ |
487 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
487 | + 'target' => $this->getMountPoint().'/'.$path, |
|
488 | 488 | 'source' => $this->getUnjailedPath($path), |
489 | 489 | ]; |
490 | 490 | \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | |
494 | 494 | public function file_put_contents($path, $data) { |
495 | 495 | $info = [ |
496 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
496 | + 'target' => $this->getMountPoint().'/'.$path, |
|
497 | 497 | 'source' => $this->getUnjailedPath($path), |
498 | 498 | ]; |
499 | 499 | \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
@@ -48,452 +48,452 @@ |
||
48 | 48 | */ |
49 | 49 | class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { |
50 | 50 | |
51 | - /** @var \OCP\Share\IShare */ |
|
52 | - private $superShare; |
|
53 | - |
|
54 | - /** @var \OCP\Share\IShare[] */ |
|
55 | - private $groupedShares; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var \OC\Files\View |
|
59 | - */ |
|
60 | - private $ownerView; |
|
61 | - |
|
62 | - private $initialized = false; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var ICacheEntry |
|
66 | - */ |
|
67 | - private $sourceRootInfo; |
|
68 | - |
|
69 | - /** @var string */ |
|
70 | - private $user; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var \OCP\ILogger |
|
74 | - */ |
|
75 | - private $logger; |
|
76 | - |
|
77 | - /** @var IStorage */ |
|
78 | - private $nonMaskedStorage; |
|
79 | - |
|
80 | - private $options; |
|
81 | - |
|
82 | - /** @var boolean */ |
|
83 | - private $sharingDisabledForUser; |
|
84 | - |
|
85 | - public function __construct($arguments) { |
|
86 | - $this->ownerView = $arguments['ownerView']; |
|
87 | - $this->logger = \OC::$server->getLogger(); |
|
88 | - |
|
89 | - $this->superShare = $arguments['superShare']; |
|
90 | - $this->groupedShares = $arguments['groupedShares']; |
|
91 | - |
|
92 | - $this->user = $arguments['user']; |
|
93 | - if (isset($arguments['sharingDisabledForUser'])) { |
|
94 | - $this->sharingDisabledForUser = $arguments['sharingDisabledForUser']; |
|
95 | - } else { |
|
96 | - $this->sharingDisabledForUser = false; |
|
97 | - } |
|
98 | - |
|
99 | - parent::__construct([ |
|
100 | - 'storage' => null, |
|
101 | - 'root' => null, |
|
102 | - ]); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @return ICacheEntry |
|
107 | - */ |
|
108 | - private function getSourceRootInfo() { |
|
109 | - if (is_null($this->sourceRootInfo)) { |
|
110 | - if (is_null($this->superShare->getNodeCacheEntry())) { |
|
111 | - $this->init(); |
|
112 | - $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
113 | - } else { |
|
114 | - $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
115 | - } |
|
116 | - } |
|
117 | - return $this->sourceRootInfo; |
|
118 | - } |
|
119 | - |
|
120 | - private function init() { |
|
121 | - if ($this->initialized) { |
|
122 | - return; |
|
123 | - } |
|
124 | - $this->initialized = true; |
|
125 | - try { |
|
126 | - Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
127 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
128 | - list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
129 | - $this->storage = new PermissionsMask([ |
|
130 | - 'storage' => $this->nonMaskedStorage, |
|
131 | - 'mask' => $this->superShare->getPermissions() |
|
132 | - ]); |
|
133 | - } catch (NotFoundException $e) { |
|
134 | - // original file not accessible or deleted, set FailedStorage |
|
135 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
136 | - $this->cache = new FailedCache(); |
|
137 | - $this->rootPath = ''; |
|
138 | - } catch (NoUserException $e) { |
|
139 | - // sharer user deleted, set FailedStorage |
|
140 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
141 | - $this->cache = new FailedCache(); |
|
142 | - $this->rootPath = ''; |
|
143 | - } catch (\Exception $e) { |
|
144 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
145 | - $this->cache = new FailedCache(); |
|
146 | - $this->rootPath = ''; |
|
147 | - $this->logger->logException($e); |
|
148 | - } |
|
149 | - |
|
150 | - if (!$this->nonMaskedStorage) { |
|
151 | - $this->nonMaskedStorage = $this->storage; |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @inheritdoc |
|
157 | - */ |
|
158 | - public function instanceOfStorage($class) { |
|
159 | - if ($class === '\OC\Files\Storage\Common') { |
|
160 | - return true; |
|
161 | - } |
|
162 | - if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
163 | - return false; |
|
164 | - } |
|
165 | - return parent::instanceOfStorage($class); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function getShareId() { |
|
172 | - return $this->superShare->getId(); |
|
173 | - } |
|
174 | - |
|
175 | - private function isValid() { |
|
176 | - return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * get id of the mount point |
|
181 | - * |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function getId() { |
|
185 | - return 'shared::' . $this->getMountPoint(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Get the permissions granted for a shared file |
|
190 | - * |
|
191 | - * @param string $target Shared target file path |
|
192 | - * @return int CRUDS permissions granted |
|
193 | - */ |
|
194 | - public function getPermissions($target = '') { |
|
195 | - if (!$this->isValid()) { |
|
196 | - return 0; |
|
197 | - } |
|
198 | - $permissions = $this->superShare->getPermissions(); |
|
199 | - // part files and the mount point always have delete permissions |
|
200 | - if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
201 | - $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
202 | - } |
|
203 | - |
|
204 | - if ($this->sharingDisabledForUser) { |
|
205 | - $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
206 | - } |
|
207 | - |
|
208 | - return $permissions; |
|
209 | - } |
|
210 | - |
|
211 | - public function isCreatable($path) { |
|
212 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
213 | - } |
|
214 | - |
|
215 | - public function isReadable($path) { |
|
216 | - if (!$this->isValid()) { |
|
217 | - return false; |
|
218 | - } |
|
219 | - if (!$this->file_exists($path)) { |
|
220 | - return false; |
|
221 | - } |
|
222 | - /** @var IStorage $storage */ |
|
223 | - /** @var string $internalPath */ |
|
224 | - list($storage, $internalPath) = $this->resolvePath($path); |
|
225 | - return $storage->isReadable($internalPath); |
|
226 | - } |
|
227 | - |
|
228 | - public function isUpdatable($path) { |
|
229 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
230 | - } |
|
231 | - |
|
232 | - public function isDeletable($path) { |
|
233 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
234 | - } |
|
235 | - |
|
236 | - public function isSharable($path) { |
|
237 | - if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
238 | - return false; |
|
239 | - } |
|
240 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
241 | - } |
|
242 | - |
|
243 | - public function fopen($path, $mode) { |
|
244 | - if ($source = $this->getUnjailedPath($path)) { |
|
245 | - switch ($mode) { |
|
246 | - case 'r+': |
|
247 | - case 'rb+': |
|
248 | - case 'w+': |
|
249 | - case 'wb+': |
|
250 | - case 'x+': |
|
251 | - case 'xb+': |
|
252 | - case 'a+': |
|
253 | - case 'ab+': |
|
254 | - case 'w': |
|
255 | - case 'wb': |
|
256 | - case 'x': |
|
257 | - case 'xb': |
|
258 | - case 'a': |
|
259 | - case 'ab': |
|
260 | - $creatable = $this->isCreatable($path); |
|
261 | - $updatable = $this->isUpdatable($path); |
|
262 | - // if neither permissions given, no need to continue |
|
263 | - if (!$creatable && !$updatable) { |
|
264 | - return false; |
|
265 | - } |
|
266 | - |
|
267 | - $exists = $this->file_exists($path); |
|
268 | - // if a file exists, updatable permissions are required |
|
269 | - if ($exists && !$updatable) { |
|
270 | - return false; |
|
271 | - } |
|
272 | - |
|
273 | - // part file is allowed if !$creatable but the final file is $updatable |
|
274 | - if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
275 | - if (!$exists && !$creatable) { |
|
276 | - return false; |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
280 | - $info = array( |
|
281 | - 'target' => $this->getMountPoint() . $path, |
|
282 | - 'source' => $source, |
|
283 | - 'mode' => $mode, |
|
284 | - ); |
|
285 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
286 | - return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
287 | - } |
|
288 | - return false; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * see http://php.net/manual/en/function.rename.php |
|
293 | - * |
|
294 | - * @param string $path1 |
|
295 | - * @param string $path2 |
|
296 | - * @return bool |
|
297 | - */ |
|
298 | - public function rename($path1, $path2) { |
|
299 | - $this->init(); |
|
300 | - $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
301 | - $targetExists = $this->file_exists($path2); |
|
302 | - $sameFodler = dirname($path1) === dirname($path2); |
|
303 | - |
|
304 | - if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
305 | - if (!$this->isUpdatable('')) { |
|
306 | - return false; |
|
307 | - } |
|
308 | - } else { |
|
309 | - if (!$this->isCreatable('')) { |
|
310 | - return false; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * return mount point of share, relative to data/user/files |
|
319 | - * |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - public function getMountPoint() { |
|
323 | - return $this->superShare->getTarget(); |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * @param string $path |
|
328 | - */ |
|
329 | - public function setMountPoint($path) { |
|
330 | - $this->superShare->setTarget($path); |
|
331 | - |
|
332 | - foreach ($this->groupedShares as $share) { |
|
333 | - $share->setTarget($path); |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * get the user who shared the file |
|
339 | - * |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function getSharedFrom() { |
|
343 | - return $this->superShare->getShareOwner(); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * @return \OCP\Share\IShare |
|
348 | - */ |
|
349 | - public function getShare() { |
|
350 | - return $this->superShare; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * return share type, can be "file" or "folder" |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function getItemType() { |
|
359 | - return $this->superShare->getNodeType(); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * @param string $path |
|
364 | - * @param null $storage |
|
365 | - * @return Cache |
|
366 | - */ |
|
367 | - public function getCache($path = '', $storage = null) { |
|
368 | - if ($this->cache) { |
|
369 | - return $this->cache; |
|
370 | - } |
|
371 | - if (!$storage) { |
|
372 | - $storage = $this; |
|
373 | - } |
|
374 | - $sourceRoot = $this->getSourceRootInfo(); |
|
375 | - if ($this->storage instanceof FailedStorage) { |
|
376 | - return new FailedCache(); |
|
377 | - } |
|
378 | - |
|
379 | - $this->cache = new \OCA\Files_Sharing\Cache($storage, $sourceRoot, $this->superShare); |
|
380 | - return $this->cache; |
|
381 | - } |
|
382 | - |
|
383 | - public function getScanner($path = '', $storage = null) { |
|
384 | - if (!$storage) { |
|
385 | - $storage = $this; |
|
386 | - } |
|
387 | - return new \OCA\Files_Sharing\Scanner($storage); |
|
388 | - } |
|
389 | - |
|
390 | - public function getOwner($path) { |
|
391 | - return $this->superShare->getShareOwner(); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * unshare complete storage, also the grouped shares |
|
396 | - * |
|
397 | - * @return bool |
|
398 | - */ |
|
399 | - public function unshareStorage() { |
|
400 | - foreach ($this->groupedShares as $share) { |
|
401 | - \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
402 | - } |
|
403 | - return true; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * @param string $path |
|
408 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
409 | - * @param \OCP\Lock\ILockingProvider $provider |
|
410 | - * @throws \OCP\Lock\LockedException |
|
411 | - */ |
|
412 | - public function acquireLock($path, $type, ILockingProvider $provider) { |
|
413 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
414 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
415 | - $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
416 | - // lock the parent folders of the owner when locking the share as recipient |
|
417 | - if ($path === '') { |
|
418 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
419 | - $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * @param string $path |
|
425 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
426 | - * @param \OCP\Lock\ILockingProvider $provider |
|
427 | - */ |
|
428 | - public function releaseLock($path, $type, ILockingProvider $provider) { |
|
429 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
430 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
431 | - $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
432 | - // unlock the parent folders of the owner when unlocking the share as recipient |
|
433 | - if ($path === '') { |
|
434 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
435 | - $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @param string $path |
|
441 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
442 | - * @param \OCP\Lock\ILockingProvider $provider |
|
443 | - */ |
|
444 | - public function changeLock($path, $type, ILockingProvider $provider) { |
|
445 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
446 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
447 | - $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * @return array [ available, last_checked ] |
|
452 | - */ |
|
453 | - public function getAvailability() { |
|
454 | - // shares do not participate in availability logic |
|
455 | - return [ |
|
456 | - 'available' => true, |
|
457 | - 'last_checked' => 0 |
|
458 | - ]; |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * @param bool $available |
|
463 | - */ |
|
464 | - public function setAvailability($available) { |
|
465 | - // shares do not participate in availability logic |
|
466 | - } |
|
467 | - |
|
468 | - public function getSourceStorage() { |
|
469 | - $this->init(); |
|
470 | - return $this->nonMaskedStorage; |
|
471 | - } |
|
472 | - |
|
473 | - public function getWrapperStorage() { |
|
474 | - $this->init(); |
|
475 | - return $this->storage; |
|
476 | - } |
|
477 | - |
|
478 | - public function file_get_contents($path) { |
|
479 | - $info = [ |
|
480 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
481 | - 'source' => $this->getUnjailedPath($path), |
|
482 | - ]; |
|
483 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
484 | - return parent::file_get_contents($path); |
|
485 | - } |
|
486 | - |
|
487 | - public function file_put_contents($path, $data) { |
|
488 | - $info = [ |
|
489 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
490 | - 'source' => $this->getUnjailedPath($path), |
|
491 | - ]; |
|
492 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
493 | - return parent::file_put_contents($path, $data); |
|
494 | - } |
|
495 | - |
|
496 | - public function setMountOptions(array $options) { |
|
497 | - $this->mountOptions = $options; |
|
498 | - } |
|
51 | + /** @var \OCP\Share\IShare */ |
|
52 | + private $superShare; |
|
53 | + |
|
54 | + /** @var \OCP\Share\IShare[] */ |
|
55 | + private $groupedShares; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var \OC\Files\View |
|
59 | + */ |
|
60 | + private $ownerView; |
|
61 | + |
|
62 | + private $initialized = false; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var ICacheEntry |
|
66 | + */ |
|
67 | + private $sourceRootInfo; |
|
68 | + |
|
69 | + /** @var string */ |
|
70 | + private $user; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var \OCP\ILogger |
|
74 | + */ |
|
75 | + private $logger; |
|
76 | + |
|
77 | + /** @var IStorage */ |
|
78 | + private $nonMaskedStorage; |
|
79 | + |
|
80 | + private $options; |
|
81 | + |
|
82 | + /** @var boolean */ |
|
83 | + private $sharingDisabledForUser; |
|
84 | + |
|
85 | + public function __construct($arguments) { |
|
86 | + $this->ownerView = $arguments['ownerView']; |
|
87 | + $this->logger = \OC::$server->getLogger(); |
|
88 | + |
|
89 | + $this->superShare = $arguments['superShare']; |
|
90 | + $this->groupedShares = $arguments['groupedShares']; |
|
91 | + |
|
92 | + $this->user = $arguments['user']; |
|
93 | + if (isset($arguments['sharingDisabledForUser'])) { |
|
94 | + $this->sharingDisabledForUser = $arguments['sharingDisabledForUser']; |
|
95 | + } else { |
|
96 | + $this->sharingDisabledForUser = false; |
|
97 | + } |
|
98 | + |
|
99 | + parent::__construct([ |
|
100 | + 'storage' => null, |
|
101 | + 'root' => null, |
|
102 | + ]); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @return ICacheEntry |
|
107 | + */ |
|
108 | + private function getSourceRootInfo() { |
|
109 | + if (is_null($this->sourceRootInfo)) { |
|
110 | + if (is_null($this->superShare->getNodeCacheEntry())) { |
|
111 | + $this->init(); |
|
112 | + $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
113 | + } else { |
|
114 | + $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
115 | + } |
|
116 | + } |
|
117 | + return $this->sourceRootInfo; |
|
118 | + } |
|
119 | + |
|
120 | + private function init() { |
|
121 | + if ($this->initialized) { |
|
122 | + return; |
|
123 | + } |
|
124 | + $this->initialized = true; |
|
125 | + try { |
|
126 | + Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
127 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
128 | + list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
129 | + $this->storage = new PermissionsMask([ |
|
130 | + 'storage' => $this->nonMaskedStorage, |
|
131 | + 'mask' => $this->superShare->getPermissions() |
|
132 | + ]); |
|
133 | + } catch (NotFoundException $e) { |
|
134 | + // original file not accessible or deleted, set FailedStorage |
|
135 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
136 | + $this->cache = new FailedCache(); |
|
137 | + $this->rootPath = ''; |
|
138 | + } catch (NoUserException $e) { |
|
139 | + // sharer user deleted, set FailedStorage |
|
140 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
141 | + $this->cache = new FailedCache(); |
|
142 | + $this->rootPath = ''; |
|
143 | + } catch (\Exception $e) { |
|
144 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
145 | + $this->cache = new FailedCache(); |
|
146 | + $this->rootPath = ''; |
|
147 | + $this->logger->logException($e); |
|
148 | + } |
|
149 | + |
|
150 | + if (!$this->nonMaskedStorage) { |
|
151 | + $this->nonMaskedStorage = $this->storage; |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @inheritdoc |
|
157 | + */ |
|
158 | + public function instanceOfStorage($class) { |
|
159 | + if ($class === '\OC\Files\Storage\Common') { |
|
160 | + return true; |
|
161 | + } |
|
162 | + if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
163 | + return false; |
|
164 | + } |
|
165 | + return parent::instanceOfStorage($class); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function getShareId() { |
|
172 | + return $this->superShare->getId(); |
|
173 | + } |
|
174 | + |
|
175 | + private function isValid() { |
|
176 | + return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * get id of the mount point |
|
181 | + * |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function getId() { |
|
185 | + return 'shared::' . $this->getMountPoint(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Get the permissions granted for a shared file |
|
190 | + * |
|
191 | + * @param string $target Shared target file path |
|
192 | + * @return int CRUDS permissions granted |
|
193 | + */ |
|
194 | + public function getPermissions($target = '') { |
|
195 | + if (!$this->isValid()) { |
|
196 | + return 0; |
|
197 | + } |
|
198 | + $permissions = $this->superShare->getPermissions(); |
|
199 | + // part files and the mount point always have delete permissions |
|
200 | + if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
201 | + $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
202 | + } |
|
203 | + |
|
204 | + if ($this->sharingDisabledForUser) { |
|
205 | + $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
206 | + } |
|
207 | + |
|
208 | + return $permissions; |
|
209 | + } |
|
210 | + |
|
211 | + public function isCreatable($path) { |
|
212 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
213 | + } |
|
214 | + |
|
215 | + public function isReadable($path) { |
|
216 | + if (!$this->isValid()) { |
|
217 | + return false; |
|
218 | + } |
|
219 | + if (!$this->file_exists($path)) { |
|
220 | + return false; |
|
221 | + } |
|
222 | + /** @var IStorage $storage */ |
|
223 | + /** @var string $internalPath */ |
|
224 | + list($storage, $internalPath) = $this->resolvePath($path); |
|
225 | + return $storage->isReadable($internalPath); |
|
226 | + } |
|
227 | + |
|
228 | + public function isUpdatable($path) { |
|
229 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
230 | + } |
|
231 | + |
|
232 | + public function isDeletable($path) { |
|
233 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
234 | + } |
|
235 | + |
|
236 | + public function isSharable($path) { |
|
237 | + if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
238 | + return false; |
|
239 | + } |
|
240 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
241 | + } |
|
242 | + |
|
243 | + public function fopen($path, $mode) { |
|
244 | + if ($source = $this->getUnjailedPath($path)) { |
|
245 | + switch ($mode) { |
|
246 | + case 'r+': |
|
247 | + case 'rb+': |
|
248 | + case 'w+': |
|
249 | + case 'wb+': |
|
250 | + case 'x+': |
|
251 | + case 'xb+': |
|
252 | + case 'a+': |
|
253 | + case 'ab+': |
|
254 | + case 'w': |
|
255 | + case 'wb': |
|
256 | + case 'x': |
|
257 | + case 'xb': |
|
258 | + case 'a': |
|
259 | + case 'ab': |
|
260 | + $creatable = $this->isCreatable($path); |
|
261 | + $updatable = $this->isUpdatable($path); |
|
262 | + // if neither permissions given, no need to continue |
|
263 | + if (!$creatable && !$updatable) { |
|
264 | + return false; |
|
265 | + } |
|
266 | + |
|
267 | + $exists = $this->file_exists($path); |
|
268 | + // if a file exists, updatable permissions are required |
|
269 | + if ($exists && !$updatable) { |
|
270 | + return false; |
|
271 | + } |
|
272 | + |
|
273 | + // part file is allowed if !$creatable but the final file is $updatable |
|
274 | + if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
275 | + if (!$exists && !$creatable) { |
|
276 | + return false; |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | + $info = array( |
|
281 | + 'target' => $this->getMountPoint() . $path, |
|
282 | + 'source' => $source, |
|
283 | + 'mode' => $mode, |
|
284 | + ); |
|
285 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
286 | + return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
287 | + } |
|
288 | + return false; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * see http://php.net/manual/en/function.rename.php |
|
293 | + * |
|
294 | + * @param string $path1 |
|
295 | + * @param string $path2 |
|
296 | + * @return bool |
|
297 | + */ |
|
298 | + public function rename($path1, $path2) { |
|
299 | + $this->init(); |
|
300 | + $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
301 | + $targetExists = $this->file_exists($path2); |
|
302 | + $sameFodler = dirname($path1) === dirname($path2); |
|
303 | + |
|
304 | + if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
305 | + if (!$this->isUpdatable('')) { |
|
306 | + return false; |
|
307 | + } |
|
308 | + } else { |
|
309 | + if (!$this->isCreatable('')) { |
|
310 | + return false; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * return mount point of share, relative to data/user/files |
|
319 | + * |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + public function getMountPoint() { |
|
323 | + return $this->superShare->getTarget(); |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * @param string $path |
|
328 | + */ |
|
329 | + public function setMountPoint($path) { |
|
330 | + $this->superShare->setTarget($path); |
|
331 | + |
|
332 | + foreach ($this->groupedShares as $share) { |
|
333 | + $share->setTarget($path); |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * get the user who shared the file |
|
339 | + * |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function getSharedFrom() { |
|
343 | + return $this->superShare->getShareOwner(); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * @return \OCP\Share\IShare |
|
348 | + */ |
|
349 | + public function getShare() { |
|
350 | + return $this->superShare; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * return share type, can be "file" or "folder" |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function getItemType() { |
|
359 | + return $this->superShare->getNodeType(); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * @param string $path |
|
364 | + * @param null $storage |
|
365 | + * @return Cache |
|
366 | + */ |
|
367 | + public function getCache($path = '', $storage = null) { |
|
368 | + if ($this->cache) { |
|
369 | + return $this->cache; |
|
370 | + } |
|
371 | + if (!$storage) { |
|
372 | + $storage = $this; |
|
373 | + } |
|
374 | + $sourceRoot = $this->getSourceRootInfo(); |
|
375 | + if ($this->storage instanceof FailedStorage) { |
|
376 | + return new FailedCache(); |
|
377 | + } |
|
378 | + |
|
379 | + $this->cache = new \OCA\Files_Sharing\Cache($storage, $sourceRoot, $this->superShare); |
|
380 | + return $this->cache; |
|
381 | + } |
|
382 | + |
|
383 | + public function getScanner($path = '', $storage = null) { |
|
384 | + if (!$storage) { |
|
385 | + $storage = $this; |
|
386 | + } |
|
387 | + return new \OCA\Files_Sharing\Scanner($storage); |
|
388 | + } |
|
389 | + |
|
390 | + public function getOwner($path) { |
|
391 | + return $this->superShare->getShareOwner(); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * unshare complete storage, also the grouped shares |
|
396 | + * |
|
397 | + * @return bool |
|
398 | + */ |
|
399 | + public function unshareStorage() { |
|
400 | + foreach ($this->groupedShares as $share) { |
|
401 | + \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
402 | + } |
|
403 | + return true; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * @param string $path |
|
408 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
409 | + * @param \OCP\Lock\ILockingProvider $provider |
|
410 | + * @throws \OCP\Lock\LockedException |
|
411 | + */ |
|
412 | + public function acquireLock($path, $type, ILockingProvider $provider) { |
|
413 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
414 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
415 | + $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
416 | + // lock the parent folders of the owner when locking the share as recipient |
|
417 | + if ($path === '') { |
|
418 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
419 | + $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * @param string $path |
|
425 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
426 | + * @param \OCP\Lock\ILockingProvider $provider |
|
427 | + */ |
|
428 | + public function releaseLock($path, $type, ILockingProvider $provider) { |
|
429 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
430 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
431 | + $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
432 | + // unlock the parent folders of the owner when unlocking the share as recipient |
|
433 | + if ($path === '') { |
|
434 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
435 | + $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @param string $path |
|
441 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
442 | + * @param \OCP\Lock\ILockingProvider $provider |
|
443 | + */ |
|
444 | + public function changeLock($path, $type, ILockingProvider $provider) { |
|
445 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
446 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
447 | + $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * @return array [ available, last_checked ] |
|
452 | + */ |
|
453 | + public function getAvailability() { |
|
454 | + // shares do not participate in availability logic |
|
455 | + return [ |
|
456 | + 'available' => true, |
|
457 | + 'last_checked' => 0 |
|
458 | + ]; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * @param bool $available |
|
463 | + */ |
|
464 | + public function setAvailability($available) { |
|
465 | + // shares do not participate in availability logic |
|
466 | + } |
|
467 | + |
|
468 | + public function getSourceStorage() { |
|
469 | + $this->init(); |
|
470 | + return $this->nonMaskedStorage; |
|
471 | + } |
|
472 | + |
|
473 | + public function getWrapperStorage() { |
|
474 | + $this->init(); |
|
475 | + return $this->storage; |
|
476 | + } |
|
477 | + |
|
478 | + public function file_get_contents($path) { |
|
479 | + $info = [ |
|
480 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
481 | + 'source' => $this->getUnjailedPath($path), |
|
482 | + ]; |
|
483 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
484 | + return parent::file_get_contents($path); |
|
485 | + } |
|
486 | + |
|
487 | + public function file_put_contents($path, $data) { |
|
488 | + $info = [ |
|
489 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
490 | + 'source' => $this->getUnjailedPath($path), |
|
491 | + ]; |
|
492 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
493 | + return parent::file_put_contents($path, $data); |
|
494 | + } |
|
495 | + |
|
496 | + public function setMountOptions(array $options) { |
|
497 | + $this->mountOptions = $options; |
|
498 | + } |
|
499 | 499 | } |