Completed
Pull Request — master (#9129)
by Joas
22:53
created
lib/private/Files/Node/Node.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 		$path = str_replace('\\', '/', $path);
289 289
 		//add leading slash
290 290
 		if ($path[0] !== '/') {
291
-			$path = '/' . $path;
291
+			$path = '/'.$path;
292 292
 		}
293 293
 		//remove duplicate slashes
294 294
 		while (strpos($path, '//') !== false) {
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 */
309 309
 	public function isValidPath($path) {
310 310
 		if (!$path || $path[0] !== '/') {
311
-			$path = '/' . $path;
311
+			$path = '/'.$path;
312 312
 		}
313 313
 		if (strstr($path, '/../') || strrchr($path, '/') === '/..') {
314 314
 			return false;
@@ -389,14 +389,14 @@  discard block
 block discarded – undo
389 389
 			$this->root->emit('\OC\Files', 'preCopy', [$this, $nonExisting]);
390 390
 			$this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
391 391
 			if (!$this->view->copy($this->path, $targetPath)) {
392
-				throw new NotPermittedException('Could not copy ' . $this->path . ' to ' . $targetPath);
392
+				throw new NotPermittedException('Could not copy '.$this->path.' to '.$targetPath);
393 393
 			}
394 394
 			$targetNode = $this->root->get($targetPath);
395 395
 			$this->root->emit('\OC\Files', 'postCopy', [$this, $targetNode]);
396 396
 			$this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
397 397
 			return $targetNode;
398 398
 		} else {
399
-			throw new NotPermittedException('No permission to copy to path ' . $targetPath);
399
+			throw new NotPermittedException('No permission to copy to path '.$targetPath);
400 400
 		}
401 401
 	}
402 402
 
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 			$this->root->emit('\OC\Files', 'preRename', [$this, $nonExisting]);
414 414
 			$this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
415 415
 			if (!$this->view->rename($this->path, $targetPath)) {
416
-				throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath);
416
+				throw new NotPermittedException('Could not move '.$this->path.' to '.$targetPath);
417 417
 			}
418 418
 			$targetNode = $this->root->get($targetPath);
419 419
 			$this->root->emit('\OC\Files', 'postRename', [$this, $targetNode]);
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 			$this->path = $targetPath;
422 422
 			return $targetNode;
423 423
 		} else {
424
-			throw new NotPermittedException('No permission to move to path ' . $targetPath);
424
+			throw new NotPermittedException('No permission to move to path '.$targetPath);
425 425
 		}
426 426
 	}
427 427
 
Please login to merge, or discard this patch.
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -35,392 +35,392 @@
 block discarded – undo
35 35
 
36 36
 // FIXME: this class really should be abstract
