@@ -32,93 +32,93 @@ |
||
| 32 | 32 | |
| 33 | 33 | class ChunkingPlugin extends ServerPlugin { |
| 34 | 34 | |
| 35 | - /** @var Server */ |
|
| 36 | - private $server; |
|
| 37 | - /** @var FutureFile */ |
|
| 38 | - private $sourceNode; |
|
| 35 | + /** @var Server */ |
|
| 36 | + private $server; |
|
| 37 | + /** @var FutureFile */ |
|
| 38 | + private $sourceNode; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @inheritdoc |
|
| 42 | - */ |
|
| 43 | - public function initialize(Server $server) { |
|
| 44 | - $server->on('beforeMove', [$this, 'beforeMove']); |
|
| 45 | - $this->server = $server; |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * @inheritdoc |
|
| 42 | + */ |
|
| 43 | + public function initialize(Server $server) { |
|
| 44 | + $server->on('beforeMove', [$this, 'beforeMove']); |
|
| 45 | + $this->server = $server; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $sourcePath source path |
|
| 50 | - * @param string $destination destination path |
|
| 51 | - * @return bool|void |
|
| 52 | - * @throws BadRequest |
|
| 53 | - * @throws NotFound |
|
| 54 | - */ |
|
| 55 | - public function beforeMove($sourcePath, $destination) { |
|
| 56 | - $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
| 57 | - if (!$this->sourceNode instanceof FutureFile) { |
|
| 58 | - // skip handling as the source is not a chunked FutureFile |
|
| 59 | - return; |
|
| 60 | - } |
|
| 48 | + /** |
|
| 49 | + * @param string $sourcePath source path |
|
| 50 | + * @param string $destination destination path |
|
| 51 | + * @return bool|void |
|
| 52 | + * @throws BadRequest |
|
| 53 | + * @throws NotFound |
|
| 54 | + */ |
|
| 55 | + public function beforeMove($sourcePath, $destination) { |
|
| 56 | + $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
| 57 | + if (!$this->sourceNode instanceof FutureFile) { |
|
| 58 | + // skip handling as the source is not a chunked FutureFile |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - try { |
|
| 63 | - /** @var INode $destinationNode */ |
|
| 64 | - $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
| 65 | - if ($destinationNode instanceof Directory) { |
|
| 66 | - throw new BadRequest("The given destination $destination is a directory."); |
|
| 67 | - } |
|
| 68 | - } catch (NotFound $e) { |
|
| 69 | - // If the destination does not exist yet it's not a directory either ;) |
|
| 70 | - } |
|
| 62 | + try { |
|
| 63 | + /** @var INode $destinationNode */ |
|
| 64 | + $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
| 65 | + if ($destinationNode instanceof Directory) { |
|
| 66 | + throw new BadRequest("The given destination $destination is a directory."); |
|
| 67 | + } |
|
| 68 | + } catch (NotFound $e) { |
|
| 69 | + // If the destination does not exist yet it's not a directory either ;) |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $this->verifySize(); |
|
| 73 | - return $this->performMove($sourcePath, $destination); |
|
| 74 | - } |
|
| 72 | + $this->verifySize(); |
|
| 73 | + return $this->performMove($sourcePath, $destination); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Move handler for future file. |
|
| 78 | - * |
|
| 79 | - * This overrides the default move behavior to prevent Sabre |
|
| 80 | - * to delete the target file before moving. Because deleting would |
|
| 81 | - * lose the file id and metadata. |
|
| 82 | - * |
|
| 83 | - * @param string $path source path |
|
| 84 | - * @param string $destination destination path |
|
| 85 | - * @return bool|void false to stop handling, void to skip this handler |
|
| 86 | - */ |
|
| 87 | - public function performMove($path, $destination) { |
|
| 88 | - if (!$this->server->tree->nodeExists($destination)) { |
|
| 89 | - // skip and let the default handler do its work |
|
| 90 | - return; |
|
| 91 | - } |
|
| 76 | + /** |
|
| 77 | + * Move handler for future file. |
|
| 78 | + * |
|
| 79 | + * This overrides the default move behavior to prevent Sabre |
|
| 80 | + * to delete the target file before moving. Because deleting would |
|
| 81 | + * lose the file id and metadata. |
|
| 82 | + * |
|
| 83 | + * @param string $path source path |
|
| 84 | + * @param string $destination destination path |
|
| 85 | + * @return bool|void false to stop handling, void to skip this handler |
|
| 86 | + */ |
|
| 87 | + public function performMove($path, $destination) { |
|
| 88 | + if (!$this->server->tree->nodeExists($destination)) { |
|
| 89 | + // skip and let the default handler do its work |
|
| 90 | + return; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 94 | - $this->server->tree->move($path, $destination); |
|
| 93 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 94 | + $this->server->tree->move($path, $destination); |
|
| 95 | 95 | |
| 96 | - // trigger all default events (copied from CorePlugin::move) |
|
| 97 | - $this->server->emit('afterMove', [$path, $destination]); |
|
| 98 | - $this->server->emit('afterUnbind', [$path]); |
|
| 99 | - $this->server->emit('afterBind', [$destination]); |
|
| 96 | + // trigger all default events (copied from CorePlugin::move) |
|
| 97 | + $this->server->emit('afterMove', [$path, $destination]); |
|
| 98 | + $this->server->emit('afterUnbind', [$path]); |
|
| 99 | + $this->server->emit('afterBind', [$destination]); |
|
| 100 | 100 | |
| 101 | - $response = $this->server->httpResponse; |
|
| 102 | - $response->setHeader('Content-Length', '0'); |
|
| 103 | - $response->setStatus(204); |
|
| 101 | + $response = $this->server->httpResponse; |
|
| 102 | + $response->setHeader('Content-Length', '0'); |
|
| 103 | + $response->setStatus(204); |
|
| 104 | 104 | |
| 105 | - return false; |
|
| 106 | - } |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @throws BadRequest |
|
| 110 | - */ |
|
| 111 | - private function verifySize() { |
|
| 112 | - $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
| 113 | - if ($expectedSize === null) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - $actualSize = $this->sourceNode->getSize(); |
|
| 108 | + /** |
|
| 109 | + * @throws BadRequest |
|
| 110 | + */ |
|
| 111 | + private function verifySize() { |
|
| 112 | + $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
| 113 | + if ($expectedSize === null) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + $actualSize = $this->sourceNode->getSize(); |
|
| 117 | 117 | |
| 118 | - // casted to string because cast to float cause equality for non equal numbers |
|
| 119 | - // and integer has the problem of limited size on 32 bit systems |
|
| 120 | - if ((string)$expectedSize !== (string)$actualSize) { |
|
| 121 | - throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
| 122 | - } |
|
| 123 | - } |
|
| 118 | + // casted to string because cast to float cause equality for non equal numbers |
|
| 119 | + // and integer has the problem of limited size on 32 bit systems |
|
| 120 | + if ((string)$expectedSize !== (string)$actualSize) { |
|
| 121 | + throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | } |