Completed
Pull Request — master (#3676)
by Individual IT
12:49
created
apps/dav/lib/Connector/Sabre/LockPlugin.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -34,53 +34,53 @@
 block discarded – undo
34 34
 use Sabre\HTTP\RequestInterface;
35 35
 
36 36
 class LockPlugin extends ServerPlugin {
37
-	/**
38
-	 * Reference to main server object
39
-	 *
40
-	 * @var \Sabre\DAV\Server
41
-	 */
42
-	private $server;
37
+    /**
38
+     * Reference to main server object
39
+     *
40
+     * @var \Sabre\DAV\Server
41
+     */
42
+    private $server;
43 43
 
44
-	/**
45
-	 * {@inheritdoc}
46
-	 */
47
-	public function initialize(\Sabre\DAV\Server $server) {
48
-		$this->server = $server;
49
-		$this->server->on('beforeMethod', [$this, 'getLock'], 50);
50
-		$this->server->on('afterMethod', [$this, 'releaseLock'], 50);
51
-	}
44
+    /**
45
+     * {@inheritdoc}
46
+     */
47
+    public function initialize(\Sabre\DAV\Server $server) {
48
+        $this->server = $server;
49
+        $this->server->on('beforeMethod', [$this, 'getLock'], 50);
50
+        $this->server->on('afterMethod', [$this, 'releaseLock'], 50);
51
+    }
52 52
 
53
-	public function getLock(RequestInterface $request) {
54
-		// we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree
55
-		// so instead we limit ourselves to the PUT method manually
56
-		if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
57
-			return;
58
-		}
59
-		try {
60
-			$node = $this->server->tree->getNodeForPath($request->getPath());
61
-		} catch (NotFound $e) {
62
-			return;
63
-		}
64
-		if ($node instanceof Node) {
65
-			try {
66
-				$node->acquireLock(ILockingProvider::LOCK_SHARED);
67
-			} catch (LockedException $e) {
68
-				throw new FileLocked($e->getMessage(), $e->getCode(), $e);
69
-			}
70
-		}
71
-	}
53
+    public function getLock(RequestInterface $request) {
54
+        // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree
55
+        // so instead we limit ourselves to the PUT method manually
56
+        if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
57
+            return;
58
+        }
59
+        try {
60
+            $node = $this->server->tree->getNodeForPath($request->getPath());
61
+        } catch (NotFound $e) {
62
+            return;
63
+        }
64
+        if ($node instanceof Node) {
65
+            try {
66
+                $node->acquireLock(ILockingProvider::LOCK_SHARED);
67
+            } catch (LockedException $e) {
68
+                throw new FileLocked($e->getMessage(), $e->getCode(), $e);
69
+            }
70
+        }
71
+    }
72 72
 
73
-	public function releaseLock(RequestInterface $request) {
74
-		if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
75
-			return;
76
-		}
77
-		try {
78
-			$node = $this->server->tree->getNodeForPath($request->getPath());
79
-		} catch (NotFound $e) {
80
-			return;
81
-		}
82
-		if ($node instanceof Node) {
83
-			$node->releaseLock(ILockingProvider::LOCK_SHARED);
84
-		}
85
-	}
73
+    public function releaseLock(RequestInterface $request) {
74
+        if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
75
+            return;
76
+        }
77
+        try {
78
+            $node = $this->server->tree->getNodeForPath($request->getPath());
79
+        } catch (NotFound $e) {
80
+            return;
81
+        }
82
+        if ($node instanceof Node) {
83
+            $node->releaseLock(ILockingProvider::LOCK_SHARED);
84
+        }
85
+    }
86 86
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/File.php 1 patch
Indentation   +507 added lines, -507 removed lines patch added patch discarded remove patch
@@ -57,512 +57,512 @@
 block discarded – undo
57 57
 