37 37
 class Node implements \OCP\Files\Node {
38
-	/**
39
-	 * @var \OC\Files\View $view
40
-	 */
41
-	protected $view;
42
-
43
-	/**
44
-	 * @var \OC\Files\Node\Root $root
45
-	 */
46
-	protected $root;
47
-
48
-	/**
49
-	 * @var string $path
50
-	 */
51
-	protected $path;
52
-
53
-	/**
54
-	 * @var \OCP\Files\FileInfo
55
-	 */
56
-	protected $fileInfo;
57
-
58
-	/**
59
-	 * @param \OC\Files\View $view
60
-	 * @param \OCP\Files\IRootFolder $root
61
-	 * @param string $path
62
-	 * @param FileInfo $fileInfo
63
-	 */
64
-	public function __construct($root, $view, $path, $fileInfo = null) {
65
-		$this->view = $view;
66
-		$this->root = $root;
67
-		$this->path = $path;
68
-		$this->fileInfo = $fileInfo;
69
-	}
70
-
71
-	/**
72
-	 * Creates a Node of the same type that represents a non-existing path
73
-	 *
74
-	 * @param string $path path
75
-	 * @return string non-existing node class
76
-	 */
77
-	protected function createNonExistingNode($path) {
78
-		throw new \Exception('Must be implemented by subclasses');
79
-	}
80
-
81
-	/**
82
-	 * Returns the matching file info
83
-	 *
84
-	 * @return FileInfo
85
-	 * @throws InvalidPathException
86
-	 * @throws NotFoundException
87
-	 */
88
-	public function getFileInfo() {
89
-		if (!Filesystem::isValidPath($this->path)) {
90
-			throw new InvalidPathException();
91
-		}
92
-		if (!$this->fileInfo) {
93
-			$fileInfo = $this->view->getFileInfo($this->path);
94
-			if ($fileInfo instanceof FileInfo) {
95
-				$this->fileInfo = $fileInfo;
96
-			} else {
97
-				throw new NotFoundException();
98
-			}
99
-		}
100
-		return $this->fileInfo;
101
-	}
102
-
103
-	/**
104
-	 * @param string[] $hooks
105
-	 */
106
-	protected function sendHooks($hooks) {
107
-		foreach ($hooks as $hook) {
108
-			$this->root->emit('\OC\Files', $hook, array($this));
109
-		}
110
-	}
111
-
112
-	/**
113
-	 * @param int $permissions
114
-	 * @return bool
115
-	 */
116
-	protected function checkPermissions($permissions) {
117
-		return ($this->getPermissions() & $permissions) === $permissions;
118
-	}
119
-
120
-	public function delete() {
121
-	}
122
-
123
-	/**
124
-	 * @param int $mtime
125
-	 * @throws \OCP\Files\NotPermittedException
126
-	 */
127
-	public function touch($mtime = null) {
128
-		if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
129
-			$this->sendHooks(array('preTouch'));
130
-			$this->view->touch($this->path, $mtime);
131
-			$this->sendHooks(array('postTouch'));
132
-			if ($this->fileInfo) {
133
-				if (is_null($mtime)) {
134
-					$mtime = time();
135
-				}
136
-				$this->fileInfo['mtime'] = $mtime;
137
-			}
138
-		} else {
139
-			throw new NotPermittedException();
140
-		}
141
-	}
142
-
143
-	/**
144
-	 * @return \OC\Files\Storage\Storage
145
-	 * @throws \OCP\Files\NotFoundException
146
-	 */
147
-	public function getStorage() {
148
-		list($storage,) = $this->view->resolvePath($this->path);
149
-		return $storage;
150
-	}
151
-
152
-	/**
153
-	 * @return string
154
-	 */
155
-	public function getPath() {
156
-		return $this->path;
157
-	}
158
-
159
-	/**
160
-	 * @return string
161
-	 */
162
-	public function getInternalPath() {
163
-		list(, $internalPath) = $this->view->resolvePath($this->path);
164
-		return $internalPath;
165
-	}
166
-
167
-	/**
168
-	 * @return int
169
-	 * @throws InvalidPathException
170
-	 * @throws NotFoundException
171
-	 */
172
-	public function getId() {
173
-		return $this->getFileInfo()->getId();
174
-	}
175
-
176
-	/**
177
-	 * @return array
178
-	 */
179
-	public function stat() {
180
-		return $this->view->stat($this->path);
181
-	}
182
-
183
-	/**
184
-	 * @return int
185
-	 * @throws InvalidPathException
186
-	 * @throws NotFoundException
187
-	 */
188
-	public function getMTime() {
189
-		return $this->getFileInfo()->getMTime();
190
-	}
191
-
192
-	/**
193
-	 * @return int
194
-	 * @throws InvalidPathException
195
-	 * @throws NotFoundException
196
-	 */
197
-	public function getSize() {
198
-		return $this->getFileInfo()->getSize();
199
-	}
200
-
201
-	/**
202
-	 * @return string
203
-	 * @throws InvalidPathException
204
-	 * @throws NotFoundException
205
-	 */
206
-	public function getEtag() {
207
-		return $this->getFileInfo()->getEtag();
208
-	}
209
-
210
-	/**
211
-	 * @return int
212
-	 * @throws InvalidPathException
213
-	 * @throws NotFoundException
214
-	 */
215
-	public function getPermissions() {
216
-		return $this->getFileInfo()->getPermissions();
217
-	}
218
-
219
-	/**
220
-	 * @return bool
221
-	 * @throws InvalidPathException
222
-	 * @throws NotFoundException
223
-	 */
224
-	public function isReadable() {
225
-		return $this->getFileInfo()->isReadable();
226
-	}
227
-
228
-	/**
229
-	 * @return bool
230
-	 * @throws InvalidPathException
231
-	 * @throws NotFoundException
232
-	 */
233
-	public function isUpdateable() {
234
-		return $this->getFileInfo()->isUpdateable();
235
-	}
236
-
237
-	/**
238
-	 * @return bool
239
-	 * @throws InvalidPathException
240
-	 * @throws NotFoundException
241
-	 */
242
-	public function isDeletable() {
243
-		return $this->getFileInfo()->isDeletable();
244
-	}
245
-
246
-	/**
247
-	 * @return bool
248
-	 * @throws InvalidPathException
249
-	 * @throws NotFoundException
250
-	 */
251
-	public function isShareable() {
252
-		return $this->getFileInfo()->isShareable();
253
-	}
254
-
255
-	/**
256
-	 * @return bool
257
-	 * @throws InvalidPathException
258
-	 * @throws NotFoundException
259
-	 */
260
-	public function isCreatable() {
261
-		return $this->getFileInfo()->isCreatable();
262
-	}
263
-
264
-	/**
265
-	 * @return Node
266
-	 */
267
-	public function getParent() {
268
-		return $this->root->get(dirname($this->path));
269
-	}
270
-
271
-	/**
272
-	 * @return string
273
-	 */
274
-	public function getName() {
275
-		return basename($this->path);
276
-	}
277
-
278
-	/**
279
-	 * @param string $path
280
-	 * @return string
281
-	 */
282
-	protected function normalizePath($path) {
283
-		if ($path === '' or $path === '/') {
284
-			return '/';
285
-		}
286
-		//no windows style slashes
287
-		$path = str_replace('\\', '/', $path);
288
-		//add leading slash
289
-		if ($path[0] !== '/') {
290
-			$path = '/' . $path;
291
-		}
292
-		//remove duplicate slashes
293
-		while (strpos($path, '//') !== false) {
294
-			$path = str_replace('//', '/', $path);
295
-		}
296
-		//remove trailing slash
297
-		$path = rtrim($path, '/');
298
-
299
-		return $path;
300
-	}
301
-
302
-	/**
303
-	 * check if the requested path is valid
304
-	 *
305
-	 * @param string $path
306
-	 * @return bool
307
-	 */
308
-	public function isValidPath($path) {
309
-		if (!$path || $path[0] !== '/') {
310
-			$path = '/' . $path;
311
-		}
312
-		if (strstr($path, '/../') || strrchr($path, '/') === '/..') {
313
-			return false;
314
-		}
315
-		return true;
316
-	}
317
-
318
-	public function isMounted() {
319
-		return $this->getFileInfo()->isMounted();
320
-	}
321
-
322
-	public function isShared() {
323
-		return $this->getFileInfo()->isShared();
324
-	}
325
-
326
-	public function getMimeType() {
327
-		return $this->getFileInfo()->getMimetype();
328
-	}
329
-
330
-	public function getMimePart() {
331
-		return $this->getFileInfo()->getMimePart();
332
-	}
333
-
334
-	public function getType() {
335
-		return $this->getFileInfo()->getType();
336
-	}
337
-
338
-	public function isEncrypted() {
339
-		return $this->getFileInfo()->isEncrypted();
340
-	}
341
-
342
-	public function getMountPoint() {
343
-		return $this->getFileInfo()->getMountPoint();
344
-	}
345
-
346
-	public function getOwner() {
347
-		return $this->getFileInfo()->getOwner();
348
-	}
349
-
350
-	public function getChecksum() {
351
-	}
352
-
353
-	/**
354
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
355
-	 * @throws \OCP\Lock\LockedException
356
-	 */
357
-	public function lock($type) {
358
-		$this->view->lockFile($this->path, $type);
359
-	}
360
-
361
-	/**
362
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
363
-	 * @throws \OCP\Lock\LockedException
364
-	 */
365
-	public function changeLock($type) {
366
-		$this->view->changeLock($this->path, $type);
367
-	}
368
-
369
-	/**
370
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
371
-	 * @throws \OCP\Lock\LockedException
372
-	 */
373
-	public function unlock($type) {
374
-		$this->view->unlockFile($this->path, $type);
375
-	}
376
-
377
-	/**
378
-	 * @param string $targetPath
379
-	 * @throws \OCP\Files\NotPermittedException if copy not allowed or failed
380
-	 * @return \OC\Files\Node\Node
381
-	 */
382
-	public function copy($targetPath) {
383
-		$targetPath = $this->normalizePath($targetPath);
384
-		$parent = $this->root->get(dirname($targetPath));
385
-		if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
386
-			$nonExisting = $this->createNonExistingNode($targetPath);
387
-			$this->root->emit('\OC\Files', 'preCopy', [$this, $nonExisting]);
388
-			$this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
389
-			if (!$this->view->copy($this->path, $targetPath)) {
390
-				throw new NotPermittedException('Could not copy ' . $this->path . ' to ' . $targetPath);
391
-			}
392
-			$targetNode = $this->root->get($targetPath);
393
-			$this->root->emit('\OC\Files', 'postCopy', [$this, $targetNode]);
394
-			$this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
395
-			return $targetNode;
396
-		} else {
397
-			throw new NotPermittedException('No permission to copy to path ' . $targetPath);
398
-		}
399
-	}
400
-
401
-	/**
402
-	 * @param string $targetPath
403
-	 * @throws \OCP\Files\NotPermittedException if move not allowed or failed
404
-	 * @return \OC\Files\Node\Node
405
-	 */
406
-	public function move($targetPath) {
407
-		$targetPath = $this->normalizePath($targetPath);
408
-		$parent = $this->root->get(dirname($targetPath));
409
-		if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
410
-			$nonExisting = $this->createNonExistingNode($targetPath);
411
-			$this->root->emit('\OC\Files', 'preRename', [$this, $nonExisting]);
412
-			$this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
413
-			if (!$this->view->rename($this->path, $targetPath)) {
414
-				throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath);
415
-			}
416
-			$targetNode = $this->root->get($targetPath);
417
-			$this->root->emit('\OC\Files', 'postRename', [$this, $targetNode]);
418
-			$this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
419
-			$this->path = $targetPath;
420
-			return $targetNode;
421
-		} else {
422
-			throw new NotPermittedException('No permission to move to path ' . $targetPath);
423
-		}
424
-	}
38
+    /**
39
+     * @var \OC\Files\View $view
40
+     */
41
+    protected $view;
42
+
43
+    /**
44
+     * @var \OC\Files\Node\Root $root
45
+     */
46
+    protected $root;
47
+
48
+    /**
49
+     * @var string $path
50
+     */
51
+    protected $path;
52
+
53
+    /**
54
+     * @var \OCP\Files\FileInfo
55
+     */
56
+    protected $fileInfo;
57
+
58
+    /**
59
+     * @param \OC\Files\View $view
60
+     * @param \OCP\Files\IRootFolder $root
61
+     * @param string $path
62
+     * @param FileInfo $fileInfo
63
+     */
64
+    public function __construct($root, $view, $path, $fileInfo = null) {
65
+        $this->view = $view;
66
+        $this->root = $root;
67
+        $this->path = $path;
68
+        $this->fileInfo = $fileInfo;
69
+    }
70
+
71
+    /**
72
+     * Creates a Node of the same type that represents a non-existing path
73
+     *
74
+     * @param string $path path
75
+     * @return string non-existing node class
76
+     */
77
+    protected function createNonExistingNode($path) {
78
+        throw new \Exception('Must be implemented by subclasses');
79
+    }
80
+
81
+    /**
82
+     * Returns the matching file info
83
+     *
84
+     * @return FileInfo
85
+     * @throws InvalidPathException
86
+     * @throws NotFoundException
87
+     */
88
+    public function getFileInfo() {
89
+        if (!Filesystem::isValidPath($this->path)) {
90
+            throw new InvalidPathException();
91
+        }
92
+        if (!$this->fileInfo) {
93
+            $fileInfo = $this->view->getFileInfo($this->path);
94
+            if ($fileInfo instanceof FileInfo) {
95
+                $this->fileInfo = $fileInfo;
96
+            } else {
97
+                throw new NotFoundException();
98
+            }
99
+        }
100
+        return $this->fileInfo;
101
+    }
102
+
103
+    /**
104
+     * @param string[] $hooks
105
+     */
106
+    protected function sendHooks($hooks) {
107
+        foreach ($hooks as $hook) {
108
+            $this->root->emit('\OC\Files', $hook, array($this));
109
+        }
110
+    }
111
+
112
+    /**
113
+     * @param int $permissions
114
+     * @return bool
115
+     */
116
+    protected function checkPermissions($permissions) {
117
+        return ($this->getPermissions() & $permissions) === $permissions;
118
+    }
119
+
120
+    public function delete() {
121
+    }
122
+
123
+    /**
124
+     * @param int $mtime
125
+     * @throws \OCP\Files\NotPermittedException
126
+     */
127
+    public function touch($mtime = null) {
128
+        if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
129
+            $this->sendHooks(array('preTouch'));
130
+            $this->view->touch($this->path, $mtime);
131
+            $this->sendHooks(array('postTouch'));
132
+            if ($this->fileInfo) {
133
+                if (is_null($mtime)) {
134
+                    $mtime = time();
135
+                }
136
+                $this->fileInfo['mtime'] = $mtime;
137
+            }
138
+        } else {
139
+            throw new NotPermittedException();
140
+        }
141
+    }
142
+
143
+    /**
144
+     * @return \OC\Files\Storage\Storage
145
+     * @throws \OCP\Files\NotFoundException
146
+     */
147
+    public function getStorage() {
148
+        list($storage,) = $this->view->resolvePath($this->path);
149
+        return $storage;
150
+    }
151
+
152
+    /**
153
+     * @return string
154
+     */
155
+    public function getPath() {
156
+        return $this->path;
157
+    }
158
+
159
+    /**
160
+     * @return string
161
+     */
162
+    public function getInternalPath() {
163
+        list(, $internalPath) = $this->view->resolvePath($this->path);
164
+        return $internalPath;
165
+    }
166
+
167
+    /**
168
+     * @return int
169
+     * @throws InvalidPathException
170
+     * @throws NotFoundException
171
+     */
172
+    public function getId() {
173
+        return $this->getFileInfo()->getId();
174
+    }
175
+
176
+    /**
177
+     * @return array
178
+     */
179
+    public function stat() {
180
+        return $this->view->stat($this->path);
181
+    }
182
+
183
+    /**
184
+     * @return int
185
+     * @throws InvalidPathException
186
+     * @throws NotFoundException
187
+     */
188
+    public function getMTime() {
189
+        return $this->getFileInfo()->getMTime();
190
+    }
191
+
192
+    /**
193
+     * @return int
194
+     * @throws InvalidPathException
195
+     * @throws NotFoundException
196
+     */
197
+    public function getSize() {
198
+        return $this->getFileInfo()->getSize();
199
+    }
200
+
201
+    /**
202
+     * @return string
203
+     * @throws InvalidPathException
204
+     * @throws NotFoundException
205
+     */
206
+    public function getEtag() {
207
+        return $this->getFileInfo()->getEtag();
208
+    }
209
+
210
+    /**
211
+     * @return int
212
+     * @throws InvalidPathException
213
+     * @throws NotFoundException
214
+     */
215
+    public function getPermissions() {
216
+        return $this->getFileInfo()->getPermissions();
217
+    }
218
+
219
+    /**
220
+     * @return bool
221
+     * @throws InvalidPathException
222
+     * @throws NotFoundException
223
+     */
224
+    public function isReadable() {
225
+        return $this->getFileInfo()->isReadable();
226
+    }
227
+
228
+    /**
229
+     * @return bool
230
+     * @throws InvalidPathException
231
+     * @throws NotFoundException
232
+     */
233
+    public function isUpdateable() {
234
+        return $this->getFileInfo()->isUpdateable();
235
+    }
236
+
237
+    /**
238
+     * @return bool
239
+     * @throws InvalidPathException
240
+     * @throws NotFoundException
241
+     */
242
+    public function isDeletable() {
243
+        return $this->getFileInfo()->isDeletable();
244
+    }
245
+
246
+    /**
247
+     * @return bool
248
+     * @throws InvalidPathException
249
+     * @throws NotFoundException
250
+     */
251
+    public function isShareable() {
252
+        return $this->getFileInfo()->isShareable();
253
+    }
254
+
255
+    /**
256
+     * @return bool
257
+     * @throws InvalidPathException
258
+     * @throws NotFoundException
259
+     */
260
+    public function isCreatable() {
261
+        return $this->getFileInfo()->isCreatable();
262
+    }
263
+
264
+    /**
265
+     * @return Node
266
+     */
267
+    public function getParent() {
268
+        return $this->root->get(dirname($this->path));
269
+    }
270
+
271
+    /**
272
+     * @return string
273
+     */
274
+    public function getName() {
275
+        return basename($this->path);
276
+    }
277
+
278
+    /**
279
+     * @param string $path
280
+     * @return string
281
+     */
282
+    protected function normalizePath($path) {
283
+        if ($path === '' or $path === '/') {
284
+            return '/';
285
+        }
286
+        //no windows style slashes
287
+        $path = str_replace('\\', '/', $path);
288
+        //add leading slash
289
+        if ($path[0] !== '/') {
290
+            $path = '/' . $path;
291
+        }
292
+        //remove duplicate slashes
293
+        while (strpos($path, '//') !== false) {
294
+            $path = str_replace('//', '/', $path);
295
+        }
296
+        //remove trailing slash
297
+        $path = rtrim($path, '/');
298
+
299
+        return $path;
300
+    }
301
+
302
+    /**
303
+     * check if the requested path is valid
304
+     *
305
+     * @param string $path
306
+     * @return bool
307
+     */
308
+    public function isValidPath($path) {
309
+        if (!$path || $path[0] !== '/') {
310
+            $path = '/' . $path;
311
+        }
312
+        if (strstr($path, '/../') || strrchr($path, '/') === '/..') {
313
+            return false;
314
+        }
315
+        return true;
316
+    }
317
+
318
+    public function isMounted() {
319
+        return $this->getFileInfo()->isMounted();
320
+    }
321
+
322
+    public function isShared() {
323
+        return $this->getFileInfo()->isShared();
324
+    }
325
+
326
+    public function getMimeType() {
327
+        return $this->getFileInfo()->getMimetype();
328
+    }
329
+
330
+    public function getMimePart() {
331
+        return $this->getFileInfo()->getMimePart();
332
+    }
333
+
334
+    public function getType() {
335
+        return $this->getFileInfo()->getType();
336
+    }
337
+
338
+    public function isEncrypted() {
339
+        return $this->getFileInfo()->isEncrypted();
340
+    }
341
+
342
+    public function getMountPoint() {
343
+        return $this->getFileInfo()->getMountPoint();
344
+    }
345
+
346
+    public function getOwner() {
347
+        return $this->getFileInfo()->getOwner();
348
+    }
349
+
350
+    public function getChecksum() {
351
+    }
352
+
353
+    /**
354
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
355
+     * @throws \OCP\Lock\LockedException
356
+     */
357
+    public function lock($type) {
358
+        $this->view->lockFile($this->path, $type);
359
+    }
360
+
361
+    /**
362
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
363
+     * @throws \OCP\Lock\LockedException
364
+     */
365
+    public function changeLock($type) {
366
+        $this->view->changeLock($this->path, $type);
367
+    }
368
+
369
+    /**
370
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
371
+     * @throws \OCP\Lock\LockedException
372
+     */
373
+    public function unlock($type) {
374
+        $this->view->unlockFile($this->path, $type);
375
+    }
376
+
377
+    /**
378
+     * @param string $targetPath
379
+     * @throws \OCP\Files\NotPermittedException if copy not allowed or failed
380
+     * @return \OC\Files\Node\Node
381
+     */
382
+    public function copy($targetPath) {
383
+        $targetPath = $this->normalizePath($targetPath);
384
+        $parent = $this->root->get(dirname($targetPath));
385
+        if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
386
+            $nonExisting = $this->createNonExistingNode($targetPath);
387
+            $this->root->emit('\OC\Files', 'preCopy', [$this, $nonExisting]);
388
+            $this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
389
+            if (!$this->view->copy($this->path, $targetPath)) {
390
+                throw new NotPermittedException('Could not copy ' . $this->path . ' to ' . $targetPath);
391
+            }
392
+            $targetNode = $this->root->get($targetPath);
393
+            $this->root->emit('\OC\Files', 'postCopy', [$this, $targetNode]);
394
+            $this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
395
+            return $targetNode;
396
+        } else {
397
+            throw new NotPermittedException('No permission to copy to path ' . $targetPath);
398
+        }
399
+    }
400
+
401
+    /**
402
+     * @param string $targetPath
403
+     * @throws \OCP\Files\NotPermittedException if move not allowed or failed
404
+     * @return \OC\Files\Node\Node
405
+     */
406
+    public function move($targetPath) {
407
+        $targetPath = $this->normalizePath($targetPath);
408
+        $parent = $this->root->get(dirname($targetPath));
409
+        if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
410
+            $nonExisting = $this->createNonExistingNode($targetPath);
411
+            $this->root->emit('\OC\Files', 'preRename', [$this, $nonExisting]);
412
+            $this->root->emit('\OC\Files', 'preWrite', [$nonExisting]);
413
+            if (!$this->view->rename($this->path, $targetPath)) {
414
+                throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath);
415
+            }
416
+            $targetNode = $this->root->get($targetPath);
417
+            $this->root->emit('\OC\Files', 'postRename', [$this, $targetNode]);
418
+            $this->root->emit('\OC\Files', 'postWrite', [$targetNode]);
419
+            $this->path = $targetPath;
420
+            return $targetNode;
421
+        } else {
422
+            throw new NotPermittedException('No permission to move to path ' . $targetPath);
423
+        }
424
+    }
425 425
 
