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