58 58
 class File extends Node implements IFile {
59 59
 
60
-	/**
61
-	 * Updates the data
62
-	 *
63
-	 * The data argument is a readable stream resource.
64
-	 *
65
-	 * After a successful put operation, you may choose to return an ETag. The
66
-	 * etag must always be surrounded by double-quotes. These quotes must
67
-	 * appear in the actual string you're returning.
68
-	 *
69
-	 * Clients may use the ETag from a PUT request to later on make sure that
70
-	 * when they update the file, the contents haven't changed in the mean
71
-	 * time.
72
-	 *
73
-	 * If you don't plan to store the file byte-by-byte, and you return a
74
-	 * different object on a subsequent GET you are strongly recommended to not
75
-	 * return an ETag, and just return null.
76
-	 *
77
-	 * @param resource $data
78
-	 *
79
-	 * @throws Forbidden
80
-	 * @throws UnsupportedMediaType
81
-	 * @throws BadRequest
82
-	 * @throws Exception
83
-	 * @throws EntityTooLarge
84
-	 * @throws ServiceUnavailable
85
-	 * @throws FileLocked
86
-	 * @return string|null
87
-	 */
88
-	public function put($data) {
89
-		try {
90
-			$exists = $this->fileView->file_exists($this->path);
91
-			if ($this->info && $exists && !$this->info->isUpdateable()) {
92
-				throw new Forbidden();
93
-			}
94
-		} catch (StorageNotAvailableException $e) {
95
-			throw new ServiceUnavailable("File is not updatable: " . $e->getMessage());
96
-		}
97
-
98
-		// verify path of the target
99
-		$this->verifyPath();
100
-
101
-		// chunked handling
102
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
103
-			try {
104
-				return $this->createFileChunked($data);
105
-			} catch (\Exception $e) {
106
-				$this->convertToSabreException($e);
107
-			}
108
-		}
109
-
110
-		list($partStorage) = $this->fileView->resolvePath($this->path);
111
-		$needsPartFile = $this->needsPartFile($partStorage) && (strlen($this->path) > 1);
112
-
113
-		if ($needsPartFile) {
114
-			// mark file as partial while uploading (ignored by the scanner)
115
-			$partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part';
116
-		} else {
117
-			// upload file directly as the final path
118
-			$partFilePath = $this->path;
119
-		}
120
-
121
-		// the part file and target file might be on a different storage in case of a single file storage (e.g. single file share)
122
-		/** @var \OC\Files\Storage\Storage $partStorage */
123
-		list($partStorage, $internalPartPath) = $this->fileView->resolvePath($partFilePath);
124
-		/** @var \OC\Files\Storage\Storage $storage */
125
-		list($storage, $internalPath) = $this->fileView->resolvePath($this->path);
126
-		try {
127
-			$target = $partStorage->fopen($internalPartPath, 'wb');
128
-			if ($target === false) {
129
-				\OCP\Util::writeLog('webdav', '\OC\Files\Filesystem::fopen() failed', \OCP\Util::ERROR);
130
-				// because we have no clue about the cause we can only throw back a 500/Internal Server Error
131
-				throw new Exception('Could not write file contents');
132
-			}
133
-			list($count, $result) = \OC_Helper::streamCopy($data, $target);
134
-			fclose($target);
135
-
136
-			if ($result === false) {
137
-				$expected = -1;
138
-				if (isset($_SERVER['CONTENT_LENGTH'])) {
139
-					$expected = $_SERVER['CONTENT_LENGTH'];
140
-				}
141
-				throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: ' . $expected . ' )');
142
-			}
143
-
144
-			// if content length is sent by client:
145
-			// double check if the file was fully received
146
-			// compare expected and actual size
147
-			if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
148
-				$expected = $_SERVER['CONTENT_LENGTH'];
149
-				if ($count != $expected) {
150
-					throw new BadRequest('expected filesize ' . $expected . ' got ' . $count);
151
-				}
152
-			}
153
-
154
-		} catch (\Exception $e) {
155
-			if ($needsPartFile) {
156
-				$partStorage->unlink($internalPartPath);
157
-			}
158
-			$this->convertToSabreException($e);
159
-		}
160
-
161
-		try {
162
-			$view = \OC\Files\Filesystem::getView();
163
-			if ($view) {
164
-				$run = $this->emitPreHooks($exists);
165
-			} else {
166
-				$run = true;
167
-			}
168
-
169
-			try {
170
-				$this->changeLock(ILockingProvider::LOCK_EXCLUSIVE);
171
-			} catch (LockedException $e) {
172
-				if ($needsPartFile) {
173
-					$partStorage->unlink($internalPartPath);
174
-				}
175
-				throw new FileLocked($e->getMessage(), $e->getCode(), $e);
176
-			}
177
-
178
-			if ($needsPartFile) {
179
-				// rename to correct path
180
-				try {
181
-					if ($run) {
182
-						$renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath);
183
-						$fileExists = $storage->file_exists($internalPath);
184
-					}
185
-					if (!$run || $renameOkay === false || $fileExists === false) {
186
-						\OCP\Util::writeLog('webdav', 'renaming part file to final file failed', \OCP\Util::ERROR);
187
-						throw new Exception('Could not rename part file to final file');
188
-					}
189
-				} catch (ForbiddenException $ex) {
190
-					throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
191
-				} catch (\Exception $e) {
192
-					$partStorage->unlink($internalPartPath);
193
-					$this->convertToSabreException($e);
194
-				}
195
-			}
196
-
197
-			// since we skipped the view we need to scan and emit the hooks ourselves
198
-			$storage->getUpdater()->update($internalPath);
199
-
200
-			try {
201
-				$this->changeLock(ILockingProvider::LOCK_SHARED);
202
-			} catch (LockedException $e) {
203
-				throw new FileLocked($e->getMessage(), $e->getCode(), $e);
204
-			}
205
-
206
-			// allow sync clients to send the mtime along in a header
207
-			$request = \OC::$server->getRequest();
208
-			if (isset($request->server['HTTP_X_OC_MTIME'])) {
209
-				if ($this->fileView->touch($this->path, $request->server['HTTP_X_OC_MTIME'])) {
210
-					header('X-OC-MTime: accepted');
211
-				}
212
-			}
60
+    /**
61
+     * Updates the data
62
+     *
63
+     * The data argument is a readable stream resource.
64
+     *
65
+     * After a successful put operation, you may choose to return an ETag. The
66
+     * etag must always be surrounded by double-quotes. These quotes must
67
+     * appear in the actual string you're returning.
68
+     *
69
+     * Clients may use the ETag from a PUT request to later on make sure that
70
+     * when they update the file, the contents haven't changed in the mean
71
+     * time.
72
+     *
73
+     * If you don't plan to store the file byte-by-byte, and you return a
74
+     * different object on a subsequent GET you are strongly recommended to not
75
+     * return an ETag, and just return null.
76
+     *
77
+     * @param resource $data
78
+     *
79
+     * @throws Forbidden
80
+     * @throws UnsupportedMediaType
81
+     * @throws BadRequest
82
+     * @throws Exception
83
+     * @throws EntityTooLarge
84
+     * @throws ServiceUnavailable
85
+     * @throws FileLocked
86
+     * @return string|null
87
+     */
88
+    public function put($data) {
89
+        try {
90
+            $exists = $this->fileView->file_exists($this->path);
91
+            if ($this->info && $exists && !$this->info->isUpdateable()) {
92
+                throw new Forbidden();
93
+            }
94
+        } catch (StorageNotAvailableException $e) {
95
+            throw new ServiceUnavailable("File is not updatable: " . $e->getMessage());
96
+        }
97
+
98
+        // verify path of the target
99
+        $this->verifyPath();
100
+
101
+        // chunked handling
102
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
103
+            try {
104
+                return $this->createFileChunked($data);
105
+            } catch (\Exception $e) {
106
+                $this->convertToSabreException($e);
107
+            }
108
+        }
109
+
110
+        list($partStorage) = $this->fileView->resolvePath($this->path);
111
+        $needsPartFile = $this->needsPartFile($partStorage) && (strlen($this->path) > 1);
112
+
113
+        if ($needsPartFile) {
114
+            // mark file as partial while uploading (ignored by the scanner)
115
+            $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part';
116
+        } else {
117
+            // upload file directly as the final path
118
+            $partFilePath = $this->path;
119
+        }
120
+
121
+        // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share)
122
+        /** @var \OC\Files\Storage\Storage $partStorage */
123
+        list($partStorage, $internalPartPath) = $this->fileView->resolvePath($partFilePath);
124
+        /** @var \OC\Files\Storage\Storage $storage */
125
+        list($storage, $internalPath) = $this->fileView->resolvePath($this->path);
126
+        try {
127
+            $target = $partStorage->fopen($internalPartPath, 'wb');
128
+            if ($target === false) {
129
+                \OCP\Util::writeLog('webdav', '\OC\Files\Filesystem::fopen() failed', \OCP\Util::ERROR);
130
+                // because we have no clue about the cause we can only throw back a 500/Internal Server Error
131
+                throw new Exception('Could not write file contents');
132
+            }
133
+            list($count, $result) = \OC_Helper::streamCopy($data, $target);
134
+            fclose($target);
135
+
136
+            if ($result === false) {
137
+                $expected = -1;
138
+                if (isset($_SERVER['CONTENT_LENGTH'])) {
139
+                    $expected = $_SERVER['CONTENT_LENGTH'];
140
+                }
141
+                throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: ' . $expected . ' )');
142
+            }
143
+
144
+            // if content length is sent by client:
145
+            // double check if the file was fully received
146
+            // compare expected and actual size
147
+            if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
148
+                $expected = $_SERVER['CONTENT_LENGTH'];
149
+                if ($count != $expected) {
150
+                    throw new BadRequest('expected filesize ' . $expected . ' got ' . $count);
151
+                }
152
+            }
153
+
154
+        } catch (\Exception $e) {
155
+            if ($needsPartFile) {
156
+                $partStorage->unlink($internalPartPath);
157
+            }
158
+            $this->convertToSabreException($e);
159
+        }
160
+
161
+        try {
162
+            $view = \OC\Files\Filesystem::getView();
163
+            if ($view) {
164
+                $run = $this->emitPreHooks($exists);
165
+            } else {
166
+                $run = true;
167
+            }
168
+
169
+            try {
170
+                $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE);
171
+            } catch (LockedException $e) {
172
+                if ($needsPartFile) {
173
+                    $partStorage->unlink($internalPartPath);
174
+                }
175
+                throw new FileLocked($e->getMessage(), $e->getCode(), $e);
176
+            }
177
+
178
+            if ($needsPartFile) {
179
+                // rename to correct path
180
+                try {
181
+                    if ($run) {
182
+                        $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath);
183
+                        $fileExists = $storage->file_exists($internalPath);
184
+                    }
185
+                    if (!$run || $renameOkay === false || $fileExists === false) {
186
+                        \OCP\Util::writeLog('webdav', 'renaming part file to final file failed', \OCP\Util::ERROR);
187
+                        throw new Exception('Could not rename part file to final file');
188
+                    }
189
+                } catch (ForbiddenException $ex) {
190
+                    throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
191
+                } catch (\Exception $e) {
192
+                    $partStorage->unlink($internalPartPath);
193
+                    $this->convertToSabreException($e);
194
+                }
195
+            }
196
+
197
+            // since we skipped the view we need to scan and emit the hooks ourselves
198
+            $storage->getUpdater()->update($internalPath);
199
+
200
+            try {
201
+                $this->changeLock(ILockingProvider::LOCK_SHARED);
202
+            } catch (LockedException $e) {
203
+                throw new FileLocked($e->getMessage(), $e->getCode(), $e);
204
+            }
205
+
206
+            // allow sync clients to send the mtime along in a header
207
+            $request = \OC::$server->getRequest();
208
+            if (isset($request->server['HTTP_X_OC_MTIME'])) {
209
+                if ($this->fileView->touch($this->path, $request->server['HTTP_X_OC_MTIME'])) {
210
+                    header('X-OC-MTime: accepted');
211
+                }
212
+            }
213 213
 					