426 426
 }
Please login to merge, or discard this patch.
lib/private/Files/Node/NonExistingFile.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -26,119 +26,119 @@
 block discarded – undo
26 26
 use OCP\Files\NotFoundException;
27 27
 
28 28
 class NonExistingFile extends File {
29
-	/**
30
-	 * @param string $newPath
31
-	 * @throws \OCP\Files\NotFoundException
32
-	 */
33
-	public function rename($newPath) {
34
-		throw new NotFoundException();
35
-	}
36
-
37
-	public function delete() {
38
-		throw new NotFoundException();
39
-	}
40
-
41
-	public function copy($newPath) {
42
-		throw new NotFoundException();
43
-	}
44
-
45
-	public function touch($mtime = null) {
46
-		throw new NotFoundException();
47
-	}
48
-
49
-	public function getId() {
50
-		if ($this->fileInfo) {
51
-			return parent::getId();
52
-		} else {
53
-			throw new NotFoundException();
54
-		}
55
-	}
56
-
57
-	public function stat() {
58
-		throw new NotFoundException();
59
-	}
60
-
61
-	public function getMTime() {
62
-		if ($this->fileInfo) {
63
-			return parent::getMTime();
64
-		} else {
65
-			throw new NotFoundException();
66
-		}
67
-	}
68
-
69
-	public function getSize() {
70
-		if ($this->fileInfo) {
71
-			return parent::getSize();
72
-		} else {
73
-			throw new NotFoundException();
74
-		}
75
-	}
76
-
77
-	public function getEtag() {
78
-		if ($this->fileInfo) {
79
-			return parent::getEtag();
80
-		} else {
81
-			throw new NotFoundException();
82
-		}
83
-	}
84
-
85
-	public function getPermissions() {
86
-		if ($this->fileInfo) {
87
-			return parent::getPermissions();
88
-		} else {
89
-			throw new NotFoundException();
90
-		}
91
-	}
92
-
93
-	public function isReadable() {
94
-		if ($this->fileInfo) {
95
-			return parent::isReadable();
96
-		} else {
97
-			throw new NotFoundException();
98
-		}
99
-	}
100
-
101
-	public function isUpdateable() {
102
-		if ($this->fileInfo) {
103
-			return parent::isUpdateable();
104
-		} else {
105
-			throw new NotFoundException();
106
-		}
107
-	}
108
-
109
-	public function isDeletable() {
110
-		if ($this->fileInfo) {
111
-			return parent::isDeletable();
112
-		} else {
113
-			throw new NotFoundException();
114
-		}
115
-	}
116
-
117
-	public function isShareable() {
118
-		if ($this->fileInfo) {
119
-			return parent::isShareable();
120
-		} else {
121
-			throw new NotFoundException();
122
-		}
123
-	}
124
-
125
-	public function getContent() {
126
-		throw new NotFoundException();
127
-	}
128
-
129
-	public function putContent($data) {
130
-		throw new NotFoundException();
131
-	}
132
-
133
-	public function getMimeType() {
134
-		if ($this->fileInfo) {
135
-			return parent::getMimeType();
136
-		} else {
137
-			throw new NotFoundException();
138
-		}
139
-	}
140
-
141
-	public function fopen($mode) {
142
-		throw new NotFoundException();
143
-	}
29
+    /**
30
+     * @param string $newPath
31
+     * @throws \OCP\Files\NotFoundException
32
+     */
33
+    public function rename($newPath) {
34
+        throw new NotFoundException();
35
+    }
36
+
37
+    public function delete() {
38
+        throw new NotFoundException();
39
+    }
40
+
41
+    public function copy($newPath) {
42
+        throw new NotFoundException();
43
+    }
44
+
45
+    public function touch($mtime = null) {
46
+        throw new NotFoundException();
47
+    }
48
+
49
+    public function getId() {
50
+        if ($this->fileInfo) {
51
+            return parent::getId();
52
+        } else {
53
+            throw new NotFoundException();
54
+        }
55
+    }
56
+
57
+    public function stat() {
58
+        throw new NotFoundException();
59
+    }
60
+
61
+    public function getMTime() {
62
+        if ($this->fileInfo) {
63
+            return parent::getMTime();
64
+        } else {
65
+            throw new NotFoundException();
66
+        }
67
+    }
68
+
69
+    public function getSize() {
70
+        if ($this->fileInfo) {
71
+            return parent::getSize();
72
+        } else {
73
+            throw new NotFoundException();
74
+        }
75
+    }
76
+
77
+    public function getEtag() {
78
+        if ($this->fileInfo) {
79
+            return parent::getEtag();
80
+        } else {
81
+            throw new NotFoundException();
82
+        }
83
+    }
84
+
85
+    public function getPermissions() {
86
+        if ($this->fileInfo) {
87
+            return parent::getPermissions();
88
+        } else {
89
+            throw new NotFoundException();
90
+        }
91
+    }
92
+
93
+    public function isReadable() {
94
+        if ($this->fileInfo) {
95
+            return parent::isReadable();
96
+        } else {
97
+            throw new NotFoundException();
98
+        }
99
+    }
100
+
101
+    public function isUpdateable() {
102
+        if ($this->fileInfo) {
103
+            return parent::isUpdateable();
104
+        } else {
105
+            throw new NotFoundException();
106
+        }
107
+    }
108
+
109
+    public function isDeletable() {
110
+        if ($this->fileInfo) {
111
+            return parent::isDeletable();
112
+        } else {
113
+            throw new NotFoundException();
114
+        }
115
+    }
116
+
117
+    public function isShareable() {
118
+        if ($this->fileInfo) {
119
+            return parent::isShareable();
120
+        } else {
121
+            throw new NotFoundException();
122
+        }
123
+    }
124
+
125
+    public function getContent() {
126
+        throw new NotFoundException();
127
+    }
128
+
129
+    public function putContent($data) {
130
+        throw new NotFoundException();
131
+    }
132
+
133
+    public function getMimeType() {
134
+        if ($this->fileInfo) {
135
+            return parent::getMimeType();
136
+        } else {
137
+            throw new NotFoundException();
138
+        }
139
+    }
140
+
141
+    public function fopen($mode) {
142
+        throw new NotFoundException();
143
+    }
144 144
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/ObjectHomeMountProvider.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 			return null;
65 65
 		}
