Completed
Push — master ( dd8350...1fcb5d )
by Roeland
12:26 queued 12s
created
lib/private/Files/Storage/Wrapper/Jail.php 2 patches
Indentation   +478 added lines, -478 removed lines patch added patch discarded remove patch
@@ -37,482 +37,482 @@
 block discarded – undo
37 37
  * This restricts access to a subfolder of the wrapped storage with the subfolder becoming the root folder new storage
38 38
  */
39 39
 class Jail extends Wrapper {
40
-	/**
41
-	 * @var string
42
-	 */
43
-	protected $rootPath;
44
-
45
-	/**
46
-	 * @param array $arguments ['storage' => $storage, 'mask' => $root]
47
-	 *
48
-	 * $storage: The storage that will be wrapper
49
-	 * $root: The folder in the wrapped storage that will become the root folder of the wrapped storage
50
-	 */
51
-	public function __construct($arguments) {
52
-		parent::__construct($arguments);
53
-		$this->rootPath = $arguments['root'];
54
-	}
55
-
56
-	public function getUnjailedPath($path) {
57
-		if ($path === '') {
58
-			return $this->rootPath;
59
-		} else {
60
-			return Filesystem::normalizePath($this->rootPath . '/' . $path);
61
-		}
62
-	}
63
-
64
-	public function getJailedPath($path) {
65
-		$root = rtrim($this->rootPath, '/') . '/';
66
-
67
-		if (strpos($path, $root) !== 0) {
68
-			return null;
69
-		} else {
70
-			$path = substr($path, strlen($this->rootPath));
71
-			return trim($path, '/');
72
-		}
73
-	}
74
-
75
-	public function getId() {
76
-		return parent::getId();
77
-	}
78
-
79
-	/**
80
-	 * see http://php.net/manual/en/function.mkdir.php
81
-	 *
82
-	 * @param string $path
83
-	 * @return bool
84
-	 */
85
-	public function mkdir($path) {
86
-		return $this->getWrapperStorage()->mkdir($this->getUnjailedPath($path));
87
-	}
88
-
89
-	/**
90
-	 * see http://php.net/manual/en/function.rmdir.php
91
-	 *
92
-	 * @param string $path
93
-	 * @return bool
94
-	 */
95
-	public function rmdir($path) {
96
-		return $this->getWrapperStorage()->rmdir($this->getUnjailedPath($path));
97
-	}
98
-
99
-	/**
100
-	 * see http://php.net/manual/en/function.opendir.php
101
-	 *
102
-	 * @param string $path
103
-	 * @return resource
104
-	 */
105
-	public function opendir($path) {
106
-		return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path));
107
-	}
108
-
109
-	/**
110
-	 * see http://php.net/manual/en/function.is_dir.php
111
-	 *
112
-	 * @param string $path
113
-	 * @return bool
114
-	 */
115
-	public function is_dir($path) {
116
-		return $this->getWrapperStorage()->is_dir($this->getUnjailedPath($path));
117
-	}
118
-
119
-	/**
120
-	 * see http://php.net/manual/en/function.is_file.php
121
-	 *
122
-	 * @param string $path
123
-	 * @return bool
124
-	 */
125
-	public function is_file($path) {
126
-		return $this->getWrapperStorage()->is_file($this->getUnjailedPath($path));
127
-	}
128
-
129
-	/**
130
-	 * see http://php.net/manual/en/function.stat.php
131
-	 * only the following keys are required in the result: size and mtime
132
-	 *
133
-	 * @param string $path
134
-	 * @return array
135
-	 */
136
-	public function stat($path) {
137
-		return $this->getWrapperStorage()->stat($this->getUnjailedPath($path));
138
-	}
139
-
140
-	/**
141
-	 * see http://php.net/manual/en/function.filetype.php
142
-	 *
143
-	 * @param string $path
144
-	 * @return bool
145
-	 */
146
-	public function filetype($path) {
147
-		return $this->getWrapperStorage()->filetype($this->getUnjailedPath($path));
148
-	}
149
-
150
-	/**
151
-	 * see http://php.net/manual/en/function.filesize.php
152
-	 * The result for filesize when called on a folder is required to be 0
153
-	 *
154
-	 * @param string $path
155
-	 * @return int
156
-	 */
157
-	public function filesize($path) {
158
-		return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path));
159
-	}
160
-
161
-	/**
162
-	 * check if a file can be created in $path
163
-	 *
164
-	 * @param string $path
165
-	 * @return bool
166
-	 */
167
-	public function isCreatable($path) {
168
-		return $this->getWrapperStorage()->isCreatable($this->getUnjailedPath($path));
169
-	}
170
-
171
-	/**
172
-	 * check if a file can be read
173
-	 *
174
-	 * @param string $path
175
-	 * @return bool
176
-	 */
177
-	public function isReadable($path) {
178
-		return $this->getWrapperStorage()->isReadable($this->getUnjailedPath($path));
179
-	}
180
-
181
-	/**
182
-	 * check if a file can be written to
183
-	 *
184
-	 * @param string $path
185
-	 * @return bool
186
-	 */
187
-	public function isUpdatable($path) {
188
-		return $this->getWrapperStorage()->isUpdatable($this->getUnjailedPath($path));
189
-	}
190
-
191
-	/**
192
-	 * check if a file can be deleted
193
-	 *
194
-	 * @param string $path
195
-	 * @return bool
196
-	 */
197
-	public function isDeletable($path) {
198
-		return $this->getWrapperStorage()->isDeletable($this->getUnjailedPath($path));
199
-	}
200
-
201
-	/**
202
-	 * check if a file can be shared
203
-	 *
204
-	 * @param string $path
205
-	 * @return bool
206
-	 */
207
-	public function isSharable($path) {
208
-		return $this->getWrapperStorage()->isSharable($this->getUnjailedPath($path));
209
-	}
210
-
211
-	/**
212
-	 * get the full permissions of a path.
213
-	 * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
214
-	 *
215
-	 * @param string $path
216
-	 * @return int
217
-	 */
218
-	public function getPermissions($path) {
219
-		return $this->getWrapperStorage()->getPermissions($this->getUnjailedPath($path));
220
-	}
221
-
222
-	/**
223
-	 * see http://php.net/manual/en/function.file_exists.php
224
-	 *
225
-	 * @param string $path
226
-	 * @return bool
227
-	 */
228
-	public function file_exists($path) {
229
-		return $this->getWrapperStorage()->file_exists($this->getUnjailedPath($path));
230
-	}
231
-
232
-	/**
233
-	 * see http://php.net/manual/en/function.filemtime.php
234
-	 *
235
-	 * @param string $path
236
-	 * @return int
237
-	 */
238
-	public function filemtime($path) {
239
-		return $this->getWrapperStorage()->filemtime($this->getUnjailedPath($path));
240
-	}
241
-
242
-	/**
243
-	 * see http://php.net/manual/en/function.file_get_contents.php
244
-	 *
245
-	 * @param string $path
246
-	 * @return string
247
-	 */
248
-	public function file_get_contents($path) {
249
-		return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path));
250
-	}
251
-
252
-	/**
253
-	 * see http://php.net/manual/en/function.file_put_contents.php
254
-	 *
255
-	 * @param string $path
256
-	 * @param string $data
257
-	 * @return bool
258
-	 */
259
-	public function file_put_contents($path, $data) {
260
-		return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data);
261
-	}
262
-
263
-	/**
264
-	 * see http://php.net/manual/en/function.unlink.php
265
-	 *
266
-	 * @param string $path
267
-	 * @return bool
268
-	 */
269
-	public function unlink($path) {
270
-		return $this->getWrapperStorage()->unlink($this->getUnjailedPath($path));
271
-	}
272
-
273
-	/**
274
-	 * see http://php.net/manual/en/function.rename.php
275
-	 *
276
-	 * @param string $path1
277
-	 * @param string $path2
278
-	 * @return bool
279
-	 */
280
-	public function rename($path1, $path2) {
281
-		return $this->getWrapperStorage()->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
282
-	}
283
-
284
-	/**
285
-	 * see http://php.net/manual/en/function.copy.php
286
-	 *
287
-	 * @param string $path1
288
-	 * @param string $path2
289
-	 * @return bool
290
-	 */
291
-	public function copy($path1, $path2) {
292
-		return $this->getWrapperStorage()->copy($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
293
-	}
294
-
295
-	/**
296
-	 * see http://php.net/manual/en/function.fopen.php
297
-	 *
298
-	 * @param string $path
299
-	 * @param string $mode
300
-	 * @return resource
301
-	 */
302
-	public function fopen($path, $mode) {
303
-		return $this->getWrapperStorage()->fopen($this->getUnjailedPath($path), $mode);
304
-	}
305
-
306
-	/**
307
-	 * get the mimetype for a file or folder
308
-	 * The mimetype for a folder is required to be "httpd/unix-directory"
309
-	 *
310
-	 * @param string $path
311
-	 * @return string
312
-	 */
313
-	public function getMimeType($path) {
314
-		return $this->getWrapperStorage()->getMimeType($this->getUnjailedPath($path));
315
-	}
316
-
317
-	/**
318
-	 * see http://php.net/manual/en/function.hash.php
319
-	 *
320
-	 * @param string $type
321
-	 * @param string $path
322
-	 * @param bool $raw
323
-	 * @return string
324
-	 */
325
-	public function hash($type, $path, $raw = false) {
326
-		return $this->getWrapperStorage()->hash($type, $this->getUnjailedPath($path), $raw);
327
-	}
328
-
329
-	/**
330
-	 * see http://php.net/manual/en/function.free_space.php
331
-	 *
332
-	 * @param string $path
333
-	 * @return int
334
-	 */
335
-	public function free_space($path) {
336
-		return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path));
337
-	}
338
-
339
-	/**
340
-	 * search for occurrences of $query in file names
341
-	 *
342
-	 * @param string $query
343
-	 * @return array
344
-	 */
345
-	public function search($query) {
346
-		return $this->getWrapperStorage()->search($query);
347
-	}
348
-
349
-	/**
350
-	 * see http://php.net/manual/en/function.touch.php
351
-	 * If the backend does not support the operation, false should be returned
352
-	 *
353
-	 * @param string $path
354
-	 * @param int $mtime
355
-	 * @return bool
356
-	 */
357
-	public function touch($path, $mtime = null) {
358
-		return $this->getWrapperStorage()->touch($this->getUnjailedPath($path), $mtime);
359
-	}
360
-
361
-	/**
362
-	 * get the path to a local version of the file.
363
-	 * The local version of the file can be temporary and doesn't have to be persistent across requests
364
-	 *
365
-	 * @param string $path
366
-	 * @return string
367
-	 */
368
-	public function getLocalFile($path) {
369
-		return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path));
370
-	}
371
-
372
-	/**
373
-	 * check if a file or folder has been updated since $time
374
-	 *
375
-	 * @param string $path
376
-	 * @param int $time
377
-	 * @return bool
378
-	 *
379
-	 * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
380
-	 * returning true for other changes in the folder is optional
381
-	 */
382
-	public function hasUpdated($path, $time) {
383
-		return $this->getWrapperStorage()->hasUpdated($this->getUnjailedPath($path), $time);
384
-	}
385
-
386
-	/**
387
-	 * get a cache instance for the storage
388
-	 *
389
-	 * @param string $path
390
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
391
-	 * @return \OC\Files\Cache\Cache
392
-	 */
393
-	public function getCache($path = '', $storage = null) {
394
-		if (!$storage) {
395
-			$storage = $this->getWrapperStorage();
396
-		}
397
-		$sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path), $storage);
398
-		return new CacheJail($sourceCache, $this->rootPath);
399
-	}
400
-
401
-	/**
402
-	 * get the user id of the owner of a file or folder
403
-	 *
404
-	 * @param string $path
405
-	 * @return string
406
-	 */
407
-	public function getOwner($path) {
408
-		return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path));
409
-	}
410
-
411
-	/**
412
-	 * get a watcher instance for the cache
413
-	 *
414
-	 * @param string $path
415
-	 * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
416
-	 * @return \OC\Files\Cache\Watcher
417
-	 */
418
-	public function getWatcher($path = '', $storage = null) {
419
-		if (!$storage) {
420
-			$storage = $this;
421
-		}
422
-		return $this->getWrapperStorage()->getWatcher($this->getUnjailedPath($path), $storage);
423
-	}
424
-
425
-	/**
426
-	 * get the ETag for a file or folder
427
-	 *
428
-	 * @param string $path
429
-	 * @return string
430
-	 */
431
-	public function getETag($path) {
432
-		return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path));
433
-	}
434
-
435
-	/**
436
-	 * @param string $path
437
-	 * @return array
438
-	 */
439
-	public function getMetaData($path) {
440
-		return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path));
441
-	}
442
-
443
-	/**
444
-	 * @param string $path
445
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
446
-	 * @param \OCP\Lock\ILockingProvider $provider
447
-	 * @throws \OCP\Lock\LockedException
448
-	 */
449
-	public function acquireLock($path, $type, ILockingProvider $provider) {
450
-		$this->getWrapperStorage()->acquireLock($this->getUnjailedPath($path), $type, $provider);
451
-	}
452
-
453
-	/**
454
-	 * @param string $path
455
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
456
-	 * @param \OCP\Lock\ILockingProvider $provider
457
-	 */
458
-	public function releaseLock($path, $type, ILockingProvider $provider) {
459
-		$this->getWrapperStorage()->releaseLock($this->getUnjailedPath($path), $type, $provider);
460
-	}
461
-
462
-	/**
463
-	 * @param string $path
464
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
465
-	 * @param \OCP\Lock\ILockingProvider $provider
466
-	 */
467
-	public function changeLock($path, $type, ILockingProvider $provider) {
468
-		$this->getWrapperStorage()->changeLock($this->getUnjailedPath($path), $type, $provider);
469
-	}
470
-
471
-	/**
472
-	 * Resolve the path for the source of the share
473
-	 *
474
-	 * @param string $path
475
-	 * @return array
476
-	 */
477
-	public function resolvePath($path) {
478
-		return [$this->getWrapperStorage(), $this->getUnjailedPath($path)];
479
-	}
480
-
481
-	/**
482
-	 * @param IStorage $sourceStorage
483
-	 * @param string $sourceInternalPath
484
-	 * @param string $targetInternalPath
485
-	 * @return bool
486
-	 */
487
-	public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
488
-		if ($sourceStorage === $this) {
489
-			return $this->copy($sourceInternalPath, $targetInternalPath);
490
-		}
491
-		return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
492
-	}
493
-
494
-	/**
495
-	 * @param IStorage $sourceStorage
496
-	 * @param string $sourceInternalPath
497
-	 * @param string $targetInternalPath
498
-	 * @return bool
499
-	 */
500
-	public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
501
-		if ($sourceStorage === $this) {
502
-			return $this->rename($sourceInternalPath, $targetInternalPath);
503
-		}
504
-		return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
505
-	}
506
-
507
-	public function getPropagator($storage = null) {
508
-		if (isset($this->propagator)) {
509
-			return $this->propagator;
510
-		}
511
-
512
-		if (!$storage) {
513
-			$storage = $this;
514
-		}
515
-		$this->propagator = new JailPropagator($storage, \OC::$server->getDatabaseConnection());
516
-		return $this->propagator;
517
-	}
40
+    /**
41
+     * @var string
42
+     */
43
+    protected $rootPath;
44
+
45
+    /**
46
+     * @param array $arguments ['storage' => $storage, 'mask' => $root]
47
+     *
48
+     * $storage: The storage that will be wrapper
49
+     * $root: The folder in the wrapped storage that will become the root folder of the wrapped storage
50
+     */
51
+    public function __construct($arguments) {
52
+        parent::__construct($arguments);
53
+        $this->rootPath = $arguments['root'];
54
+    }
55
+
56
+    public function getUnjailedPath($path) {
57
+        if ($path === '') {
58
+            return $this->rootPath;
59
+        } else {
60
+            return Filesystem::normalizePath($this->rootPath . '/' . $path);
61
+        }
62
+    }
63
+
64
+    public function getJailedPath($path) {
65
+        $root = rtrim($this->rootPath, '/') . '/';
66
+
67
+        if (strpos($path, $root) !== 0) {
68
+            return null;
69
+        } else {
70
+            $path = substr($path, strlen($this->rootPath));
71
+            return trim($path, '/');
72
+        }
73
+    }
74
+
75
+    public function getId() {
76
+        return parent::getId();
77
+    }
78
+
79
+    /**
80
+     * see http://php.net/manual/en/function.mkdir.php
81
+     *
82
+     * @param string $path
83
+     * @return bool
84
+     */
85
+    public function mkdir($path) {
86
+        return $this->getWrapperStorage()->mkdir($this->getUnjailedPath($path));
87
+    }
88
+
89
+    /**
90
+     * see http://php.net/manual/en/function.rmdir.php
91
+     *
92
+     * @param string $path
93
+     * @return bool
94
+     */
95
+    public function rmdir($path) {
96
+        return $this->getWrapperStorage()->rmdir($this->getUnjailedPath($path));
97
+    }
98
+
99
+    /**
100
+     * see http://php.net/manual/en/function.opendir.php
101
+     *
102
+     * @param string $path
103
+     * @return resource
104
+     */
105
+    public function opendir($path) {
106
+        return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path));
107
+    }
108
+
109
+    /**
110
+     * see http://php.net/manual/en/function.is_dir.php
111
+     *
112
+     * @param string $path
113
+     * @return bool
114
+     */
115
+    public function is_dir($path) {
116
+        return $this->getWrapperStorage()->is_dir($this->getUnjailedPath($path));
117
+    }
118
+
119
+    /**
120
+     * see http://php.net/manual/en/function.is_file.php
121
+     *
122
+     * @param string $path
123
+     * @return bool
124
+     */
125
+    public function is_file($path) {
126
+        return $this->getWrapperStorage()->is_file($this->getUnjailedPath($path));
127
+    }
128
+
129
+    /**
130
+     * see http://php.net/manual/en/function.stat.php
131
+     * only the following keys are required in the result: size and mtime
132
+     *
133
+     * @param string $path
134
+     * @return array
135
+     */
136
+    public function stat($path) {
137
+        return $this->getWrapperStorage()->stat($this->getUnjailedPath($path));
138
+    }
139
+
140
+    /**
141
+     * see http://php.net/manual/en/function.filetype.php
142
+     *
143
+     * @param string $path
144
+     * @return bool
145
+     */
146
+    public function filetype($path) {
147
+        return $this->getWrapperStorage()->filetype($this->getUnjailedPath($path));
148
+    }
149
+
150
+    /**
151
+     * see http://php.net/manual/en/function.filesize.php
152
+     * The result for filesize when called on a folder is required to be 0
153
+     *
154
+     * @param string $path
155
+     * @return int
156
+     */
157
+    public function filesize($path) {
158
+        return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path));
159
+    }
160
+
161
+    /**
162
+     * check if a file can be created in $path
163
+     *
164
+     * @param string $path
165
+     * @return bool
166
+     */
167
+    public function isCreatable($path) {
168
+        return $this->getWrapperStorage()->isCreatable($this->getUnjailedPath($path));
169
+    }
170
+
171
+    /**
172
+     * check if a file can be read
173
+     *
174
+     * @param string $path
175
+     * @return bool
176
+     */
177
+    public function isReadable($path) {
178
+        return $this->getWrapperStorage()->isReadable($this->getUnjailedPath($path));
179
+    }
180
+
181
+    /**
182
+     * check if a file can be written to
183
+     *
184
+     * @param string $path
185
+     * @return bool
186
+     */
187
+    public function isUpdatable($path) {
188
+        return $this->getWrapperStorage()->isUpdatable($this->getUnjailedPath($path));
189
+    }
190
+
191
+    /**
192
+     * check if a file can be deleted
193
+     *
194
+     * @param string $path
195
+     * @return bool
196
+     */
197
+    public function isDeletable($path) {
198
+        return $this->getWrapperStorage()->isDeletable($this->getUnjailedPath($path));
199
+    }
200
+
201
+    /**
202
+     * check if a file can be shared
203
+     *
204
+     * @param string $path
205
+     * @return bool
206
+     */
207
+    public function isSharable($path) {
208
+        return $this->getWrapperStorage()->isSharable($this->getUnjailedPath($path));
209
+    }
210
+
211
+    /**
212
+     * get the full permissions of a path.
213
+     * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
214
+     *
215
+     * @param string $path
216
+     * @return int
217
+     */
218
+    public function getPermissions($path) {
219
+        return $this->getWrapperStorage()->getPermissions($this->getUnjailedPath($path));
220
+    }
221
+
222
+    /**
223
+     * see http://php.net/manual/en/function.file_exists.php
224
+     *
225
+     * @param string $path
226
+     * @return bool
227
+     */
228
+    public function file_exists($path) {
229
+        return $this->getWrapperStorage()->file_exists($this->getUnjailedPath($path));
230
+    }
231
+
232
+    /**
233
+     * see http://php.net/manual/en/function.filemtime.php
234
+     *
235
+     * @param string $path
236
+     * @return int
237
+     */
238
+    public function filemtime($path) {
239
+        return $this->getWrapperStorage()->filemtime($this->getUnjailedPath($path));
240
+    }
241
+
242
+    /**
243
+     * see http://php.net/manual/en/function.file_get_contents.php
244
+     *
245
+     * @param string $path
246
+     * @return string
247
+     */
248
+    public function file_get_contents($path) {
249
+        return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path));
250
+    }
251
+
252
+    /**
253
+     * see http://php.net/manual/en/function.file_put_contents.php
254
+     *
255
+     * @param string $path
256
+     * @param string $data
257
+     * @return bool
258
+     */
259
+    public function file_put_contents($path, $data) {
260
+        return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data);
261
+    }
262
+
263
+    /**
264
+     * see http://php.net/manual/en/function.unlink.php
265
+     *
266
+     * @param string $path
267
+     * @return bool
268
+     */
269
+    public function unlink($path) {
270
+        return $this->getWrapperStorage()->unlink($this->getUnjailedPath($path));
271
+    }
272
+
273
+    /**
274
+     * see http://php.net/manual/en/function.rename.php
275
+     *
276
+     * @param string $path1
277
+     * @param string $path2
278
+     * @return bool
279
+     */
280
+    public function rename($path1, $path2) {
281
+        return $this->getWrapperStorage()->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
282
+    }
283
+
284
+    /**
285
+     * see http://php.net/manual/en/function.copy.php
286
+     *
287
+     * @param string $path1
288
+     * @param string $path2
289
+     * @return bool
290
+     */
291
+    public function copy($path1, $path2) {
292
+        return $this->getWrapperStorage()->copy($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
293
+    }
294
+
295
+    /**
296
+     * see http://php.net/manual/en/function.fopen.php
297
+     *
298
+     * @param string $path
299
+     * @param string $mode
300
+     * @return resource
301
+     */
302
+    public function fopen($path, $mode) {
303
+        return $this->getWrapperStorage()->fopen($this->getUnjailedPath($path), $mode);
304
+    }
305
+
306
+    /**
307
+     * get the mimetype for a file or folder
308
+     * The mimetype for a folder is required to be "httpd/unix-directory"
309
+     *
310
+     * @param string $path
311
+     * @return string
312
+     */
313
+    public function getMimeType($path) {
314
+        return $this->getWrapperStorage()->getMimeType($this->getUnjailedPath($path));
315
+    }
316
+
317
+    /**
318
+     * see http://php.net/manual/en/function.hash.php
319
+     *
320
+     * @param string $type
321
+     * @param string $path
322
+     * @param bool $raw
323
+     * @return string
324
+     */
325
+    public function hash($type, $path, $raw = false) {
326
+        return $this->getWrapperStorage()->hash($type, $this->getUnjailedPath($path), $raw);
327
+    }
328
+
329
+    /**
330
+     * see http://php.net/manual/en/function.free_space.php
331
+     *
332
+     * @param string $path
333
+     * @return int
334
+     */
335
+    public function free_space($path) {
336
+        return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path));
337
+    }
338
+
339
+    /**
340
+     * search for occurrences of $query in file names
341
+     *
342
+     * @param string $query
343
+     * @return array
344
+     */
345
+    public function search($query) {
346
+        return $this->getWrapperStorage()->search($query);
347
+    }
348
+
349
+    /**
350
+     * see http://php.net/manual/en/function.touch.php
351
+     * If the backend does not support the operation, false should be returned
352
+     *
353
+     * @param string $path
354
+     * @param int $mtime
355
+     * @return bool
356
+     */
357
+    public function touch($path, $mtime = null) {
358
+        return $this->getWrapperStorage()->touch($this->getUnjailedPath($path), $mtime);
359
+    }
360
+
361
+    /**
362
+     * get the path to a local version of the file.
363
+     * The local version of the file can be temporary and doesn't have to be persistent across requests
364
+     *
365
+     * @param string $path
366
+     * @return string
367
+     */
368
+    public function getLocalFile($path) {
369
+        return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path));
370
+    }
371
+
372
+    /**
373
+     * check if a file or folder has been updated since $time
374
+     *
375
+     * @param string $path
376
+     * @param int $time
377
+     * @return bool
378
+     *
379
+     * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
380
+     * returning true for other changes in the folder is optional
381
+     */
382
+    public function hasUpdated($path, $time) {
383
+        return $this->getWrapperStorage()->hasUpdated($this->getUnjailedPath($path), $time);
384
+    }
385
+
386
+    /**
387
+     * get a cache instance for the storage
388
+     *
389
+     * @param string $path
390
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache
391
+     * @return \OC\Files\Cache\Cache
392
+     */
393
+    public function getCache($path = '', $storage = null) {
394
+        if (!$storage) {
395
+            $storage = $this->getWrapperStorage();
396
+        }
397
+        $sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path), $storage);
398
+        return new CacheJail($sourceCache, $this->rootPath);
399
+    }
400
+
401
+    /**
402
+     * get the user id of the owner of a file or folder
403
+     *
404
+     * @param string $path
405
+     * @return string
406
+     */
407
+    public function getOwner($path) {
408
+        return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path));
409
+    }
410
+
411
+    /**
412
+     * get a watcher instance for the cache
413
+     *
414
+     * @param string $path
415
+     * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher
416
+     * @return \OC\Files\Cache\Watcher
417
+     */
418
+    public function getWatcher($path = '', $storage = null) {
419
+        if (!$storage) {
420
+            $storage = $this;
421
+        }
422
+        return $this->getWrapperStorage()->getWatcher($this->getUnjailedPath($path), $storage);
423
+    }
424
+
425
+    /**
426
+     * get the ETag for a file or folder
427
+     *
428
+     * @param string $path
429
+     * @return string
430
+     */
431
+    public function getETag($path) {
432
+        return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path));
433
+    }
434
+
435
+    /**
436
+     * @param string $path
437
+     * @return array
438
+     */
439
+    public function getMetaData($path) {
440
+        return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path));
441
+    }
442
+
443
+    /**
444
+     * @param string $path
445
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
446
+     * @param \OCP\Lock\ILockingProvider $provider
447
+     * @throws \OCP\Lock\LockedException
448
+     */
449
+    public function acquireLock($path, $type, ILockingProvider $provider) {
450
+        $this->getWrapperStorage()->acquireLock($this->getUnjailedPath($path), $type, $provider);
451
+    }
452
+
453
+    /**
454
+     * @param string $path
455
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
456
+     * @param \OCP\Lock\ILockingProvider $provider
457
+     */
458
+    public function releaseLock($path, $type, ILockingProvider $provider) {
459
+        $this->getWrapperStorage()->releaseLock($this->getUnjailedPath($path), $type, $provider);
460
+    }
461
+
462
+    /**
463
+     * @param string $path
464
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
465
+     * @param \OCP\Lock\ILockingProvider $provider
466
+     */
467
+    public function changeLock($path, $type, ILockingProvider $provider) {
468
+        $this->getWrapperStorage()->changeLock($this->getUnjailedPath($path), $type, $provider);
469
+    }
470
+
471
+    /**
472
+     * Resolve the path for the source of the share
473
+     *
474
+     * @param string $path
475
+     * @return array
476
+     */
477
+    public function resolvePath($path) {
478
+        return [$this->getWrapperStorage(), $this->getUnjailedPath($path)];
479
+    }
480
+
481
+    /**
482
+     * @param IStorage $sourceStorage
483
+     * @param string $sourceInternalPath
484
+     * @param string $targetInternalPath
485
+     * @return bool
486
+     */
487
+    public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
488
+        if ($sourceStorage === $this) {
489
+            return $this->copy($sourceInternalPath, $targetInternalPath);
490
+        }
491
+        return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
492
+    }
493
+
494
+    /**
495
+     * @param IStorage $sourceStorage
496
+     * @param string $sourceInternalPath
497
+     * @param string $targetInternalPath
498
+     * @return bool
499
+     */
500
+    public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
501
+        if ($sourceStorage === $this) {
502
+            return $this->rename($sourceInternalPath, $targetInternalPath);
503
+        }
504
+        return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
505
+    }
506
+
507
+    public function getPropagator($storage = null) {
508
+        if (isset($this->propagator)) {
509
+            return $this->propagator;
510
+        }
511
+
512
+        if (!$storage) {
513
+            $storage = $this;
514
+        }
515
+        $this->propagator = new JailPropagator($storage, \OC::$server->getDatabaseConnection());
516
+        return $this->propagator;
517
+    }
518 518
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,12 +57,12 @@
 block discarded – undo
57 57
 		if ($path === '') {
58 58
 			return $this->rootPath;
59 59
 		} else {
60
-			return Filesystem::normalizePath($this->rootPath . '/' . $path);
60
+			return Filesystem::normalizePath($this->rootPath.'/'.$path);
61 61
 		}
62 62
 	}
63 63
 
64 64
 	public function getJailedPath($path) {
65
-		$root = rtrim($this->rootPath, '/') . '/';
65
+		$root = rtrim($this->rootPath, '/').'/';
66 66
 
67 67
 		if (strpos($path, $root) !== 0) {
68 68
 			return null;
Please login to merge, or discard this patch.