214
-			if ($view) {
215
-				$this->emitPostHooks($exists);
216
-			}
217
-
218
-			$this->refreshInfo();
219
-
220
-			if (isset($request->server['HTTP_OC_CHECKSUM'])) {
221
-				$checksum = trim($request->server['HTTP_OC_CHECKSUM']);
222
-				$this->fileView->putFileInfo($this->path, ['checksum' => $checksum]);
223
-				$this->refreshInfo();
224
-			} else if ($this->getChecksum() !== null && $this->getChecksum() !== '') {
225
-				$this->fileView->putFileInfo($this->path, ['checksum' => '']);
226
-				$this->refreshInfo();
227
-			}
228
-
229
-		} catch (StorageNotAvailableException $e) {
230
-			throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage());
231
-		}
232
-
233
-		return '"' . $this->info->getEtag() . '"';
234
-	}
235
-
236
-	private function getPartFileBasePath($path) {
237
-		$partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true);
238
-		if ($partFileInStorage) {
239
-			return $path;
240
-		} else {
241
-			return md5($path); // will place it in the root of the view with a unique name
242
-		}
243
-	}
244
-
245
-	/**
246
-	 * @param string $path
247
-	 */
248
-	private function emitPreHooks($exists, $path = null) {
249
-		if (is_null($path)) {
250
-			$path = $this->path;
251
-		}
252
-		$hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
253
-		$run = true;
254
-
255
-		if (!$exists) {
256
-			\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, array(
257
-				\OC\Files\Filesystem::signal_param_path => $hookPath,
258
-				\OC\Files\Filesystem::signal_param_run => &$run,
259
-			));
260
-		} else {
261
-			\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, array(
262
-				\OC\Files\Filesystem::signal_param_path => $hookPath,
263
-				\OC\Files\Filesystem::signal_param_run => &$run,
264
-			));
265
-		}
266
-		\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, array(
267
-			\OC\Files\Filesystem::signal_param_path => $hookPath,
268
-			\OC\Files\Filesystem::signal_param_run => &$run,
269
-		));
270
-		return $run;
271
-	}
272
-
273
-	/**
274
-	 * @param string $path
275
-	 */
276
-	private function emitPostHooks($exists, $path = null) {
277
-		if (is_null($path)) {
278
-			$path = $this->path;
279
-		}
280
-		$hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
281
-		if (!$exists) {
282
-			\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array(
283
-				\OC\Files\Filesystem::signal_param_path => $hookPath
284
-			));
285
-		} else {
286
-			\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, array(
287
-				\OC\Files\Filesystem::signal_param_path => $hookPath
288
-			));
289
-		}
290
-		\OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array(
291
-			\OC\Files\Filesystem::signal_param_path => $hookPath
292
-		));
293
-	}
294
-
295
-	/**
296
-	 * Returns the data
297
-	 *
298
-	 * @return resource
299
-	 * @throws Forbidden
300
-	 * @throws ServiceUnavailable
301
-	 */
302
-	public function get() {
303
-		//throw exception if encryption is disabled but files are still encrypted
304
-		try {
305
-			$res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
306
-			if ($res === false) {
307
-				throw new ServiceUnavailable("Could not open file");
308
-			}
309
-			return $res;
310
-		} catch (GenericEncryptionException $e) {
311
-			// returning 503 will allow retry of the operation at a later point in time
312
-			throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage());
313
-		} catch (StorageNotAvailableException $e) {
314
-			throw new ServiceUnavailable("Failed to open file: " . $e->getMessage());
315
-		} catch (ForbiddenException $ex) {
316
-			throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
317
-		} catch (LockedException $e) {
318
-			throw new FileLocked($e->getMessage(), $e->getCode(), $e);
319
-		}
320
-	}
321
-
322
-	/**
323
-	 * Delete the current file
324
-	 *
325
-	 * @throws Forbidden
326
-	 * @throws ServiceUnavailable
327
-	 */
328
-	public function delete() {
329
-		if (!$this->info->isDeletable()) {
330
-			throw new Forbidden();
331
-		}
332
-
333
-		try {
334
-			if (!$this->fileView->unlink($this->path)) {
335
-				// assume it wasn't possible to delete due to permissions
336
-				throw new Forbidden();
337
-			}
338
-		} catch (StorageNotAvailableException $e) {
339
-			throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage());
340
-		} catch (ForbiddenException $ex) {
341
-			throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
342
-		} catch (LockedException $e) {
343
-			throw new FileLocked($e->getMessage(), $e->getCode(), $e);
344
-		}
345
-	}
346
-
347
-	/**
348
-	 * Returns the mime-type for a file
349
-	 *
350
-	 * If null is returned, we'll assume application/octet-stream
351
-	 *
352
-	 * @return string
353
-	 */
354
-	public function getContentType() {
355
-		$mimeType = $this->info->getMimetype();
356
-
357
-		// PROPFIND needs to return the correct mime type, for consistency with the web UI
358
-		if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') {
359
-			return $mimeType;
360
-		}
361
-		return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType);
362
-	}
363
-
364
-	/**
365
-	 * @return array|false
366
-	 */
367
-	public function getDirectDownload() {
368
-		if (\OCP\App::isEnabled('encryption')) {
369
-			return [];
370
-		}
371
-		/** @var \OCP\Files\Storage $storage */
372
-		list($storage, $internalPath) = $this->fileView->resolvePath($this->path);
373
-		if (is_null($storage)) {
374
-			return [];
375
-		}
376
-
377
-		return $storage->getDirectDownload($internalPath);
378
-	}
379
-
380
-	/**
381
-	 * @param resource $data
382
-	 * @return null|string
383
-	 * @throws Exception
384
-	 * @throws BadRequest
385
-	 * @throws NotImplemented
386
-	 * @throws ServiceUnavailable
387
-	 */
388
-	private function createFileChunked($data) {
389
-		list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($this->path);
390
-
391
-		$info = \OC_FileChunking::decodeName($name);
392
-		if (empty($info)) {
393
-			throw new NotImplemented('Invalid chunk name');
394
-		}
395
-
396
-		$chunk_handler = new \OC_FileChunking($info);
397
-		$bytesWritten = $chunk_handler->store($info['index'], $data);
398
-
399
-		//detect aborted upload
400
-		if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
401
-			if (isset($_SERVER['CONTENT_LENGTH'])) {
402
-				$expected = $_SERVER['CONTENT_LENGTH'];
403
-				if ($bytesWritten != $expected) {
404
-					$chunk_handler->remove($info['index']);
405
-					throw new BadRequest(
406
-						'expected filesize ' . $expected . ' got ' . $bytesWritten);
407
-				}
408
-			}
409
-		}
410
-
411
-		if ($chunk_handler->isComplete()) {
412
-			list($storage,) = $this->fileView->resolvePath($path);
413
-			$needsPartFile = $this->needsPartFile($storage);
414
-			$partFile = null;
415
-
416
-			$targetPath = $path . '/' . $info['name'];
417
-			/** @var \OC\Files\Storage\Storage $targetStorage */
418
-			list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath);
419
-
420
-			$exists = $this->fileView->file_exists($targetPath);
421
-
422
-			try {
423
-				$this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED);
424
-
425
-				$this->emitPreHooks($exists, $targetPath);
426
-				$this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE);
427
-				/** @var \OC\Files\Storage\Storage $targetStorage */
428
-				list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath);
429
-
430
-				if ($needsPartFile) {
431
-					// we first assembly the target file as a part file
432
-					$partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part';
433
-					/** @var \OC\Files\Storage\Storage $targetStorage */
434
-					list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile);
435
-
436
-
437
-					$chunk_handler->file_assemble($partStorage, $partInternalPath);
438
-
439
-					// here is the final atomic rename
440
-					$renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath);
441
-					$fileExists = $targetStorage->file_exists($targetInternalPath);
442
-					if ($renameOkay === false || $fileExists === false) {
443
-						\OCP\Util::writeLog('webdav', '\OC\Files\Filesystem::rename() failed', \OCP\Util::ERROR);
444
-						// only delete if an error occurred and the target file was already created
445
-						if ($fileExists) {
446
-							// set to null to avoid double-deletion when handling exception
447
-							// stray part file
448
-							$partFile = null;
449
-							$targetStorage->unlink($targetInternalPath);
450
-						}
451
-						$this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED);
452
-						throw new Exception('Could not rename part file assembled from chunks');
453
-					}
454
-				} else {
455
-					// assemble directly into the final file
456
-					$chunk_handler->file_assemble($targetStorage, $targetInternalPath);
457
-				}
458
-
459
-				// allow sync clients to send the mtime along in a header
460
-				$request = \OC::$server->getRequest();
461
-				if (isset($request->server['HTTP_X_OC_MTIME'])) {
462
-					if ($targetStorage->touch($targetInternalPath, $request->server['HTTP_X_OC_MTIME'])) {
463
-						header('X-OC-MTime: accepted');
464
-					}
465
-				}
466
-
467
-				// since we skipped the view we need to scan and emit the hooks ourselves
468
-				$targetStorage->getUpdater()->update($targetInternalPath);
469
-
470
-				$this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED);
471
-
472
-				$this->emitPostHooks($exists, $targetPath);
473
-
474
-				// FIXME: should call refreshInfo but can't because $this->path is not the of the final file
475
-				$info = $this->fileView->getFileInfo($targetPath);
476
-
477
-				if (isset($request->server['HTTP_OC_CHECKSUM'])) {
478
-					$checksum = trim($request->server['HTTP_OC_CHECKSUM']);
479
-					$this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]);
480
-				} else if ($info->getChecksum() !== null && $info->getChecksum() !== '') {
481
-					$this->fileView->putFileInfo($this->path, ['checksum' => '']);
482
-				}
483
-
484
-				$this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED);
485
-
486
-				return $info->getEtag();
487
-			} catch (\Exception $e) {
488
-				if ($partFile !== null) {
489
-					$targetStorage->unlink($targetInternalPath);
490
-				}
491
-				$this->convertToSabreException($e);
492
-			}
493
-		}
494
-
495
-		return null;
496
-	}
497
-
498
-	/**
499
-	 * Returns whether a part file is needed for the given storage
500
-	 * or whether the file can be assembled/uploaded directly on the
501
-	 * target storage.
502
-	 *
503
-	 * @param \OCP\Files\Storage $storage
504
-	 * @return bool true if the storage needs part file handling
505
-	 */
506
-	private function needsPartFile($storage) {
507
-		// TODO: in the future use ChunkHandler provided by storage
508
-		// and/or add method on Storage called "needsPartFile()"
509
-		return !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage') &&
510
-		!$storage->instanceOfStorage('OC\Files\Storage\OwnCloud');
511
-	}
512
-
513
-	/**
514
-	 * Convert the given exception to a SabreException instance
515
-	 *
516
-	 * @param \Exception $e
517
-	 *
518
-	 * @throws \Sabre\DAV\Exception
519
-	 */
520
-	private function convertToSabreException(\Exception $e) {
521
-		if ($e instanceof \Sabre\DAV\Exception) {
522
-			throw $e;
523
-		}
524
-		if ($e instanceof NotPermittedException) {
525
-			// a more general case - due to whatever reason the content could not be written
526
-			throw new Forbidden($e->getMessage(), 0, $e);
527
-		}
528
-		if ($e instanceof ForbiddenException) {
529
-			// the path for the file was forbidden
530
-			throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e);
531
-		}
532
-		if ($e instanceof EntityTooLargeException) {
533
-			// the file is too big to be stored
534
-			throw new EntityTooLarge($e->getMessage(), 0, $e);
535
-		}
536
-		if ($e instanceof InvalidContentException) {
537
-			// the file content is not permitted
538
-			throw new UnsupportedMediaType($e->getMessage(), 0, $e);
539
-		}
540
-		if ($e instanceof InvalidPathException) {
541
-			// the path for the file was not valid
542
-			// TODO: find proper http status code for this case
543
-			throw new Forbidden($e->getMessage(), 0, $e);
544
-		}
545
-		if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) {
546
-			// the file is currently being written to by another process
547
-			throw new FileLocked($e->getMessage(), $e->getCode(), $e);
548
-		}
549
-		if ($e instanceof GenericEncryptionException) {
550
-			// returning 503 will allow retry of the operation at a later point in time
551
-			throw new ServiceUnavailable('Encryption not ready: ' . $e->getMessage(), 0, $e);
552
-		}
553
-		if ($e instanceof StorageNotAvailableException) {
554
-			throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e);
555
-		}
556
-
557
-		throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e);
558
-	}
559
-
560
-	/**
561
-	 * Get the checksum for this file
562
-	 *
563
-	 * @return string
564
-	 */
565
-	public function getChecksum() {
566
-		return $this->info->getChecksum();
567
-	}
214
+            if ($view) {
215
+                $this->emitPostHooks($exists);
216
+            }
217
+
218
+            $this->refreshInfo();
219
+
220
+            if (isset($request->server['HTTP_OC_CHECKSUM'])) {
221
+                $checksum = trim($request->server['HTTP_OC_CHECKSUM']);
222
+                $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]);
223
+                $this->refreshInfo();
224
+            } else if ($this->getChecksum() !== null && $this->getChecksum() !== '') {
225
+                $this->fileView->putFileInfo($this->path, ['checksum' => '']);
226
+                $this->refreshInfo();
227
+            }
228
+
229
+        } catch (StorageNotAvailableException $e) {
230
+            throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage());
231
+        }
232
+
233
+        return '"' . $this->info->getEtag() . '"';
234
+    }
235
+
236
+    private function getPartFileBasePath($path) {
237
+        $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true);
238
+        if ($partFileInStorage) {
239
+            return $path;
240
+        } else {
241
+            return md5($path); // will place it in the root of the view with a unique name
242
+        }
243
+    }
244
+
245
+    /**
246
+     * @param string $path
247
+     */
248
+    private function emitPreHooks($exists, $path = null) {
249
+        if (is_null($path)) {
250
+            $path = $this->path;
251
+        }
252
+        $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
253
+        $run = true;
254
+
255
+        if (!$exists) {
256
+            \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, array(
257
+                \OC\Files\Filesystem::signal_param_path => $hookPath,
258
+                \OC\Files\Filesystem::signal_param_run => &$run,
259
+            ));
260
+        } else {
261
+            \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, array(
262
+                \OC\Files\Filesystem::signal_param_path => $hookPath,
263
+                \OC\Files\Filesystem::signal_param_run => &$run,
264
+            ));
265
+        }
266
+        \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, array(
267
+            \OC\Files\Filesystem::signal_param_path => $hookPath,
268
+            \OC\Files\Filesystem::signal_param_run => &$run,
269
+        ));
270
+        return $run;
271
+    }
272
+
273
+    /**
274
+     * @param string $path
275
+     */
276
+    private function emitPostHooks($exists, $path = null) {
277
+        if (is_null($path)) {
278
+            $path = $this->path;
279
+        }
280
+        $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path));
281
+        if (!$exists) {
282
+            \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array(
283
+                \OC\Files\Filesystem::signal_param_path => $hookPath
284
+            ));
285
+        } else {
286
+            \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, array(
287
+                \OC\Files\Filesystem::signal_param_path => $hookPath
288
+            ));
289
+        }
290
+        \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array(
291
+            \OC\Files\Filesystem::signal_param_path => $hookPath
292
+        ));
293
+    }
294
+
295
+    /**
296
+     * Returns the data
297
+     *
298
+     * @return resource
299
+     * @throws Forbidden
300
+     * @throws ServiceUnavailable
301
+     */
302
+    public function get() {
303
+        //throw exception if encryption is disabled but files are still encrypted
304
+        try {
305
+            $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
306
+            if ($res === false) {
307
+                throw new ServiceUnavailable("Could not open file");
308
+            }
309
+            return $res;
310
+        } catch (GenericEncryptionException $e) {
311
+            // returning 503 will allow retry of the operation at a later point in time
312
+            throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage());
313
+        } catch (StorageNotAvailableException $e) {
314
+            throw new ServiceUnavailable("Failed to open file: " . $e->getMessage());
315
+        } catch (ForbiddenException $ex) {
316
+            throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
317
+        } catch (LockedException $e) {
318
+            throw new FileLocked($e->getMessage(), $e->getCode(), $e);
319
+        }
320
+    }
321
+
322
+    /**
323
+     * Delete the current file
324
+     *
325
+     * @throws Forbidden
326
+     * @throws ServiceUnavailable
327
+     */
328
+    public function delete() {
329
+        if (!$this->info->isDeletable()) {
330
+            throw new Forbidden();
331
+        }
332
+
333
+        try {
334
+            if (!$this->fileView->unlink($this->path)) {
335
+                // assume it wasn't possible to delete due to permissions
336
+                throw new Forbidden();
337
+            }
338
+        } catch (StorageNotAvailableException $e) {
339
+            throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage());
340
+        } catch (ForbiddenException $ex) {
341
+            throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry());
342
+        } catch (LockedException $e) {
343
+            throw new FileLocked($e->getMessage(), $e->getCode(), $e);
344
+        }
345
+    }
346
+
347
+    /**
348
+     * Returns the mime-type for a file
349
+     *
350
+     * If null is returned, we'll assume application/octet-stream
351
+     *
352
+     * @return string
353
+     */
354
+    public function getContentType() {
355
+        $mimeType = $this->info->getMimetype();
356
+
357
+        // PROPFIND needs to return the correct mime type, for consistency with the web UI
358
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') {
359
+            return $mimeType;
360
+        }
361
+        return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType);
362
+    }
363
+
364
+    /**
365
+     * @return array|false
366
+     */
367
+    public function getDirectDownload() {
368
+        if (\OCP\App::isEnabled('encryption')) {
369
+            return [];
370
+        }
371
+        /** @var \OCP\Files\Storage $storage */
372
+        list($storage, $internalPath) = $this->fileView->resolvePath($this->path);
373
+        if (is_null($storage)) {
374
+            return [];
375
+        }
376
+
377
+        return $storage->getDirectDownload($internalPath);
378
+    }
379
+
380
+    /**
381
+     * @param resource $data
382
+     * @return null|string
383
+     * @throws Exception
384
+     * @throws BadRequest
385
+     * @throws NotImplemented
386
+     * @throws ServiceUnavailable
387
+     */
388
+    private function createFileChunked($data) {
389
+        list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($this->path);
390
+
391
+        $info = \OC_FileChunking::decodeName($name);
392
+        if (empty($info)) {
393
+            throw new NotImplemented('Invalid chunk name');
394
+        }
395
+
396
+        $chunk_handler = new \OC_FileChunking($info);
397
+        $bytesWritten = $chunk_handler->store($info['index'], $data);
398
+
399
+        //detect aborted upload
400
+        if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
401
+            if (isset($_SERVER['CONTENT_LENGTH'])) {
402
+                $expected = $_SERVER['CONTENT_LENGTH'];
403
+                if ($bytesWritten != $expected) {
404
+                    $chunk_handler->remove($info['index']);
405
+                    throw new BadRequest(
406
+                        'expected filesize ' . $expected . ' got ' . $bytesWritten);
407
+                }
408
+            }
409
+        }
410
+
411
+        if ($chunk_handler->isComplete()) {
412
+            list($storage,) = $this->fileView->resolvePath($path);
413
+            $needsPartFile = $this->needsPartFile($storage);
414
+            $partFile = null;
415
+
416
+            $targetPath = $path . '/' . $info['name'];
417
+            /** @var \OC\Files\Storage\Storage $targetStorage */
418
+            list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath);
419
+
420
+            $exists = $this->fileView->file_exists($targetPath);
421
+
422
+            try {
423
+                $this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED);
424
+
425
+                $this->emitPreHooks($exists, $targetPath);
426
+                $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE);
427
+                /** @var \OC\Files\Storage\Storage $targetStorage */
428
+                list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath);
429
+
430
+                if ($needsPartFile) {
431
+                    // we first assembly the target file as a part file
432
+                    $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part';
433
+                    /** @var \OC\Files\Storage\Storage $targetStorage */
434
+                    list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile);
435
+
436
+
437
+                    $chunk_handler->file_assemble($partStorage, $partInternalPath);
438
+
439
+                    // here is the final atomic rename
440
+                    $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath);
441
+                    $fileExists = $targetStorage->file_exists($targetInternalPath);
442
+                    if ($renameOkay === false || $fileExists === false) {
443
+                        \OCP\Util::writeLog('webdav', '\OC\Files\Filesystem::rename() failed', \OCP\Util::ERROR);
444
+                        // only delete if an error occurred and the target file was already created
445
+                        if ($fileExists) {
446
+                            // set to null to avoid double-deletion when handling exception
447
+                            // stray part file
448
+                            $partFile = null;
449
+                            $targetStorage->unlink($targetInternalPath);
450
+                        }
451
+                        $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED);
452
+                        throw new Exception('Could not rename part file assembled from chunks');
453
+                    }
454
+                } else {
455
+                    // assemble directly into the final file
456
+                    $chunk_handler->file_assemble($targetStorage, $targetInternalPath);
457
+                }
458
+
459
+                // allow sync clients to send the mtime along in a header
460
+                $request = \OC::$server->getRequest();
461
+                if (isset($request->server['HTTP_X_OC_MTIME'])) {
462
+                    if ($targetStorage->touch($targetInternalPath, $request->server['HTTP_X_OC_MTIME'])) {
463
+                        header('X-OC-MTime: accepted');
464
+                    }
465
+                }
466
+
467
+                // since we skipped the view we need to scan and emit the hooks ourselves
468
+                $targetStorage->getUpdater()->update($targetInternalPath);
469
+
470
+                $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED);
471
+
472
+                $this->emitPostHooks($exists, $targetPath);
473
+
474
+                // FIXME: should call refreshInfo but can't because $this->path is not the of the final file
475
+                $info = $this->fileView->getFileInfo($targetPath);
476
+
477
+                if (isset($request->server['HTTP_OC_CHECKSUM'])) {
478
+                    $checksum = trim($request->server['HTTP_OC_CHECKSUM']);
479
+                    $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]);
480
+                } else if ($info->getChecksum() !== null && $info->getChecksum() !== '') {
481
+                    $this->fileView->putFileInfo($this->path, ['checksum' => '']);
482
+                }
483
+
484
+                $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED);
485
+
486
+                return $info->getEtag();
487
+            } catch (\Exception $e) {
488
+                if ($partFile !== null) {
489
+                    $targetStorage->unlink($targetInternalPath);
490
+                }
491
+                $this->convertToSabreException($e);
492
+            }
493
+        }
494
+
495
+        return null;
496
+    }
497
+
498
+    /**
499
+     * Returns whether a part file is needed for the given storage
500
+     * or whether the file can be assembled/uploaded directly on the
501
+     * target storage.
502
+     *
503
+     * @param \OCP\Files\Storage $storage
504
+     * @return bool true if the storage needs part file handling
505
+     */
506
+    private function needsPartFile($storage) {
507
+        // TODO: in the future use ChunkHandler provided by storage
508
+        // and/or add method on Storage called "needsPartFile()"
509
+        return !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage') &&
510
+        !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud');
511
+    }
512
+
513
+    /**
514
+     * Convert the given exception to a SabreException instance
515
+     *
516
+     * @param \Exception $e
517
+     *
518
+     * @throws \Sabre\DAV\Exception
519
+     */
520
+    private function convertToSabreException(\Exception $e) {
521
+        if ($e instanceof \Sabre\DAV\Exception) {
522
+            throw $e;
523
+        }
524
+        if ($e instanceof NotPermittedException) {
525
+            // a more general case - due to whatever reason the content could not be written
526
+            throw new Forbidden($e->getMessage(), 0, $e);
527
+        }
528
+        if ($e instanceof ForbiddenException) {
529
+            // the path for the file was forbidden
530
+            throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e);
531
+        }
532
+        if ($e instanceof EntityTooLargeException) {
533
+            // the file is too big to be stored
534
+            throw new EntityTooLarge($e->getMessage(), 0, $e);
535
+        }
536
+        if ($e instanceof InvalidContentException) {
537
+            // the file content is not permitted
538
+            throw new UnsupportedMediaType($e->getMessage(), 0, $e);
539
+        }
540
+        if ($e instanceof InvalidPathException) {
541
+            // the path for the file was not valid
542
+            // TODO: find proper http status code for this case
543
+            throw new Forbidden($e->getMessage(), 0, $e);
544
+        }
545
+        if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) {
546
+            // the file is currently being written to by another process
547
+            throw new FileLocked($e->getMessage(), $e->getCode(), $e);
548
+        }
549
+        if ($e instanceof GenericEncryptionException) {
550
+            // returning 503 will allow retry of the operation at a later point in time
551
+            throw new ServiceUnavailable('Encryption not ready: ' . $e->getMessage(), 0, $e);
552
+        }
553
+        if ($e instanceof StorageNotAvailableException) {
554
+            throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e);
555
+        }
556
+
557
+        throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e);
558
+    }
559
+
560
+    /**
561
+     * Get the checksum for this file
562
+     *
563
+     * @return string
564
+     */
565
+    public function getChecksum() {
566
+        return $this->info->getChecksum();
567
+    }
568 568
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/Forbidden.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -24,42 +24,42 @@
 block discarded – undo