66 66
 
67
-		return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader);
67
+		return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/'.$user->getUID(), $config['arguments'], $loader);
68 68
 	}
69 69
 
70 70
 	/**
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @param IUser $user
53 53
 	 * @param IStorageFactory $loader
54
-	 * @return \OCP\Files\Mount\IMountPoint
54
+	 * @return null|MountPoint
55 55
 	 */
56 56
 	public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
57 57
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
 	/**
71 71
 	 * @param IUser $user
72
-	 * @return array|null
72
+	 * @return IStorageFactory|null
73 73
 	 */
74 74
 	private function getSingleBucketObjectStoreConfig(IUser $user) {
75 75
 		$config = $this->config->getSystemValue('objectstore');
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 	/**
95 95
 	 * @param IUser $user
96
-	 * @return array|null
96
+	 * @return IStorageFactory|null
97 97
 	 */
98 98
 	private function getMultiBucketObjectStoreConfig(IUser $user) {
99 99
 		$config = $this->config->getSystemValue('objectstore_multibucket');
Please login to merge, or discard this patch.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -32,107 +32,107 @@
 block discarded – undo
32 32
  * Mount provider for object store home storages
33 33
  */
34 34
 class ObjectHomeMountProvider implements IHomeMountProvider {
35
-	/**
36
-	 * @var IConfig
37
-	 */
38
-	private $config;
39
-
40
-	/**
41
-	 * ObjectStoreHomeMountProvider constructor.
42
-	 *
43
-	 * @param IConfig $config
44
-	 */
45
-	public function __construct(IConfig $config) {
46
-		$this->config = $config;
47
-	}
48
-
49
-	/**
50
-	 * Get the cache mount for a user
51
-	 *
52
-	 * @param IUser $user
53
-	 * @param IStorageFactory $loader
54
-	 * @return \OCP\Files\Mount\IMountPoint
55
-	 */
56
-	public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
57
-
58
-		$config = $this->getMultiBucketObjectStoreConfig($user);
59
-		if ($config === null) {
60
-			$config = $this->getSingleBucketObjectStoreConfig($user);
61
-		}
62
-
63
-		if ($config === null) {
64
-			return null;
65
-		}
66
-
67
-		return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader);
68
-	}
69
-
70
-	/**
71
-	 * @param IUser $user
72
-	 * @return array|null
73
-	 */
74
-	private function getSingleBucketObjectStoreConfig(IUser $user) {
75
-		$config = $this->config->getSystemValue('objectstore');
76
-		if (!is_array($config)) {
77
-			return null;
78
-		}
79
-
80
-		// sanity checks
81
-		if (empty($config['class'])) {
82
-			\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
83
-		}
84
-		if (!isset($config['arguments'])) {
85
-			$config['arguments'] = [];
86
-		}
87
-		// instantiate object store implementation
88
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
89
-
90
-		$config['arguments']['user'] = $user;
91
-
92
-		return $config;
93
-	}
94
-
95
-	/**
96
-	 * @param IUser $user
97
-	 * @return array|null
98
-	 */
99
-	private function getMultiBucketObjectStoreConfig(IUser $user) {
100
-		$config = $this->config->getSystemValue('objectstore_multibucket');
101
-		if (!is_array($config)) {
102
-			return null;
103
-		}
104
-
105
-		// sanity checks
106
-		if (empty($config['class'])) {
107
-			\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
108
-		}
109
-		if (!isset($config['arguments'])) {
110
-			$config['arguments'] = [];
111
-		}
112
-		$config['arguments']['user'] = $user;
113
-
114
-		$bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null);
115
-
116
-		if ($bucket === null) {
117
-			/*
35
+    /**
36
+     * @var IConfig
37
+     */
38
+    private $config;
39
+
40
+    /**
41
+     * ObjectStoreHomeMountProvider constructor.
42
+     *
43
+     * @param IConfig $config
44
+     */
45
+    public function __construct(IConfig $config) {
46
+        $this->config = $config;
47
+    }
48
+
49
+    /**
50
+     * Get the cache mount for a user
51
+     *
52
+     * @param IUser $user
53
+     * @param IStorageFactory $loader
54
+     * @return \OCP\Files\Mount\IMountPoint
55
+     */
56
+    public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
57
+
58
+        $config = $this->getMultiBucketObjectStoreConfig($user);
59
+        if ($config === null) {
60
+            $config = $this->getSingleBucketObjectStoreConfig($user);
61
+        }
62
+
63
+        if ($config === null) {
64
+            return null;
65
+        }
66
+
67
+        return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader);
68
+    }
69
+
70
+    /**
71
+     * @param IUser $user
72
+     * @return array|null
73
+     */
74
+    private function getSingleBucketObjectStoreConfig(IUser $user) {
75
+        $config = $this->config->getSystemValue('objectstore');
76
+        if (!is_array($config)) {
77
+            return null;
78
+        }
79
+
80
+        // sanity checks
81
+        if (empty($config['class'])) {
82
+            \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
83
+        }
84
+        if (!isset($config['arguments'])) {
85
+            $config['arguments'] = [];
86
+        }
87
+        // instantiate object store implementation
88
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
89
+
90
+        $config['arguments']['user'] = $user;
91
+
92
+        return $config;
93
+    }
94
+
95
+    /**
96
+     * @param IUser $user
97
+     * @return array|null
98
+     */
99
+    private function getMultiBucketObjectStoreConfig(IUser $user) {
100
+        $config = $this->config->getSystemValue('objectstore_multibucket');
101
+        if (!is_array($config)) {
102
+            return null;
103
+        }
104
+
105
+        // sanity checks
106
+        if (empty($config['class'])) {
107
+            \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR);
108
+        }
109
+        if (!isset($config['arguments'])) {
110
+            $config['arguments'] = [];
111
+        }
112
+        $config['arguments']['user'] = $user;
113
+
114
+        $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null);
115
+
116
+        if ($bucket === null) {
117
+            /*
118 118
 			 * Use any provided bucket argument as prefix
119 119
 			 * and add the mapping from username => bucket
120 120
 			 */
121
-			if (!isset($config['arguments']['bucket'])) {
122
-				$config['arguments']['bucket'] = '';
123
-			}
124
-			$mapper = new \OC\Files\ObjectStore\Mapper($user);
125
-			$numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64;
126
-			$config['arguments']['bucket'] .= $mapper->getBucket($numBuckets);
127
-
128
-			$this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);
129
-		} else {
130
-			$config['arguments']['bucket'] = $bucket;
131
-		}
132
-
133
-		// instantiate object store implementation
134
-		$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
135
-
136
-		return $config;
137
-	}
121
+            if (!isset($config['arguments']['bucket'])) {
122
+                $config['arguments']['bucket'] = '';
123
+            }
124
+            $mapper = new \OC\Files\ObjectStore\Mapper($user);
125
+            $numBuckets = isset($config['arguments']['num_buckets']) ? $config['arguments']['num_buckets'] : 64;
126
+            $config['arguments']['bucket'] .= $mapper->getBucket($numBuckets);
127
+
128
+            $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);
129
+        } else {
130
+            $config['arguments']['bucket'] = $bucket;
131
+        }
132
+
133
+        // instantiate object store implementation
134
+        $config['arguments']['objectstore'] = new $config['class']($config['arguments']);
135
+
136
+        return $config;
137
+    }
138 138
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/MountPoint.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		} else {
106 106
 			// Update old classes to new namespace
107 107
 			if (strpos($storage, 'OC_Filestorage_') !== false) {
108
-				$storage = '\OC\Files\Storage\\' . substr($storage, 15);
108
+				$storage = '\OC\Files\Storage\\'.substr($storage, 15);
109 109
 			}
110 110
 			$this->class = $storage;
111 111
 			$this->arguments = $arguments;
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 				return;
158 158
 			}
