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