24 24
 
25 25
 class Forbidden extends \Sabre\DAV\Exception\Forbidden {
26 26
 
27
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
27
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
28 28
 
29
-	/**
30
-	 * @var bool
31
-	 */
32
-	private $retry;
29
+    /**
30
+     * @var bool
31
+     */
32
+    private $retry;
33 33
 
34
-	/**
35
-	 * @param string $message
36
-	 * @param bool $retry
37
-	 * @param \Exception $previous
38
-	 */
39
-	public function __construct($message, $retry = false, \Exception $previous = null) {
40
-		parent::__construct($message, 0, $previous);
41
-		$this->retry = $retry;
42
-	}
34
+    /**
35
+     * @param string $message
36
+     * @param bool $retry
37
+     * @param \Exception $previous
38
+     */
39
+    public function __construct($message, $retry = false, \Exception $previous = null) {
40
+        parent::__construct($message, 0, $previous);
41
+        $this->retry = $retry;
42
+    }
43 43
 
44
-	/**
45
-	 * This method allows the exception to include additional information
46
-	 * into the WebDAV error response
47
-	 *
48
-	 * @param \Sabre\DAV\Server $server
49
-	 * @param \DOMElement $errorNode
50
-	 * @return void
51
-	 */
52
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
44
+    /**
45
+     * This method allows the exception to include additional information
46
+     * into the WebDAV error response
47
+     *
48
+     * @param \Sabre\DAV\Server $server
49
+     * @param \DOMElement $errorNode
50
+     * @return void
51
+     */
52
+    public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
53 53
 
54
-		// set ownCloud namespace
55
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
54
+        // set ownCloud namespace
55
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
56 56
 
57
-		// adding the retry node
58
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
59
-		$errorNode->appendChild($error);
57
+        // adding the retry node
58
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
59
+        $errorNode->appendChild($error);
60 60
 
61
-		// adding the message node
62
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
63
-		$errorNode->appendChild($error);
64
-	}
61
+        // adding the message node
62
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
63
+        $errorNode->appendChild($error);
64
+    }
65 65
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/InvalidPath.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -26,53 +26,53 @@
 block discarded – undo