159 159
 		} else {
160
-			\OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR);
160
+			\OCP\Util::writeLog('core', 'storage backend '.$this->class.' not found', \OCP\Util::ERROR);
161 161
 			$this->invalidStorage = true;
162 162
 			return;
163 163
 		}
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public function getInternalPath($path) {
209 209
 		$path = Filesystem::normalizePath($path, true, false, true);
210
-		if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
210
+		if ($this->mountPoint === $path or $this->mountPoint.'/' === $path) {
211 211
 			$internalPath = '';
212 212
 		} else {
213 213
 			$internalPath = substr($path, strlen($this->mountPoint));
214 214
 		}
215 215
 		// substr returns false instead of an empty string, we always want a string
216
-		return (string)$internalPath;
216
+		return (string) $internalPath;
217 217
 	}
218 218
 
219 219
 	/**
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 */
267 267
 	public function getStorageRootId() {
268 268
 		if (is_null($this->rootId)) {
269
-			$this->rootId = (int)$this->getStorage()->getCache()->getId('');
269
+			$this->rootId = (int) $this->getStorage()->getCache()->getId('');
270 270
 		}
271 271
 		return $this->rootId;
272 272
 	}
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -35,247 +35,247 @@
 block discarded – undo
35 35
 use OCP\Files\Mount\IMountPoint;
36 36
 
37 37
 class MountPoint implements IMountPoint {
38
-	/**
39
-	 * @var \OC\Files\Storage\Storage $storage
40
-	 */
41
-	protected $storage = null;
42
-	protected $class;
43
-	protected $storageId;
44
-	protected $rootId = null;
38
+    /**
39
+     * @var \OC\Files\Storage\Storage $storage
40
+     */
41
+    protected $storage = null;
42
+    protected $class;
43
+    protected $storageId;
44
+    protected $rootId = null;
45 45
 
46
-	/**
47
-	 * Configuration options for the storage backend
48
-	 *
49
-	 * @var array
50
-	 */
51
-	protected $arguments = array();
52
-	protected $mountPoint;
46
+    /**
47
+     * Configuration options for the storage backend
48
+     *
49
+     * @var array
50
+     */
51
+    protected $arguments = array();
52
+    protected $mountPoint;
53 53
 
54
-	/**
55
-	 * Mount specific options
56
-	 *
57
-	 * @var array
58
-	 */
59
-	protected $mountOptions = array();
54
+    /**
55
+     * Mount specific options
56
+     *
57
+     * @var array
58
+     */
59
+    protected $mountOptions = array();
60 60
 
61
-	/**
62
-	 * @var \OC\Files\Storage\StorageFactory $loader
63
-	 */
64
-	private $loader;
61
+    /**
62
+     * @var \OC\Files\Storage\StorageFactory $loader
63
+     */
64
+    private $loader;
65 65
 
66
-	/**
67
-	 * Specified whether the storage is invalid after failing to
68
-	 * instantiate it.
69
-	 *
70
-	 * @var bool
71
-	 */
72
-	private $invalidStorage = false;
66
+    /**
67
+     * Specified whether the storage is invalid after failing to
68
+     * instantiate it.
69
+     *
70
+     * @var bool
71
+     */
72
+    private $invalidStorage = false;
73 73
 
74
-	/** @var int|null */
75
-	protected $mountId;
74
+    /** @var int|null */
75
+    protected $mountId;
76 76
 
77
-	/**
78
-	 * @param string|\OC\Files\Storage\Storage $storage
79
-	 * @param string $mountpoint
80
-	 * @param array $arguments (optional) configuration for the storage backend
81
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
82
-	 * @param array $mountOptions mount specific options
83
-	 * @param int|null $mountId
84
-	 * @throws \Exception
85
-	 */
86
-	public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
87
-		if (is_null($arguments)) {
88
-			$arguments = array();
89
-		}
90
-		if (is_null($loader)) {
91
-			$this->loader = new StorageFactory();
92
-		} else {
93
-			$this->loader = $loader;
94
-		}
77
+    /**
78
+     * @param string|\OC\Files\Storage\Storage $storage
79
+     * @param string $mountpoint
80
+     * @param array $arguments (optional) configuration for the storage backend
81
+     * @param \OCP\Files\Storage\IStorageFactory $loader
82
+     * @param array $mountOptions mount specific options
83
+     * @param int|null $mountId
84
+     * @throws \Exception
85
+     */
86
+    public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) {
87
+        if (is_null($arguments)) {
88
+            $arguments = array();
89
+        }
90
+        if (is_null($loader)) {
91
+            $this->loader = new StorageFactory();
92
+        } else {
93
+            $this->loader = $loader;
94
+        }
95 95
 
96
-		if (!is_null($mountOptions)) {
97
-			$this->mountOptions = $mountOptions;
98
-		}
96
+        if (!is_null($mountOptions)) {
97
+            $this->mountOptions = $mountOptions;
98
+        }
99 99
 
100
-		$mountpoint = $this->formatPath($mountpoint);
101
-		$this->mountPoint = $mountpoint;
102
-		if ($storage instanceof Storage) {
103
-			$this->class = get_class($storage);
104
-			$this->storage = $this->loader->wrap($this, $storage);
105
-		} else {
106
-			// Update old classes to new namespace
107
-			if (strpos($storage, 'OC_Filestorage_') !== false) {
108
-				$storage = '\OC\Files\Storage\\' . substr($storage, 15);
109
-			}
110
-			$this->class = $storage;
111
-			$this->arguments = $arguments;
112
-		}
113
-		$this->mountId = $mountId;
114
-	}
100
+        $mountpoint = $this->formatPath($mountpoint);
101
+        $this->mountPoint = $mountpoint;
102
+        if ($storage instanceof Storage) {
103
+            $this->class = get_class($storage);
104
+            $this->storage = $this->loader->wrap($this, $storage);
105
+        } else {
106
+            // Update old classes to new namespace
107
+            if (strpos($storage, 'OC_Filestorage_') !== false) {
108
+                $storage = '\OC\Files\Storage\\' . substr($storage, 15);
109
+            }
110
+            $this->class = $storage;
111
+            $this->arguments = $arguments;
112
+        }
113
+        $this->mountId = $mountId;
114
+    }
115 115
 
