Completed
Push — master ( 7c8b3c...2634ce )
by Blizzz
23:36 queued 10s
created
apps/files_sharing/lib/SharedStorage.php 2 patches
Indentation   +455 added lines, -455 removed lines patch added patch discarded remove patch
@@ -48,459 +48,459 @@
 block discarded – undo
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 = parent::getPermissions($target) & $this->superShare->getPermissions();
199
-
200
-		// part files and the mount point always have delete permissions
201
-		if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
202
-			$permissions |= \OCP\Constants::PERMISSION_DELETE;
203
-		}
204
-
205
-		if ($this->sharingDisabledForUser) {
206
-			$permissions &= ~\OCP\Constants::PERMISSION_SHARE;
207
-		}
208
-
209
-		return $permissions;
210
-	}
211
-
212
-	public function isCreatable($path) {
213
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
214
-	}
215
-
216
-	public function isReadable($path) {
217
-		if (!$this->isValid()) {
218
-			return false;
219
-		}
220
-		if (!$this->file_exists($path)) {
221
-			return false;
222
-		}
223
-		/** @var IStorage $storage */
224
-		/** @var string $internalPath */
225
-		list($storage, $internalPath) = $this->resolvePath($path);
226
-		return $storage->isReadable($internalPath);
227
-	}
228
-
229
-	public function isUpdatable($path) {
230
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
231
-	}
232
-
233
-	public function isDeletable($path) {
234
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
235
-	}
236
-
237
-	public function isSharable($path) {
238
-		if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
239
-			return false;
240
-		}
241
-		return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
242
-	}
243
-
244
-	public function fopen($path, $mode) {
245
-		if ($source = $this->getUnjailedPath($path)) {
246
-			switch ($mode) {
247
-				case 'r+':
248
-				case 'rb+':
249
-				case 'w+':
250
-				case 'wb+':
251
-				case 'x+':
252
-				case 'xb+':
253
-				case 'a+':
254
-				case 'ab+':
255
-				case 'w':
256
-				case 'wb':
257
-				case 'x':
258
-				case 'xb':
259
-				case 'a':
260
-				case 'ab':
261
-					$creatable = $this->isCreatable(dirname($path));
262
-					$updatable = $this->isUpdatable($path);
263
-					// if neither permissions given, no need to continue
264
-					if (!$creatable && !$updatable) {
265
-						if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
266
-							$updatable = $this->isUpdatable(dirname($path));
267
-						}
268
-
269
-						if (!$updatable) {
270
-							return false;
271
-						}
272
-					}
273
-
274
-					$exists = $this->file_exists($path);
275
-					// if a file exists, updatable permissions are required
276
-					if ($exists && !$updatable) {
277
-						return false;
278
-					}
279
-
280
-					// part file is allowed if !$creatable but the final file is $updatable
281
-					if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') {
282
-						if (!$exists && !$creatable) {
283
-							return false;
284
-						}
285
-					}
286
-			}
287
-			$info = array(
288
-				'target' => $this->getMountPoint() . $path,
289
-				'source' => $source,
290
-				'mode' => $mode,
291
-			);
292
-			\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
293
-			return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode);
294
-		}
295
-		return false;
296
-	}
297
-
298
-	/**
299
-	 * see http://php.net/manual/en/function.rename.php
300
-	 *
301
-	 * @param string $path1
302
-	 * @param string $path2
303
-	 * @return bool
304
-	 */
305
-	public function rename($path1, $path2) {
306
-		$this->init();
307
-		$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
308
-		$targetExists = $this->file_exists($path2);
309
-		$sameFodler = dirname($path1) === dirname($path2);
310
-
311
-		if ($targetExists || ($sameFodler && !$isPartFile)) {
312
-			if (!$this->isUpdatable('')) {
313
-				return false;
314
-			}
315
-		} else {
316
-			if (!$this->isCreatable('')) {
317
-				return false;
318
-			}
319
-		}
320
-
321
-		return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
322
-	}
323
-
324
-	/**
325
-	 * return mount point of share, relative to data/user/files
326
-	 *
327
-	 * @return string
328
-	 */
329
-	public function getMountPoint() {
330
-		return $this->superShare->getTarget();
331
-	}
332
-
333
-	/**
334
-	 * @param string $path
335
-	 */
336
-	public function setMountPoint($path) {
337
-		$this->superShare->setTarget($path);
338
-
339
-		foreach ($this->groupedShares as $share) {
340
-			$share->setTarget($path);
341
-		}
342
-	}
343
-
344
-	/**
345
-	 * get the user who shared the file
346
-	 *
347
-	 * @return string
348
-	 */
349
-	public function getSharedFrom() {
350
-		return $this->superShare->getShareOwner();
351
-	}
352
-
353
-	/**
354
-	 * @return \OCP\Share\IShare
355
-	 */
356
-	public function getShare() {
357
-		return $this->superShare;
358
-	}
359
-
360
-	/**
361
-	 * return share type, can be "file" or "folder"
362
-	 *
363
-	 * @return string
364
-	 */
365
-	public function getItemType() {
366
-		return $this->superShare->getNodeType();
367
-	}
368
-
369
-	/**
370
-	 * @param string $path
371
-	 * @param null $storage
372
-	 * @return Cache
373
-	 */
374
-	public function getCache($path = '', $storage = null) {
375
-		if ($this->cache) {
376
-			return $this->cache;
377
-		}
378
-		if (!$storage) {
379
-			$storage = $this;
380
-		}
381
-		$sourceRoot  = $this->getSourceRootInfo();
382
-		if ($this->storage instanceof FailedStorage) {
383
-			return new FailedCache();
384
-		}
385
-
386
-		$this->cache = new \OCA\Files_Sharing\Cache($storage, $sourceRoot, $this->superShare);
387
-		return $this->cache;
388
-	}
389
-
390
-	public function getScanner($path = '', $storage = null) {
391
-		if (!$storage) {
392
-			$storage = $this;
393
-		}
394
-		return new \OCA\Files_Sharing\Scanner($storage);
395
-	}
396
-
397
-	public function getOwner($path) {
398
-		return $this->superShare->getShareOwner();
399
-	}
400
-
401
-	/**
402
-	 * unshare complete storage, also the grouped shares
403
-	 *
404
-	 * @return bool
405
-	 */
406
-	public function unshareStorage() {
407
-		foreach ($this->groupedShares as $share) {
408
-			\OC::$server->getShareManager()->deleteFromSelf($share, $this->user);
409
-		}
410
-		return true;
411
-	}
412
-
413
-	/**
414
-	 * @param string $path
415
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
416
-	 * @param \OCP\Lock\ILockingProvider $provider
417
-	 * @throws \OCP\Lock\LockedException
418
-	 */
419
-	public function acquireLock($path, $type, ILockingProvider $provider) {
420
-		/** @var \OCP\Files\Storage $targetStorage */
421
-		list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
422
-		$targetStorage->acquireLock($targetInternalPath, $type, $provider);
423
-		// lock the parent folders of the owner when locking the share as recipient
424
-		if ($path === '') {
425
-			$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
426
-			$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
427
-		}
428
-	}
429
-
430
-	/**
431
-	 * @param string $path
432
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
433
-	 * @param \OCP\Lock\ILockingProvider $provider
434
-	 */
435
-	public function releaseLock($path, $type, ILockingProvider $provider) {
436
-		/** @var \OCP\Files\Storage $targetStorage */
437
-		list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
438
-		$targetStorage->releaseLock($targetInternalPath, $type, $provider);
439
-		// unlock the parent folders of the owner when unlocking the share as recipient
440
-		if ($path === '') {
441
-			$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
442
-			$this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
443
-		}
444
-	}
445
-
446
-	/**
447
-	 * @param string $path
448
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
449
-	 * @param \OCP\Lock\ILockingProvider $provider
450
-	 */
451
-	public function changeLock($path, $type, ILockingProvider $provider) {
452
-		/** @var \OCP\Files\Storage $targetStorage */
453
-		list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
454
-		$targetStorage->changeLock($targetInternalPath, $type, $provider);
455
-	}
456
-
457
-	/**
458
-	 * @return array [ available, last_checked ]
459
-	 */
460
-	public function getAvailability() {
461
-		// shares do not participate in availability logic
462
-		return [
463
-			'available' => true,
464
-			'last_checked' => 0
465
-		];
466
-	}
467
-
468
-	/**
469
-	 * @param bool $available
470
-	 */
471
-	public function setAvailability($available) {
472
-		// shares do not participate in availability logic
473
-	}
474
-
475
-	public function getSourceStorage() {
476
-		$this->init();
477
-		return $this->nonMaskedStorage;
478
-	}
479
-
480
-	public function getWrapperStorage() {
481
-		$this->init();
482
-		return $this->storage;
483
-	}
484
-
485
-	public function file_get_contents($path) {
486
-		$info = [
487
-			'target' => $this->getMountPoint() . '/' . $path,
488
-			'source' => $this->getUnjailedPath($path),
489
-		];
490
-		\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
491
-		return parent::file_get_contents($path);
492
-	}
493
-
494
-	public function file_put_contents($path, $data) {
495
-		$info = [
496
-			'target' => $this->getMountPoint() . '/' . $path,
497
-			'source' => $this->getUnjailedPath($path),
498
-		];
499
-		\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
500
-		return parent::file_put_contents($path, $data);
501
-	}
502
-
503
-	public function setMountOptions(array $options) {
504
-		$this->mountOptions = $options;
505
-	}
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 = parent::getPermissions($target) & $this->superShare->getPermissions();
199
+
200
+        // part files and the mount point always have delete permissions
201
+        if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') {
202
+            $permissions |= \OCP\Constants::PERMISSION_DELETE;
203
+        }
204
+
205
+        if ($this->sharingDisabledForUser) {
206
+            $permissions &= ~\OCP\Constants::PERMISSION_SHARE;
207
+        }
208
+
209
+        return $permissions;
210
+    }
211
+
212
+    public function isCreatable($path) {
213
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE);
214
+    }
215
+
216
+    public function isReadable($path) {
217
+        if (!$this->isValid()) {
218
+            return false;
219
+        }
220
+        if (!$this->file_exists($path)) {
221
+            return false;
222
+        }
223
+        /** @var IStorage $storage */
224
+        /** @var string $internalPath */
225
+        list($storage, $internalPath) = $this->resolvePath($path);
226
+        return $storage->isReadable($internalPath);
227
+    }
228
+
229
+    public function isUpdatable($path) {
230
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE);
231
+    }
232
+
233
+    public function isDeletable($path) {
234
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE);
235
+    }
236
+
237
+    public function isSharable($path) {
238
+        if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
239
+            return false;
240
+        }
241
+        return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE);
242
+    }
243
+
244
+    public function fopen($path, $mode) {
245
+        if ($source = $this->getUnjailedPath($path)) {
246
+            switch ($mode) {
247
+                case 'r+':
248
+                case 'rb+':
249
+                case 'w+':
250
+                case 'wb+':
251
+                case 'x+':
252
+                case 'xb+':
253
+                case 'a+':
254
+                case 'ab+':
255
+                case 'w':
256
+                case 'wb':
257
+                case 'x':
258
+                case 'xb':
259
+                case 'a':
260
+                case 'ab':
261
+                    $creatable = $this->isCreatable(dirname($path));
262
+                    $updatable = $this->isUpdatable($path);
263
+                    // if neither permissions given, no need to continue
264
+                    if (!$creatable && !$updatable) {
265
+                        if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
266
+                            $updatable = $this->isUpdatable(dirname($path));
267
+                        }
268
+
269
+                        if (!$updatable) {
270
+                            return false;
271
+                        }
272
+                    }
273
+
274
+                    $exists = $this->file_exists($path);
275
+                    // if a file exists, updatable permissions are required
276
+                    if ($exists && !$updatable) {
277
+                        return false;
278
+                    }
279
+
280
+                    // part file is allowed if !$creatable but the final file is $updatable
281
+                    if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') {
282
+                        if (!$exists && !$creatable) {
283
+                            return false;
284
+                        }
285
+                    }
286
+            }
287
+            $info = array(
288
+                'target' => $this->getMountPoint() . $path,
289
+                'source' => $source,
290
+                'mode' => $mode,
291
+            );
292
+            \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
293
+            return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode);
294
+        }
295
+        return false;
296
+    }
297
+
298
+    /**
299
+     * see http://php.net/manual/en/function.rename.php
300
+     *
301
+     * @param string $path1
302
+     * @param string $path2
303
+     * @return bool
304
+     */
305
+    public function rename($path1, $path2) {
306
+        $this->init();
307
+        $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
308
+        $targetExists = $this->file_exists($path2);
309
+        $sameFodler = dirname($path1) === dirname($path2);
310
+
311
+        if ($targetExists || ($sameFodler && !$isPartFile)) {
312
+            if (!$this->isUpdatable('')) {
313
+                return false;
314
+            }
315
+        } else {
316
+            if (!$this->isCreatable('')) {
317
+                return false;
318
+            }
319
+        }
320
+
321
+        return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
322
+    }
323
+
324
+    /**
325
+     * return mount point of share, relative to data/user/files
326
+     *
327
+     * @return string
328
+     */
329
+    public function getMountPoint() {
330
+        return $this->superShare->getTarget();
331
+    }
332
+
333
+    /**
334
+     * @param string $path
335
+     */
336
+    public function setMountPoint($path) {
337
+        $this->superShare->setTarget($path);
338
+
339
+        foreach ($this->groupedShares as $share) {
340
+            $share->setTarget($path);
341
+        }
342
+    }
343
+
344
+    /**
345
+     * get the user who shared the file
346
+     *
347
+     * @return string
348
+     */
349
+    public function getSharedFrom() {
350
+        return $this->superShare->getShareOwner();
351
+    }
352
+
353
+    /**
354
+     * @return \OCP\Share\IShare
355
+     */
356
+    public function getShare() {
357
+        return $this->superShare;
358
+    }
359
+
360
+    /**
361
+     * return share type, can be "file" or "folder"
362
+     *
363
+     * @return string
364
+     */
365
+    public function getItemType() {
366
+        return $this->superShare->getNodeType();
367
+    }
368
+
369
+    /**
370
+     * @param string $path
371
+     * @param null $storage
372
+     * @return Cache
373
+     */
374
+    public function getCache($path = '', $storage = null) {
375
+        if ($this->cache) {
376
+            return $this->cache;
377
+        }
378
+        if (!$storage) {
379
+            $storage = $this;
380
+        }
381
+        $sourceRoot  = $this->getSourceRootInfo();
382
+        if ($this->storage instanceof FailedStorage) {
383
+            return new FailedCache();
384
+        }
385
+
386
+        $this->cache = new \OCA\Files_Sharing\Cache($storage, $sourceRoot, $this->superShare);
387
+        return $this->cache;
388
+    }
389
+
390
+    public function getScanner($path = '', $storage = null) {
391
+        if (!$storage) {
392
+            $storage = $this;
393
+        }
394
+        return new \OCA\Files_Sharing\Scanner($storage);
395
+    }
396
+
397
+    public function getOwner($path) {
398
+        return $this->superShare->getShareOwner();
399
+    }
400
+
401
+    /**
402
+     * unshare complete storage, also the grouped shares
403
+     *
404
+     * @return bool
405
+     */
406
+    public function unshareStorage() {
407
+        foreach ($this->groupedShares as $share) {
408
+            \OC::$server->getShareManager()->deleteFromSelf($share, $this->user);
409
+        }
410
+        return true;
411
+    }
412
+
413
+    /**
414
+     * @param string $path
415
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
416
+     * @param \OCP\Lock\ILockingProvider $provider
417
+     * @throws \OCP\Lock\LockedException
418
+     */
419
+    public function acquireLock($path, $type, ILockingProvider $provider) {
420
+        /** @var \OCP\Files\Storage $targetStorage */
421
+        list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
422
+        $targetStorage->acquireLock($targetInternalPath, $type, $provider);
423
+        // lock the parent folders of the owner when locking the share as recipient
424
+        if ($path === '') {
425
+            $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
426
+            $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
427
+        }
428
+    }
429
+
430
+    /**
431
+     * @param string $path
432
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
433
+     * @param \OCP\Lock\ILockingProvider $provider
434
+     */
435
+    public function releaseLock($path, $type, ILockingProvider $provider) {
436
+        /** @var \OCP\Files\Storage $targetStorage */
437
+        list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
438
+        $targetStorage->releaseLock($targetInternalPath, $type, $provider);
439
+        // unlock the parent folders of the owner when unlocking the share as recipient
440
+        if ($path === '') {
441
+            $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
442
+            $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
443
+        }
444
+    }
445
+
446
+    /**
447
+     * @param string $path
448
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
449
+     * @param \OCP\Lock\ILockingProvider $provider
450
+     */
451
+    public function changeLock($path, $type, ILockingProvider $provider) {
452
+        /** @var \OCP\Files\Storage $targetStorage */
453
+        list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
454
+        $targetStorage->changeLock($targetInternalPath, $type, $provider);
455
+    }
456
+
457
+    /**
458
+     * @return array [ available, last_checked ]
459
+     */
460
+    public function getAvailability() {
461
+        // shares do not participate in availability logic
462
+        return [
463
+            'available' => true,
464
+            'last_checked' => 0
465
+        ];
466
+    }
467
+
468
+    /**
469
+     * @param bool $available
470
+     */
471
+    public function setAvailability($available) {
472
+        // shares do not participate in availability logic
473
+    }
474
+
475
+    public function getSourceStorage() {
476
+        $this->init();
477
+        return $this->nonMaskedStorage;
478
+    }
479
+
480
+    public function getWrapperStorage() {
481
+        $this->init();
482
+        return $this->storage;
483
+    }
484
+
485
+    public function file_get_contents($path) {
486
+        $info = [
487
+            'target' => $this->getMountPoint() . '/' . $path,
488
+            'source' => $this->getUnjailedPath($path),
489
+        ];
490
+        \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
491
+        return parent::file_get_contents($path);
492
+    }
493
+
494
+    public function file_put_contents($path, $data) {
495
+        $info = [
496
+            'target' => $this->getMountPoint() . '/' . $path,
497
+            'source' => $this->getUnjailedPath($path),
498
+        ];
499
+        \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
500
+        return parent::file_put_contents($path, $data);
501
+    }
502
+
503
+    public function setMountOptions(array $options) {
504
+        $this->mountOptions = $options;
505
+    }
506 506
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.