26 26
 
27 27
 class InvalidPath extends Exception {
28 28
 
29
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
29
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
30 30
 
31
-	/**
32
-	 * @var bool
33
-	 */
34
-	private $retry;
31
+    /**
32
+     * @var bool
33
+     */
34
+    private $retry;
35 35
 
36
-	/**
37
-	 * @param string $message
38
-	 * @param bool $retry
39
-	 */
40
-	public function __construct($message, $retry = false) {
41
-		parent::__construct($message);
42
-		$this->retry = $retry;
43
-	}
36
+    /**
37
+     * @param string $message
38
+     * @param bool $retry
39
+     */
40
+    public function __construct($message, $retry = false) {
41
+        parent::__construct($message);
42
+        $this->retry = $retry;
43
+    }
44 44
 
45
-	/**
46
-	 * Returns the HTTP status code for this exception
47
-	 *
48
-	 * @return int
49
-	 */
50
-	public function getHTTPCode() {
45
+    /**
46
+     * Returns the HTTP status code for this exception
47
+     *
48
+     * @return int
49
+     */
50
+    public function getHTTPCode() {
51 51
 
52
-		return 400;
52
+        return 400;
53 53
 
54
-	}
54
+    }
55 55
 
56
-	/**
57
-	 * This method allows the exception to include additional information
58
-	 * into the WebDAV error response
59
-	 *
60
-	 * @param \Sabre\DAV\Server $server
61
-	 * @param \DOMElement $errorNode
62
-	 * @return void
63
-	 */
64
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
56
+    /**
57
+     * This method allows the exception to include additional information
58
+     * into the WebDAV error response
59
+     *
60
+     * @param \Sabre\DAV\Server $server
61
+     * @param \DOMElement $errorNode
62
+     * @return void
63
+     */
64
+    public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
65 65
 
66
-		// set ownCloud namespace
67
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
66
+        // set ownCloud namespace
67
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
68 68
 
69
-		// adding the retry node
70
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
71
-		$errorNode->appendChild($error);
69
+        // adding the retry node
70
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
71
+        $errorNode->appendChild($error);
72 72
 
73
-		// adding the message node
74
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
75
-		$errorNode->appendChild($error);
76
-	}
73
+        // adding the message node
74
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
75
+        $errorNode->appendChild($error);
76
+    }
77 77
 
78 78
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/PasswordLoginForbidden.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,27 +29,27 @@
 block discarded – undo
29 29
 
30 30
 class PasswordLoginForbidden extends NotAuthenticated {
31 31
 
32
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
33
-
34
-	public function getHTTPCode() {
35
-		return 401;
36
-	}
37
-
38
-	/**
39
-	 * This method allows the exception to include additional information
40
-	 * into the WebDAV error response
41
-	 *
42
-	 * @param Server $server
43
-	 * @param DOMElement $errorNode
44
-	 * @return void
45
-	 */
46
-	public function serialize(Server $server, DOMElement $errorNode) {
47
-
48
-		// set ownCloud namespace
49
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
50
-
51
-		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden');
52
-		$errorNode->appendChild($error);
53
-	}
32
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
33
+
34
+    public function getHTTPCode() {
35
+        return 401;
36
+    }
37
+
38
+    /**
39
+     * This method allows the exception to include additional information
40
+     * into the WebDAV error response
41
+     *
42
+     * @param Server $server
43
+     * @param DOMElement $errorNode
44
+     * @return void
45
+     */
46
+    public function serialize(Server $server, DOMElement $errorNode) {
47
+
48
+        // set ownCloud namespace
49
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
50
+
51
+        $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden');
52
+        $errorNode->appendChild($error);
53
+    }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/FileLocked.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,20 +30,20 @@
 block discarded – undo
30 30
 
31 31
 class FileLocked extends \Sabre\DAV\Exception {
32 32
 
33
-	public function __construct($message = "", $code = 0, Exception $previous = null) {
34
-		if($previous instanceof \OCP\Files\LockNotAcquiredException) {
35
-			$message = sprintf('Target file %s is locked by another process.', $previous->path);
36
-		}
37
-		parent::__construct($message, $code, $previous);
38
-	}
33
+    public function __construct($message = "", $code = 0, Exception $previous = null) {
34
+        if($previous instanceof \OCP\Files\LockNotAcquiredException) {
35
+            $message = sprintf('Target file %s is locked by another process.', $previous->path);
36
+        }
37
+        parent::__construct($message, $code, $previous);
38
+    }
39 39
 
40
-	/**
41
-	 * Returns the HTTP status code for this exception
42
-	 *
43
-	 * @return int
44
-	 */
45
-	public function getHTTPCode() {
40
+    /**
41
+     * Returns the HTTP status code for this exception
42
+     *
43
+     * @return int
44
+     */
45
+    public function getHTTPCode() {
46 46
 
47
-		return 423;
48
-	}
47
+        return 423;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/UnsupportedMediaType.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class UnsupportedMediaType extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 415;
41
+        return 415;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/EntityTooLarge.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class EntityTooLarge extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 413;
41
+        return 413;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ServerFactory.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -42,158 +42,158 @@
 block discarded – undo
42 42
 use Sabre\DAV\Auth\Backend\BackendInterface;
43 43
 
44 44
 class ServerFactory {
45
-	/** @var IConfig */
46
-	private $config;
47
-	/** @var ILogger */
48
-	private $logger;
49
-	/** @var IDBConnection */
50
-	private $databaseConnection;
51
-	/** @var IUserSession */
52
-	private $userSession;
53
-	/** @var IMountManager */
54
-	private $mountManager;
55
-	/** @var ITagManager */
56
-	private $tagManager;
57
-	/** @var IRequest */
58
-	private $request;
59
-	/** @var IPreview  */
60
-	private $previewManager;
45
+    /** @var IConfig */
46
+    private $config;
47
+    /** @var ILogger */
48
+    private $logger;
49
+    /** @var IDBConnection */
50
+    private $databaseConnection;
51
+    /** @var IUserSession */
52
+    private $userSession;
53
+    /** @var IMountManager */
54
+    private $mountManager;
55
+    /** @var ITagManager */
56
+    private $tagManager;
57
+    /** @var IRequest */
58
+    private $request;
59
+    /** @var IPreview  */
60
+    private $previewManager;
61 61
 
62
-	/**
63
-	 * @param IConfig $config
64
-	 * @param ILogger $logger
65
-	 * @param IDBConnection $databaseConnection
66
-	 * @param IUserSession $userSession
67
-	 * @param IMountManager $mountManager
68
-	 * @param ITagManager $tagManager
69
-	 * @param IRequest $request
70
-	 * @param IPreview $previewManager
71
-	 */
72
-	public function __construct(
73
-		IConfig $config,
74
-		ILogger $logger,
75
-		IDBConnection $databaseConnection,
76
-		IUserSession $userSession,
77
-		IMountManager $mountManager,
78
-		ITagManager $tagManager,
79
-		IRequest $request,
80
-		IPreview $previewManager
81
-	) {
82
-		$this->config = $config;
83
-		$this->logger = $logger;
84
-		$this->databaseConnection = $databaseConnection;
85
-		$this->userSession = $userSession;
86
-		$this->mountManager = $mountManager;
87
-		$this->tagManager = $tagManager;
88
-		$this->request = $request;
89
-		$this->previewManager = $previewManager;
90
-	}
62
+    /**
63
+     * @param IConfig $config
64
+     * @param ILogger $logger
65
+     * @param IDBConnection $databaseConnection
66
+     * @param IUserSession $userSession
67
+     * @param IMountManager $mountManager
68
+     * @param ITagManager $tagManager
69
+     * @param IRequest $request
70
+     * @param IPreview $previewManager
71
+     */
72
+    public function __construct(
73
+        IConfig $config,
74
+        ILogger $logger,
75
+        IDBConnection $databaseConnection,
76
+        IUserSession $userSession,
77
+        IMountManager $mountManager,
78
+        ITagManager $tagManager,
79
+        IRequest $request,
80
+        IPreview $previewManager
81
+    ) {
82
+        $this->config = $config;
83
+        $this->logger = $logger;
84
+        $this->databaseConnection = $databaseConnection;
85
+        $this->userSession = $userSession;
86
+        $this->mountManager = $mountManager;
87
+        $this->tagManager = $tagManager;
88
+        $this->request = $request;
89
+        $this->previewManager = $previewManager;
90
+    }
91 91
 
92
-	/**
93
-	 * @param string $baseUri
94
-	 * @param string $requestUri
95
-	 * @param BackendInterface $authBackend
96
-	 * @param callable $viewCallBack callback that should return the view for the dav endpoint
97
-	 * @return Server
98
-	 */
99
-	public function createServer($baseUri,
100
-								 $requestUri,
101
-								 BackendInterface $authBackend,
102
-								 callable $viewCallBack) {
103
-		// Fire up server
104
-		$objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree();
105
-		$server = new \OCA\DAV\Connector\Sabre\Server($objectTree);
106
-		// Set URL explicitly due to reverse-proxy situations
107
-		$server->httpRequest->setUrl($requestUri);
108
-		$server->setBaseUri($baseUri);
92
+    /**
93
+     * @param string $baseUri
94
+     * @param string $requestUri
95
+     * @param BackendInterface $authBackend
96
+     * @param callable $viewCallBack callback that should return the view for the dav endpoint
97
+     * @return Server
98
+     */
99
+    public function createServer($baseUri,
100
+                                    $requestUri,
101
+                                    BackendInterface $authBackend,
102
+                                    callable $viewCallBack) {
103
+        // Fire up server
104
+        $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree();
105
+        $server = new \OCA\DAV\Connector\Sabre\Server($objectTree);
106
+        // Set URL explicitly due to reverse-proxy situations
107
+        $server->httpRequest->setUrl($requestUri);
108
+        $server->setBaseUri($baseUri);
109 109
 
110
-		// Load plugins
111
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config));
112
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
113
-		$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
114
-		// FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
115
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
116
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
117
-		$server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
118
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
119
-		// we do not provide locking we emulate it using a fake locking plugin.
120
-		if($this->request->isUserAgent([
121
-				'/WebDAVFS/',
122
-				'/Microsoft Office OneNote 2013/',
123
-				'/Microsoft-WebDAV-MiniRedir/',
124
-		])) {
125
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
126
-		}
110
+        // Load plugins
111
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config));
112
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config));
113
+        $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
114
+        // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
115
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
116
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger));
117
+        $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
118
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
119
+        // we do not provide locking we emulate it using a fake locking plugin.
120
+        if($this->request->isUserAgent([
121
+                '/WebDAVFS/',
122
+                '/Microsoft Office OneNote 2013/',
123
+                '/Microsoft-WebDAV-MiniRedir/',
124
+        ])) {
125
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
126
+        }
127 127
 