116
-	/**
117
-	 * get complete path to the mount point, relative to data/
118
-	 *
119
-	 * @return string
120
-	 */
121
-	public function getMountPoint() {
122
-		return $this->mountPoint;
123
-	}
116
+    /**
117
+     * get complete path to the mount point, relative to data/
118
+     *
119
+     * @return string
120
+     */
121
+    public function getMountPoint() {
122
+        return $this->mountPoint;
123
+    }
124 124
 
125
-	/**
126
-	 * Sets the mount point path, relative to data/
127
-	 *
128
-	 * @param string $mountPoint new mount point
129
-	 */
130
-	public function setMountPoint($mountPoint) {
131
-		$this->mountPoint = $this->formatPath($mountPoint);
132
-	}
125
+    /**
126
+     * Sets the mount point path, relative to data/
127
+     *
128
+     * @param string $mountPoint new mount point
129
+     */
130
+    public function setMountPoint($mountPoint) {
131
+        $this->mountPoint = $this->formatPath($mountPoint);
132
+    }
133 133
 
134
-	/**
135
-	 * create the storage that is mounted
136
-	 */
137
-	private function createStorage() {
138
-		if ($this->invalidStorage) {
139
-			return;
140
-		}
134
+    /**
135
+     * create the storage that is mounted
136
+     */
137
+    private function createStorage() {
138
+        if ($this->invalidStorage) {
139
+            return;
140
+        }
141 141
 
142
-		if (class_exists($this->class)) {
143
-			try {
144
-				$class = $this->class;
145
-				// prevent recursion by setting the storage before applying wrappers
146
-				$this->storage = new $class($this->arguments);
147
-				$this->storage = $this->loader->wrap($this, $this->storage);
148
-			} catch (\Exception $exception) {
149
-				$this->storage = null;
150
-				$this->invalidStorage = true;
151
-				if ($this->mountPoint === '/') {
152
-					// the root storage could not be initialized, show the user!
153
-					throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
154
-				} else {
155
-					\OC::$server->getLogger()->logException($exception, ['level' => \OCP\Util::ERROR]);
156
-				}
157
-				return;
158
-			}
159
-		} else {
160
-			\OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR);
161
-			$this->invalidStorage = true;
162
-			return;
163
-		}
164
-	}
142
+        if (class_exists($this->class)) {
143
+            try {
144
+                $class = $this->class;
145
+                // prevent recursion by setting the storage before applying wrappers
146
+                $this->storage = new $class($this->arguments);
147
+                $this->storage = $this->loader->wrap($this, $this->storage);
148
+            } catch (\Exception $exception) {
149
+                $this->storage = null;
150
+                $this->invalidStorage = true;
151
+                if ($this->mountPoint === '/') {
152
+                    // the root storage could not be initialized, show the user!
153
+                    throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
154
+                } else {
155
+                    \OC::$server->getLogger()->logException($exception, ['level' => \OCP\Util::ERROR]);
156
+                }
157
+                return;
158
+            }
159
+        } else {
160
+            \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR);
161
+            $this->invalidStorage = true;
162
+            return;
163
+        }
164
+    }
165 165
 
166
-	/**
167
-	 * @return \OC\Files\Storage\Storage
168
-	 */
169
-	public function getStorage() {
170
-		if (is_null($this->storage)) {
171
-			$this->createStorage();
172
-		}
173
-		return $this->storage;
174
-	}
166
+    /**
167
+     * @return \OC\Files\Storage\Storage
168
+     */
169
+    public function getStorage() {
170
+        if (is_null($this->storage)) {
171
+            $this->createStorage();
172
+        }
173
+        return $this->storage;
174
+    }
175 175
 
176
-	/**
177
-	 * @return string
178
-	 */
179
-	public function getStorageId() {
180
-		if (!$this->storageId) {
181
-			if (is_null($this->storage)) {
182
-				$storage = $this->createStorage(); //FIXME: start using exceptions
183
-				if (is_null($storage)) {
184
-					return null;
185
-				}
176
+    /**
177
+     * @return string
178
+     */
179
+    public function getStorageId() {
180
+        if (!$this->storageId) {
181
+            if (is_null($this->storage)) {
182
+                $storage = $this->createStorage(); //FIXME: start using exceptions
183
+                if (is_null($storage)) {
184
+                    return null;
185
+                }
186 186
 
187
-				$this->storage = $storage;
188
-			}
189
-			$this->storageId = $this->storage->getId();
190
-			if (strlen($this->storageId) > 64) {
191
-				$this->storageId = md5($this->storageId);
192
-			}
193
-		}
194
-		return $this->storageId;
195
-	}
187
+                $this->storage = $storage;
188
+            }
189
+            $this->storageId = $this->storage->getId();
190
+            if (strlen($this->storageId) > 64) {
191
+                $this->storageId = md5($this->storageId);
192
+            }
193
+        }
194
+        return $this->storageId;
195
+    }
196 196
 
197
-	/**
198
-	 * @return int
199
-	 */
200
-	public function getNumericStorageId() {
201
-		return $this->getStorage()->getStorageCache()->getNumericId();
202
-	}
197
+    /**
198
+     * @return int
199
+     */
200
+    public function getNumericStorageId() {
201
+        return $this->getStorage()->getStorageCache()->getNumericId();
202
+    }
203 203
 
204
-	/**
205
-	 * @param string $path
206
-	 * @return string
207
-	 */
208
-	public function getInternalPath($path) {
209
-		$path = Filesystem::normalizePath($path, true, false, true);
210
-		if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
211
-			$internalPath = '';
212
-		} else {
213
-			$internalPath = substr($path, strlen($this->mountPoint));
214
-		}
215
-		// substr returns false instead of an empty string, we always want a string
216
-		return (string)$internalPath;
217
-	}
204
+    /**
205
+     * @param string $path
206
+     * @return string
207
+     */
208
+    public function getInternalPath($path) {
209
+        $path = Filesystem::normalizePath($path, true, false, true);
210
+        if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
211
+            $internalPath = '';
212
+        } else {
213
+            $internalPath = substr($path, strlen($this->mountPoint));
214
+        }
215
+        // substr returns false instead of an empty string, we always want a string
216
+        return (string)$internalPath;
217
+    }
218 218
 
219
-	/**
220
-	 * @param string $path
221
-	 * @return string
222
-	 */
223
-	private function formatPath($path) {
224
-		$path = Filesystem::normalizePath($path);
225
-		if (strlen($path) > 1) {
226
-			$path .= '/';
227
-		}
228
-		return $path;
229
-	}
219
+    /**
220
+     * @param string $path
221
+     * @return string
222
+     */
223
+    private function formatPath($path) {
224
+        $path = Filesystem::normalizePath($path);
225
+        if (strlen($path) > 1) {
226
+            $path .= '/';
227
+        }
228
+        return $path;
229
+    }
230 230
 
231
-	/**
232
-	 * @param callable $wrapper
233
-	 */
234
-	public function wrapStorage($wrapper) {
235
-		$storage = $this->getStorage();
236
-		// storage can be null if it couldn't be initialized
237
-		if ($storage != null) {
238
-			$this->storage = $wrapper($this->mountPoint, $storage, $this);
239
-		}
240
-	}
231
+    /**
232
+     * @param callable $wrapper
233
+     */
234
+    public function wrapStorage($wrapper) {
235
+        $storage = $this->getStorage();
236
+        // storage can be null if it couldn't be initialized
237
+        if ($storage != null) {
238
+            $this->storage = $wrapper($this->mountPoint, $storage, $this);
239
+        }
240
+    }
241 241
 
