@@ -40,114 +40,114 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | class QuotaPlugin extends \Sabre\DAV\ServerPlugin { |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var \OC\Files\View |
|
| 45 | - */ |
|
| 46 | - private $view; |
|
| 43 | + /** |
|
| 44 | + * @var \OC\Files\View |
|
| 45 | + */ |
|
| 46 | + private $view; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Reference to main server object |
|
| 50 | - * |
|
| 51 | - * @var \Sabre\DAV\Server |
|
| 52 | - */ |
|
| 53 | - private $server; |
|
| 48 | + /** |
|
| 49 | + * Reference to main server object |
|
| 50 | + * |
|
| 51 | + * @var \Sabre\DAV\Server |
|
| 52 | + */ |
|
| 53 | + private $server; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param \OC\Files\View $view |
|
| 57 | - */ |
|
| 58 | - public function __construct($view) { |
|
| 59 | - $this->view = $view; |
|
| 60 | - } |
|
| 55 | + /** |
|
| 56 | + * @param \OC\Files\View $view |
|
| 57 | + */ |
|
| 58 | + public function __construct($view) { |
|
| 59 | + $this->view = $view; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * This initializes the plugin. |
|
| 64 | - * |
|
| 65 | - * This function is called by \Sabre\DAV\Server, after |
|
| 66 | - * addPlugin is called. |
|
| 67 | - * |
|
| 68 | - * This method should set up the requires event subscriptions. |
|
| 69 | - * |
|
| 70 | - * @param \Sabre\DAV\Server $server |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 62 | + /** |
|
| 63 | + * This initializes the plugin. |
|
| 64 | + * |
|
| 65 | + * This function is called by \Sabre\DAV\Server, after |
|
| 66 | + * addPlugin is called. |
|
| 67 | + * |
|
| 68 | + * This method should set up the requires event subscriptions. |
|
| 69 | + * |
|
| 70 | + * @param \Sabre\DAV\Server $server |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 74 | 74 | |
| 75 | - $this->server = $server; |
|
| 75 | + $this->server = $server; |
|
| 76 | 76 | |
| 77 | - $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
| 78 | - $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
| 79 | - } |
|
| 77 | + $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
| 78 | + $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * This method is called before any HTTP method and validates there is enough free space to store the file |
|
| 83 | - * |
|
| 84 | - * @param string $uri |
|
| 85 | - * @throws InsufficientStorage |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - public function checkQuota($uri) { |
|
| 89 | - $length = $this->getLength(); |
|
| 90 | - if ($length) { |
|
| 91 | - if (substr($uri, 0, 1) !== '/') { |
|
| 92 | - $uri = '/' . $uri; |
|
| 93 | - } |
|
| 94 | - list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
| 95 | - if(is_null($parentUri)) { |
|
| 96 | - $parentUri = ''; |
|
| 97 | - } |
|
| 98 | - $req = $this->server->httpRequest; |
|
| 99 | - if ($req->getHeader('OC-Chunked')) { |
|
| 100 | - $info = \OC_FileChunking::decodeName($newName); |
|
| 101 | - $chunkHandler = $this->getFileChunking($info); |
|
| 102 | - // subtract the already uploaded size to see whether |
|
| 103 | - // there is still enough space for the remaining chunks |
|
| 104 | - $length -= $chunkHandler->getCurrentSize(); |
|
| 105 | - // use target file name for free space check in case of shared files |
|
| 106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
| 107 | - } |
|
| 108 | - $freeSpace = $this->getFreeSpace($uri); |
|
| 109 | - if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && $length > $freeSpace) { |
|
| 110 | - if (isset($chunkHandler)) { |
|
| 111 | - $chunkHandler->cleanup(); |
|
| 112 | - } |
|
| 113 | - throw new InsufficientStorage(); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - return true; |
|
| 117 | - } |
|
| 81 | + /** |
|
| 82 | + * This method is called before any HTTP method and validates there is enough free space to store the file |
|
| 83 | + * |
|
| 84 | + * @param string $uri |
|
| 85 | + * @throws InsufficientStorage |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + public function checkQuota($uri) { |
|
| 89 | + $length = $this->getLength(); |
|
| 90 | + if ($length) { |
|
| 91 | + if (substr($uri, 0, 1) !== '/') { |
|
| 92 | + $uri = '/' . $uri; |
|
| 93 | + } |
|
| 94 | + list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
| 95 | + if(is_null($parentUri)) { |
|
| 96 | + $parentUri = ''; |
|
| 97 | + } |
|
| 98 | + $req = $this->server->httpRequest; |
|
| 99 | + if ($req->getHeader('OC-Chunked')) { |
|
| 100 | + $info = \OC_FileChunking::decodeName($newName); |
|
| 101 | + $chunkHandler = $this->getFileChunking($info); |
|
| 102 | + // subtract the already uploaded size to see whether |
|
| 103 | + // there is still enough space for the remaining chunks |
|
| 104 | + $length -= $chunkHandler->getCurrentSize(); |
|
| 105 | + // use target file name for free space check in case of shared files |
|
| 106 | + $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
| 107 | + } |
|
| 108 | + $freeSpace = $this->getFreeSpace($uri); |
|
| 109 | + if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && $length > $freeSpace) { |
|
| 110 | + if (isset($chunkHandler)) { |
|
| 111 | + $chunkHandler->cleanup(); |
|
| 112 | + } |
|
| 113 | + throw new InsufficientStorage(); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + return true; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - public function getFileChunking($info) { |
|
| 120 | - // FIXME: need a factory for better mocking support |
|
| 121 | - return new \OC_FileChunking($info); |
|
| 122 | - } |
|
| 119 | + public function getFileChunking($info) { |
|
| 120 | + // FIXME: need a factory for better mocking support |
|
| 121 | + return new \OC_FileChunking($info); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - public function getLength() { |
|
| 125 | - $req = $this->server->httpRequest; |
|
| 126 | - $length = $req->getHeader('X-Expected-Entity-Length'); |
|
| 127 | - if (!is_numeric($length)) { |
|
| 128 | - $length = $req->getHeader('Content-Length'); |
|
| 129 | - $length = is_numeric($length) ? $length : null; |
|
| 130 | - } |
|
| 124 | + public function getLength() { |
|
| 125 | + $req = $this->server->httpRequest; |
|
| 126 | + $length = $req->getHeader('X-Expected-Entity-Length'); |
|
| 127 | + if (!is_numeric($length)) { |
|
| 128 | + $length = $req->getHeader('Content-Length'); |
|
| 129 | + $length = is_numeric($length) ? $length : null; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - $ocLength = $req->getHeader('OC-Total-Length'); |
|
| 133 | - if (is_numeric($length) && is_numeric($ocLength)) { |
|
| 134 | - return max($length, $ocLength); |
|
| 135 | - } |
|
| 132 | + $ocLength = $req->getHeader('OC-Total-Length'); |
|
| 133 | + if (is_numeric($length) && is_numeric($ocLength)) { |
|
| 134 | + return max($length, $ocLength); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $length; |
|
| 138 | - } |
|
| 137 | + return $length; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @param string $uri |
|
| 142 | - * @return mixed |
|
| 143 | - * @throws ServiceUnavailable |
|
| 144 | - */ |
|
| 145 | - public function getFreeSpace($uri) { |
|
| 146 | - try { |
|
| 147 | - $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
| 148 | - return $freeSpace; |
|
| 149 | - } catch (StorageNotAvailableException $e) { |
|
| 150 | - throw new ServiceUnavailable($e->getMessage()); |
|
| 151 | - } |
|
| 152 | - } |
|
| 140 | + /** |
|
| 141 | + * @param string $uri |
|
| 142 | + * @return mixed |
|
| 143 | + * @throws ServiceUnavailable |
|
| 144 | + */ |
|
| 145 | + public function getFreeSpace($uri) { |
|
| 146 | + try { |
|
| 147 | + $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
| 148 | + return $freeSpace; |
|
| 149 | + } catch (StorageNotAvailableException $e) { |
|
| 150 | + throw new ServiceUnavailable($e->getMessage()); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | $length = $this->getLength(); |
| 90 | 90 | if ($length) { |
| 91 | 91 | if (substr($uri, 0, 1) !== '/') { |
| 92 | - $uri = '/' . $uri; |
|
| 92 | + $uri = '/'.$uri; |
|
| 93 | 93 | } |
| 94 | 94 | list($parentUri, $newName) = URLUtil::splitPath($uri); |
| 95 | - if(is_null($parentUri)) { |
|
| 95 | + if (is_null($parentUri)) { |
|
| 96 | 96 | $parentUri = ''; |
| 97 | 97 | } |
| 98 | 98 | $req = $this->server->httpRequest; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | // there is still enough space for the remaining chunks |
| 104 | 104 | $length -= $chunkHandler->getCurrentSize(); |
| 105 | 105 | // use target file name for free space check in case of shared files |
| 106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
| 106 | + $uri = rtrim($parentUri, '/').'/'.$info['name']; |
|
| 107 | 107 | } |
| 108 | 108 | $freeSpace = $this->getFreeSpace($uri); |
| 109 | 109 | if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && $length > $freeSpace) { |