128
-		if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
129
-			$server->addPlugin(new BrowserErrorPagePlugin());
130
-		}
128
+        if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) {
129
+            $server->addPlugin(new BrowserErrorPagePlugin());
130
+        }
131 131
 
132
-		// wait with registering these until auth is handled and the filesystem is setup
133
-		$server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {
134
-			// ensure the skeleton is copied
135
-			$userFolder = \OC::$server->getUserFolder();
132
+        // wait with registering these until auth is handled and the filesystem is setup
133
+        $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) {
134
+            // ensure the skeleton is copied
135
+            $userFolder = \OC::$server->getUserFolder();
136 136
 			
137
-			/** @var \OC\Files\View $view */
138
-			$view = $viewCallBack($server);
139
-			if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
140
-				$rootInfo = $userFolder;
141
-			} else {
142
-				$rootInfo = $view->getFileInfo('');
143
-			}
137
+            /** @var \OC\Files\View $view */
138
+            $view = $viewCallBack($server);
139
+            if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) {
140
+                $rootInfo = $userFolder;
141
+            } else {
142
+                $rootInfo = $view->getFileInfo('');
143
+            }
144 144
 
145
-			// Create ownCloud Dir
146
-			if ($rootInfo->getType() === 'dir') {
147
-				$root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
148
-			} else {
149
-				$root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
150
-			}
151
-			$objectTree->init($root, $view, $this->mountManager);
145
+            // Create ownCloud Dir
146
+            if ($rootInfo->getType() === 'dir') {
147
+                $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
148
+            } else {
149
+                $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
150
+            }
151
+            $objectTree->init($root, $view, $this->mountManager);
152 152
 