242
-	/**
243
-	 * Get a mount option
244
-	 *
245
-	 * @param string $name Name of the mount option to get
246
-	 * @param mixed $default Default value for the mount option
247
-	 * @return mixed
248
-	 */
249
-	public function getOption($name, $default) {
250
-		return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
251
-	}
242
+    /**
243
+     * Get a mount option
244
+     *
245
+     * @param string $name Name of the mount option to get
246
+     * @param mixed $default Default value for the mount option
247
+     * @return mixed
248
+     */
249
+    public function getOption($name, $default) {
250
+        return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
251
+    }
252 252
 
253
-	/**
254
-	 * Get all options for the mount
255
-	 *
256
-	 * @return array
257
-	 */
258
-	public function getOptions() {
259
-		return $this->mountOptions;
260
-	}
253
+    /**
254
+     * Get all options for the mount
255
+     *
256
+     * @return array
257
+     */
258
+    public function getOptions() {
259
+        return $this->mountOptions;
260
+    }
261 261
 
262
-	/**
263
-	 * Get the file id of the root of the storage
264
-	 *
265
-	 * @return int
266
-	 */
267
-	public function getStorageRootId() {
268
-		if (is_null($this->rootId)) {
269
-			$this->rootId = (int)$this->getStorage()->getCache()->getId('');
270
-		}
271
-		return $this->rootId;
272
-	}
262
+    /**
263
+     * Get the file id of the root of the storage
264
+     *
265
+     * @return int
266
+     */
267
+    public function getStorageRootId() {
268
+        if (is_null($this->rootId)) {
269
+            $this->rootId = (int)$this->getStorage()->getCache()->getId('');
270
+        }
271
+        return $this->rootId;
272
+    }
273 273
 
274
-	public function getMountId() {
275
-		return $this->mountId;
276
-	}
274
+    public function getMountId() {
275
+        return $this->mountId;
276
+    }
277 277
 
278
-	public function getMountType() {
279
-		return '';
280
-	}
278
+    public function getMountType() {
279
+        return '';
280
+    }
281 281
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/LocalHomeMountProvider.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@
 block discarded – undo
30 30
  * Mount provider for regular posix home folders
31 31
  */
32 32
 class LocalHomeMountProvider implements IHomeMountProvider {
33
-	/**
34
-	 * Get the cache mount for a user
35
-	 *
36
-	 * @param IUser $user
37
-	 * @param IStorageFactory $loader
38
-	 * @return \OCP\Files\Mount\IMountPoint[]
39
-	 */
40
-	public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
41
-		$arguments = ['user' => $user];
42
-		return new MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader);
43
-	}
33
+    /**
34
+     * Get the cache mount for a user
35
+     *
36
+     * @param IUser $user
37
+     * @param IStorageFactory $loader
38
+     * @return \OCP\Files\Mount\IMountPoint[]
39
+     */
40
+    public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
41
+        $arguments = ['user' => $user];
42
+        return new MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader);
43
+    }
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,6 +39,6 @@
 block discarded – undo
39 39
 	 */
40 40
 	public function getHomeMountForUser(IUser $user, IStorageFactory $loader) {
41 41
 		$arguments = ['user' => $user];
42
-		return new MountPoint('\OC\Files\Storage\Home', '/' . $user->getUID(), $arguments, $loader);
42
+		return new MountPoint('\OC\Files\Storage\Home', '/'.$user->getUID(), $arguments, $loader);
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/MoveableMount.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@
 block discarded – undo
27 27
  * Defines the mount point to be (re)moved by the user
28 28
  */
29 29
 interface MoveableMount {
30
-	/**
31
-	 * Move the mount point to $target
32
-	 *
33
-	 * @param string $target the target mount point
34
-	 * @return bool
35
-	 */
36
-	public function moveMount($target);
30
+    /**
31
+     * Move the mount point to $target
32
+     *
33
+     * @param string $target the target mount point
34
+     * @return bool
35
+     */
36
+    public function moveMount($target);
37 37
 
38
-	/**
39
-	 * Remove the mount points
40
-	 *
41
-	 * @return mixed
42
-	 * @return bool
43
-	 */
44
-	public function removeMount();
38
+    /**
39
+     * Remove the mount points
40
+     *
41
+     * @return mixed
42
+     * @return bool
43
+     */
44
+    public function removeMount();
45 45
 }
Please login to merge, or discard this patch.
lib/private/Files/AppData/Factory.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,24 +27,24 @@
 block discarded – undo
27 27
 
28 28
 class Factory {
29 29
 
30
-	/** @var IRootFolder */
31
-	private $rootFolder;
30
+    /** @var IRootFolder */
31
+    private $rootFolder;
32 32
 
33
-	/** @var SystemConfig */
34
-	private $config;
33
+    /** @var SystemConfig */
34
+    private $config;
35 35
 
36
-	public function __construct(IRootFolder $rootFolder,
37
-								SystemConfig $systemConfig) {
36
+    public function __construct(IRootFolder $rootFolder,
37
+                                SystemConfig $systemConfig) {
38 38
 
39
-		$this->rootFolder = $rootFolder;
40
-		$this->config = $systemConfig;
41
-	}
39
+        $this->rootFolder = $rootFolder;
40
+        $this->config = $systemConfig;
41
+    }
42 42
 
43
-	/**
44
-	 * @param string $appId
45
-	 * @return AppData
46
-	 */
47
-	public function get($appId) {
48
-		return new AppData($this->rootFolder, $this->config, $appId);
49
-	}
43
+    /**
44
+     * @param string $appId
45
+     * @return AppData
46
+     */
47
+    public function get($appId) {
48
+        return new AppData($this->rootFolder, $this->config, $appId);
49
+    }
50 50
 }
Please login to merge, or discard this patch.
lib/private/Files/AppData/AppData.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -34,98 +34,98 @@
 block discarded – undo
34 34
 
35 35
 class AppData implements IAppData {
36 36
 
37
-	/** @var IRootFolder */
38
-	private $rootFolder;
39
-
40
-	/** @var SystemConfig */
41
-	private $config;
42
-
43
-	/** @var string */
44
-	private $appId;
45
-
46
-	/** @var Folder */
47
-	private $folder;
48
-
49
-	/**
50
-	 * AppData constructor.
51
-	 *
52
-	 * @param IRootFolder $rootFolder
53
-	 * @param SystemConfig $systemConfig
54
-	 * @param string $appId
55
-	 */
56
-	public function __construct(IRootFolder $rootFolder,
57
-								SystemConfig $systemConfig,
58
-								$appId) {
59
-
60
-		$this->rootFolder = $rootFolder;
61
-		$this->config = $systemConfig;
62
-		$this->appId = $appId;
63
-	}
64
-
65
-	/**
66
-	 * @return Folder
67
-	 * @throws \RuntimeException
68
-	 */
69
-	private function getAppDataFolder() {
70
-		if ($this->folder === null) {
71
-			$instanceId = $this->config->getValue('instanceid', null);
72
-			if ($instanceId === null) {
73
-				throw new \RuntimeException('no instance id!');
74
-			}
75
-
76
-			$name = 'appdata_' . $instanceId;
77
-
78
-			try {
79
-				$appDataFolder = $this->rootFolder->get($name);
80
-			} catch (NotFoundException $e) {
81
-				try {
82
-					$appDataFolder = $this->rootFolder->newFolder($name);
83
-				} catch (NotPermittedException $e) {
84
-					throw new \RuntimeException('Could not get appdata folder');
85
-				}
86
-			}
87
-
88
-			try {
89
-				$appDataFolder = $appDataFolder->get($this->appId);
90
-			} catch (NotFoundException $e) {
91
-				try {
92
-					$appDataFolder = $appDataFolder->newFolder($this->appId);
93
-				} catch (NotPermittedException $e) {
94
-					throw new \RuntimeException('Could not get appdata folder for ' . $this->appId);
95
-				}
96
-			}
97
-
98
-			$this->folder = $appDataFolder;
99
-		}
100
-
101
-		return $this->folder;
102
-	}
103
-
104
-	public function getFolder($name) {
105
-		$node = $this->getAppDataFolder()->get($name);
106
-
107
-		/** @var Folder $node */
108
-		return new SimpleFolder($node);
109
-	}
110
-
111
-	public function newFolder($name) {
112
-		$folder = $this->getAppDataFolder()->newFolder($name);
113
-
114
-		return new SimpleFolder($folder);
115
-	}
116
-
117
-	public function getDirectoryListing() {
118
-		$listing = $this->getAppDataFolder()->getDirectoryListing();
119
-
120
-		$fileListing = array_map(function(Node $folder) {
121
-			if ($folder instanceof Folder) {
122
-				return new SimpleFolder($folder);
123
-			}
124
-			return null;
125
-		}, $listing);
126
-
127
-		$fileListing = array_filter($fileListing);
128
-
129
-		return array_values($fileListing);
130
-	}
37
+    /** @var IRootFolder */
38
+    private $rootFolder;
39
+
40
+    /** @var SystemConfig */
41
+    private $config;
42
+
43
+    /** @var string */
44
+    private $appId;
45
+
46
+    /** @var Folder */
47
+    private $folder;
48
+
49
+    /**
50
+     * AppData constructor.
51
+     *
52
+     * @param IRootFolder $rootFolder
53
+     * @param SystemConfig $systemConfig
54
+     * @param string $appId
55
+     */
56
+    public function __construct(IRootFolder $rootFolder,
57
+                                SystemConfig $systemConfig,
58
+                                $appId) {
59
+
60
+        $this->rootFolder = $rootFolder;
61
+        $this->config = $systemConfig;
62
+        $this->appId = $appId;
63
+    }
64
+
65
+    /**
66
+     * @return Folder
67
+     * @throws \RuntimeException
68
+     */
69
+    private function getAppDataFolder() {
70
+        if ($this->folder === null) {
71
+            $instanceId = $this->config->getValue('instanceid', null);
72
+            if ($instanceId === null) {
73
+                throw new \RuntimeException('no instance id!');
74
+            }
75
+
76
+            $name = 'appdata_' . $instanceId;
77
+
78
+            try {
79
+                $appDataFolder = $this->rootFolder->get($name);
80
+            } catch (NotFoundException $e) {
81
+                try {
82
+                    $appDataFolder = $this->rootFolder->newFolder($name);
83
+                } catch (NotPermittedException $e) {
84
+                    throw new \RuntimeException('Could not get appdata folder');
85
+                }
86
+            }
87
+
88
+            try {
89
+                $appDataFolder = $appDataFolder->get($this->appId);
90
+            } catch (NotFoundException $e) {
91
+                try {
92
+                    $appDataFolder = $appDataFolder->newFolder($this->appId);
93
+                } catch (NotPermittedException $e) {
94
+                    throw new \RuntimeException('Could not get appdata folder for ' . $this->appId);
95
+                }
96
+            }
97
+
98
+            $this->folder = $appDataFolder;
99
+        }
100
+
101
+        return $this->folder;
102
+    }
103
+
104
+    public function getFolder($name) {
105
+        $node = $this->getAppDataFolder()->get($name);
106
+
107
+        /** @var Folder $node */
108
+        return new SimpleFolder($node);
109
+    }
110
+
111
+    public function newFolder($name) {
112
+        $folder = $this->getAppDataFolder()->newFolder($name);
113
+
114
+        return new SimpleFolder($folder);
115
+    }
116
+
117
+    public function getDirectoryListing() {
118
+        $listing = $this->getAppDataFolder()->getDirectoryListing();
119
+
120
+        $fileListing = array_map(function(Node $folder) {
121
+            if ($folder instanceof Folder) {
122
+                return new SimpleFolder($folder);
123
+            }
124
+            return null;
125
+        }, $listing);
126
+
127
+        $fileListing = array_filter($fileListing);
128
+
129
+        return array_values($fileListing);
130
+    }
131 131
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 				throw new \RuntimeException('no instance id!');
74 74
 			}
75 75
 
76
-			$name = 'appdata_' . $instanceId;
76
+			$name = 'appdata_'.$instanceId;
77 77
 
78 78
 			try {
79 79
 				$appDataFolder = $this->rootFolder->get($name);
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 				try {
92 92
 					$appDataFolder = $appDataFolder->newFolder($this->appId);
93 93
 				} catch (NotPermittedException $e) {
94
-					throw new \RuntimeException('Could not get appdata folder for ' . $this->appId);
94
+					throw new \RuntimeException('Could not get appdata folder for '.$this->appId);
95 95
 				}
96 96
 			}
97 97
 
Please login to merge, or discard this patch.
lib/private/Files/Stream/Quota.php 3 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -33,71 +33,71 @@
 block discarded – undo
33 33
  * usage: resource \OC\Files\Stream\Quota::wrap($stream, $limit)
34 34
  */
35 35
 class Quota extends Wrapper {
36
-	/**
37
-	 * @var int $limit
38
-	 */
39
-	private $limit;
36
+    /**
37
+     * @var int $limit
38
+     */
39
+    private $limit;
40 40
 
41
-	/**
42
-	 * @param resource $stream
43
-	 * @param int $limit
44
-	 * @return resource
45
-	 */
46
-	static public function wrap($stream, $limit) {
47
-		$context = stream_context_create(array(
48
-			'quota' => array(
49
-				'source' => $stream,
50
-				'limit' => $limit
51
-			)
52
-		));
53
-		return Wrapper::wrapSource($stream, $context, 'quota', self::class);
54
-	}
41
+    /**
42
+     * @param resource $stream
43
+     * @param int $limit
44
+     * @return resource
45
+     */
46
+    static public function wrap($stream, $limit) {
47
+        $context = stream_context_create(array(
48
+            'quota' => array(
49
+                'source' => $stream,
50
+                'limit' => $limit
51
+            )
52
+        ));
53
+        return Wrapper::wrapSource($stream, $context, 'quota', self::class);
54
+    }
55 55
 
56
-	public function stream_open($path, $mode, $options, &$opened_path) {
57
-		$context = $this->loadContext('quota');
58
-		$this->source = $context['source'];
59
-		$this->limit = $context['limit'];
56
+    public function stream_open($path, $mode, $options, &$opened_path) {
57
+        $context = $this->loadContext('quota');
58
+        $this->source = $context['source'];
59
+        $this->limit = $context['limit'];
60 60
 
61
-		return true;
62
-	}
61
+        return true;
62
+    }
63 63
 
64
-	public function dir_opendir($path, $options) {
65
-		return false;
66
-	}
64
+    public function dir_opendir($path, $options) {
65
+        return false;
66
+    }
67 67
 
68
-	public function stream_seek($offset, $whence = SEEK_SET) {
69
-		if ($whence === SEEK_END){
70
-			// go to the end to find out last position's offset
71
-			$oldOffset = $this->stream_tell();
72
-			if (fseek($this->source, 0, $whence) !== 0){
73
-				return false;
74
-			}
75
-			$whence = SEEK_SET;
76
-			$offset = $this->stream_tell() + $offset;
77
-			$this->limit += $oldOffset - $offset;
78
-		}
79
-		else if ($whence === SEEK_SET) {
80
-			$this->limit += $this->stream_tell() - $offset;
81
-		} else {
82
-			$this->limit -= $offset;
83
-		}
84
-		// this wrapper needs to return "true" for success.
85
-		// the fseek call itself returns 0 on succeess
86
-		return fseek($this->source, $offset, $whence) === 0;
87
-	}
68
+    public function stream_seek($offset, $whence = SEEK_SET) {
69
+        if ($whence === SEEK_END){
70
+            // go to the end to find out last position's offset
71
+            $oldOffset = $this->stream_tell();
72
+            if (fseek($this->source, 0, $whence) !== 0){
73
+                return false;
74
+            }
75
+            $whence = SEEK_SET;
76
+            $offset = $this->stream_tell() + $offset;
77
+            $this->limit += $oldOffset - $offset;
78
+        }
79
+        else if ($whence === SEEK_SET) {
80
+            $this->limit += $this->stream_tell() - $offset;
81
+        } else {
82
+            $this->limit -= $offset;
83
+        }
84
+        // this wrapper needs to return "true" for success.
85
+        // the fseek call itself returns 0 on succeess
86
+        return fseek($this->source, $offset, $whence) === 0;
87
+    }
88 88
 
89
-	public function stream_read($count) {
90
-		$this->limit -= $count;
91
-		return fread($this->source, $count);
92
-	}
89
+    public function stream_read($count) {
90
+        $this->limit -= $count;
91
+        return fread($this->source, $count);
92
+    }
93 93
 
94
-	public function stream_write($data) {
95
-		$size = strlen($data);
96
-		if ($size > $this->limit) {
97
-			$data = substr($data, 0, $this->limit);
98
-			$size = $this->limit;
99
-		}
100
-		$this->limit -= $size;
101
-		return fwrite($this->source, $data);
102
-	}
94
+    public function stream_write($data) {
95
+        $size = strlen($data);
96
+        if ($size > $this->limit) {
97
+            $data = substr($data, 0, $this->limit);
98
+            $size = $this->limit;
99
+        }
100
+        $this->limit -= $size;
101
+        return fwrite($this->source, $data);
102
+    }
103 103
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,10 +66,10 @@
 block discarded – undo
66 66
 	}
67 67
 
68 68
 	public function stream_seek($offset, $whence = SEEK_SET) {
69
-		if ($whence === SEEK_END){
69
+		if ($whence === SEEK_END) {
70 70
 			// go to the end to find out last position's offset
71 71
 			$oldOffset = $this->stream_tell();
72
-			if (fseek($this->source, 0, $whence) !== 0){
72
+			if (fseek($this->source, 0, $whence) !== 0) {
73 73
 				return false;
74 74
 			}
75 75
 			$whence = SEEK_SET;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,8 +75,7 @@
 block discarded – undo
75 75
 			$whence = SEEK_SET;
76 76
 			$offset = $this->stream_tell() + $offset;
77 77
 			$this->limit += $oldOffset - $offset;
78
-		}
79
-		else if ($whence === SEEK_SET) {
78
+		} else if ($whence === SEEK_SET) {
80 79
 			$this->limit += $this->stream_tell() - $offset;
81 80
 		} else {
82 81
 			$this->limit -= $offset;
Please login to merge, or discard this patch.