153
-			$server->addPlugin(
154
-				new \OCA\DAV\Connector\Sabre\FilesPlugin(
155
-					$objectTree,
156
-					$this->config,
157
-					$this->request,
158
-					$this->previewManager,
159
-					false,
160
-					!$this->config->getSystemValue('debug', false)
161
-				)
162
-			);
163
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
153
+            $server->addPlugin(
154
+                new \OCA\DAV\Connector\Sabre\FilesPlugin(
155
+                    $objectTree,
156
+                    $this->config,
157
+                    $this->request,
158
+                    $this->previewManager,
159
+                    false,
160
+                    !$this->config->getSystemValue('debug', false)
161
+                )
162
+            );
163
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
164 164
 
165
-			if($this->userSession->isLoggedIn()) {
166
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
167
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
168
-					$objectTree,
169
-					$this->userSession,
170
-					$userFolder,
171
-					\OC::$server->getShareManager()
172
-				));
173
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession));
174
-				$server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
175
-					$objectTree,
176
-					$view,
177
-					\OC::$server->getSystemTagManager(),
178
-					\OC::$server->getSystemTagObjectMapper(),
179
-					\OC::$server->getTagManager(),
180
-					$this->userSession,
181
-					\OC::$server->getGroupManager(),
182
-					$userFolder
183
-				));
184
-				// custom properties plugin must be the last one
185
-				$server->addPlugin(
186
-					new \Sabre\DAV\PropertyStorage\Plugin(
187
-						new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend(
188
-							$objectTree,
189
-							$this->databaseConnection,
190
-							$this->userSession->getUser()
191
-						)
192
-					)
193
-				);
194
-			}
195
-			$server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
196
-		}, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
197
-		return $server;
198
-	}
165
+            if($this->userSession->isLoggedIn()) {
166
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager));
167
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
168
+                    $objectTree,
169
+                    $this->userSession,
170
+                    $userFolder,
171
+                    \OC::$server->getShareManager()
172
+                ));
173
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession));
174
+                $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
175
+                    $objectTree,
176
+                    $view,
177
+                    \OC::$server->getSystemTagManager(),
178
+                    \OC::$server->getSystemTagObjectMapper(),
179
+                    \OC::$server->getTagManager(),
180
+                    $this->userSession,
181
+                    \OC::$server->getGroupManager(),
182
+                    $userFolder
183
+                ));
184
+                // custom properties plugin must be the last one
185
+                $server->addPlugin(
186
+                    new \Sabre\DAV\PropertyStorage\Plugin(
187
+                        new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend(
188
+                            $objectTree,
189
+                            $this->databaseConnection,
190
+                            $this->userSession->getUser()
191
+                        )
192
+                    )
193
+                );
194
+            }
195
+            $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
196
+        }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
197
+        return $server;
198
+    }
199 199
 }
Please login to merge, or discard this patch.