@@ -60,7 +60,7 @@ |
||
| 60 | 60 | $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
| 61 | 61 | } |
| 62 | 62 | } else { |
| 63 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
| 63 | + throw new \InvalidArgumentException('The given Capability ('.get_class($c).') does not implement the ICapability interface'); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -36,56 +36,56 @@ |
||
| 36 | 36 | |
| 37 | 37 | class CapabilitiesManager { |
| 38 | 38 | |
| 39 | - /** @var \Closure[] */ |
|
| 40 | - private $capabilities = []; |
|
| 39 | + /** @var \Closure[] */ |
|
| 40 | + private $capabilities = []; |
|
| 41 | 41 | |
| 42 | - /** @var LoggerInterface */ |
|
| 43 | - private $logger; |
|
| 42 | + /** @var LoggerInterface */ |
|
| 43 | + private $logger; |
|
| 44 | 44 | |
| 45 | - public function __construct(LoggerInterface $logger) { |
|
| 46 | - $this->logger = $logger; |
|
| 47 | - } |
|
| 45 | + public function __construct(LoggerInterface $logger) { |
|
| 46 | + $this->logger = $logger; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Get an array of al the capabilities that are registered at this manager |
|
| 51 | - * |
|
| 52 | - * @param bool $public get public capabilities only |
|
| 53 | - * @throws \InvalidArgumentException |
|
| 54 | - * @return array |
|
| 55 | - */ |
|
| 56 | - public function getCapabilities(bool $public = false) : array { |
|
| 57 | - $capabilities = []; |
|
| 58 | - foreach ($this->capabilities as $capability) { |
|
| 59 | - try { |
|
| 60 | - $c = $capability(); |
|
| 61 | - } catch (QueryException $e) { |
|
| 62 | - $this->logger->error('CapabilitiesManager', [ |
|
| 63 | - 'exception' => $e, |
|
| 64 | - ]); |
|
| 65 | - continue; |
|
| 66 | - } |
|
| 49 | + /** |
|
| 50 | + * Get an array of al the capabilities that are registered at this manager |
|
| 51 | + * |
|
| 52 | + * @param bool $public get public capabilities only |
|
| 53 | + * @throws \InvalidArgumentException |
|
| 54 | + * @return array |
|
| 55 | + */ |
|
| 56 | + public function getCapabilities(bool $public = false) : array { |
|
| 57 | + $capabilities = []; |
|
| 58 | + foreach ($this->capabilities as $capability) { |
|
| 59 | + try { |
|
| 60 | + $c = $capability(); |
|
| 61 | + } catch (QueryException $e) { |
|
| 62 | + $this->logger->error('CapabilitiesManager', [ |
|
| 63 | + 'exception' => $e, |
|
| 64 | + ]); |
|
| 65 | + continue; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if ($c instanceof ICapability) { |
|
| 69 | - if (!$public || $c instanceof IPublicCapability) { |
|
| 70 | - $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
| 74 | - } |
|
| 75 | - } |
|
| 68 | + if ($c instanceof ICapability) { |
|
| 69 | + if (!$public || $c instanceof IPublicCapability) { |
|
| 70 | + $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return $capabilities; |
|
| 78 | - } |
|
| 77 | + return $capabilities; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 82 | - * capabilities are actually requested |
|
| 83 | - * |
|
| 84 | - * $callable has to return an instance of OCP\Capabilities\ICapability |
|
| 85 | - * |
|
| 86 | - * @param \Closure $callable |
|
| 87 | - */ |
|
| 88 | - public function registerCapability(\Closure $callable) { |
|
| 89 | - $this->capabilities[] = $callable; |
|
| 90 | - } |
|
| 80 | + /** |
|
| 81 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 82 | + * capabilities are actually requested |
|
| 83 | + * |
|
| 84 | + * $callable has to return an instance of OCP\Capabilities\ICapability |
|
| 85 | + * |
|
| 86 | + * @param \Closure $callable |
|
| 87 | + */ |
|
| 88 | + public function registerCapability(\Closure $callable) { |
|
| 89 | + $this->capabilities[] = $callable; |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | * @return $this |
| 136 | 136 | */ |
| 137 | 137 | public function addHeader($name, $value) { |
| 138 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 138 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 139 | 139 | // to be able to reliably check for security |
| 140 | 140 | // headers |
| 141 | 141 | |
@@ -33,127 +33,127 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Result { |
| 35 | 35 | |
| 36 | - /** @var array */ |
|
| 37 | - protected $data; |
|
| 38 | - |
|
| 39 | - /** @var null|string */ |
|
| 40 | - protected $message; |
|
| 41 | - |
|
| 42 | - /** @var int */ |
|
| 43 | - protected $statusCode; |
|
| 44 | - |
|
| 45 | - /** @var integer */ |
|
| 46 | - protected $items; |
|
| 47 | - |
|
| 48 | - /** @var integer */ |
|
| 49 | - protected $perPage; |
|
| 50 | - |
|
| 51 | - /** @var array */ |
|
| 52 | - private $headers = []; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * create the OCS_Result object |
|
| 56 | - * @param mixed $data the data to return |
|
| 57 | - * @param int $code |
|
| 58 | - * @param null|string $message |
|
| 59 | - * @param array $headers |
|
| 60 | - */ |
|
| 61 | - public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
| 62 | - if ($data === null) { |
|
| 63 | - $this->data = []; |
|
| 64 | - } elseif (!is_array($data)) { |
|
| 65 | - $this->data = [$this->data]; |
|
| 66 | - } else { |
|
| 67 | - $this->data = $data; |
|
| 68 | - } |
|
| 69 | - $this->statusCode = $code; |
|
| 70 | - $this->message = $message; |
|
| 71 | - $this->headers = $headers; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * optionally set the total number of items available |
|
| 76 | - * @param int $items |
|
| 77 | - */ |
|
| 78 | - public function setTotalItems($items) { |
|
| 79 | - $this->items = $items; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * optionally set the the number of items per page |
|
| 84 | - * @param int $items |
|
| 85 | - */ |
|
| 86 | - public function setItemsPerPage($items) { |
|
| 87 | - $this->perPage = $items; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * get the status code |
|
| 92 | - * @return int |
|
| 93 | - */ |
|
| 94 | - public function getStatusCode() { |
|
| 95 | - return $this->statusCode; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * get the meta data for the result |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function getMeta() { |
|
| 103 | - $meta = []; |
|
| 104 | - $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
| 105 | - $meta['statuscode'] = $this->statusCode; |
|
| 106 | - $meta['message'] = $this->message; |
|
| 107 | - if ($this->items !== null) { |
|
| 108 | - $meta['totalitems'] = $this->items; |
|
| 109 | - } |
|
| 110 | - if ($this->perPage !== null) { |
|
| 111 | - $meta['itemsperpage'] = $this->perPage; |
|
| 112 | - } |
|
| 113 | - return $meta; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * get the result data |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - public function getData() { |
|
| 121 | - return $this->data; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * return bool Whether the method succeeded |
|
| 126 | - * @return bool |
|
| 127 | - */ |
|
| 128 | - public function succeeded() { |
|
| 129 | - return ($this->statusCode == 100); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Adds a new header to the response |
|
| 134 | - * @param string $name The name of the HTTP header |
|
| 135 | - * @param string $value The value, null will delete it |
|
| 136 | - * @return $this |
|
| 137 | - */ |
|
| 138 | - public function addHeader($name, $value) { |
|
| 139 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 140 | - // to be able to reliably check for security |
|
| 141 | - // headers |
|
| 142 | - |
|
| 143 | - if (is_null($value)) { |
|
| 144 | - unset($this->headers[$name]); |
|
| 145 | - } else { |
|
| 146 | - $this->headers[$name] = $value; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $this; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns the set headers |
|
| 154 | - * @return array the headers |
|
| 155 | - */ |
|
| 156 | - public function getHeaders() { |
|
| 157 | - return $this->headers; |
|
| 158 | - } |
|
| 36 | + /** @var array */ |
|
| 37 | + protected $data; |
|
| 38 | + |
|
| 39 | + /** @var null|string */ |
|
| 40 | + protected $message; |
|
| 41 | + |
|
| 42 | + /** @var int */ |
|
| 43 | + protected $statusCode; |
|
| 44 | + |
|
| 45 | + /** @var integer */ |
|
| 46 | + protected $items; |
|
| 47 | + |
|
| 48 | + /** @var integer */ |
|
| 49 | + protected $perPage; |
|
| 50 | + |
|
| 51 | + /** @var array */ |
|
| 52 | + private $headers = []; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * create the OCS_Result object |
|
| 56 | + * @param mixed $data the data to return |
|
| 57 | + * @param int $code |
|
| 58 | + * @param null|string $message |
|
| 59 | + * @param array $headers |
|
| 60 | + */ |
|
| 61 | + public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
| 62 | + if ($data === null) { |
|
| 63 | + $this->data = []; |
|
| 64 | + } elseif (!is_array($data)) { |
|
| 65 | + $this->data = [$this->data]; |
|
| 66 | + } else { |
|
| 67 | + $this->data = $data; |
|
| 68 | + } |
|
| 69 | + $this->statusCode = $code; |
|
| 70 | + $this->message = $message; |
|
| 71 | + $this->headers = $headers; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * optionally set the total number of items available |
|
| 76 | + * @param int $items |
|
| 77 | + */ |
|
| 78 | + public function setTotalItems($items) { |
|
| 79 | + $this->items = $items; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * optionally set the the number of items per page |
|
| 84 | + * @param int $items |
|
| 85 | + */ |
|
| 86 | + public function setItemsPerPage($items) { |
|
| 87 | + $this->perPage = $items; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * get the status code |
|
| 92 | + * @return int |
|
| 93 | + */ |
|
| 94 | + public function getStatusCode() { |
|
| 95 | + return $this->statusCode; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * get the meta data for the result |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function getMeta() { |
|
| 103 | + $meta = []; |
|
| 104 | + $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
| 105 | + $meta['statuscode'] = $this->statusCode; |
|
| 106 | + $meta['message'] = $this->message; |
|
| 107 | + if ($this->items !== null) { |
|
| 108 | + $meta['totalitems'] = $this->items; |
|
| 109 | + } |
|
| 110 | + if ($this->perPage !== null) { |
|
| 111 | + $meta['itemsperpage'] = $this->perPage; |
|
| 112 | + } |
|
| 113 | + return $meta; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * get the result data |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + public function getData() { |
|
| 121 | + return $this->data; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * return bool Whether the method succeeded |
|
| 126 | + * @return bool |
|
| 127 | + */ |
|
| 128 | + public function succeeded() { |
|
| 129 | + return ($this->statusCode == 100); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Adds a new header to the response |
|
| 134 | + * @param string $name The name of the HTTP header |
|
| 135 | + * @param string $value The value, null will delete it |
|
| 136 | + * @return $this |
|
| 137 | + */ |
|
| 138 | + public function addHeader($name, $value) { |
|
| 139 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 140 | + // to be able to reliably check for security |
|
| 141 | + // headers |
|
| 142 | + |
|
| 143 | + if (is_null($value)) { |
|
| 144 | + unset($this->headers[$name]); |
|
| 145 | + } else { |
|
| 146 | + $this->headers[$name] = $value; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $this; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns the set headers |
|
| 154 | + * @return array the headers |
|
| 155 | + */ |
|
| 156 | + public function getHeaders() { |
|
| 157 | + return $this->headers; |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * @return int|null |
| 152 | 152 | */ |
| 153 | 153 | public function getId() { |
| 154 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 154 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | public function getEtag() { |
| 182 | 182 | $this->updateEntryfromSubMounts(); |
| 183 | 183 | if (count($this->childEtags) > 0) { |
| 184 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 184 | + $combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags); |
|
| 185 | 185 | return md5($combinedEtag); |
| 186 | 186 | } else { |
| 187 | 187 | return $this->data['etag']; |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
| 378 | 378 | // attach the permissions to propagate etag on permision changes of submounts |
| 379 | 379 | $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
| 380 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 380 | + $this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions; |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
@@ -37,384 +37,384 @@ |
||
| 37 | 37 | use OCP\IUser; |
| 38 | 38 | |
| 39 | 39 | class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { |
| 40 | - /** |
|
| 41 | - * @var array $data |
|
| 42 | - */ |
|
| 43 | - private $data; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string $path |
|
| 47 | - */ |
|
| 48 | - private $path; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var \OC\Files\Storage\Storage $storage |
|
| 52 | - */ |
|
| 53 | - private $storage; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string $internalPath |
|
| 57 | - */ |
|
| 58 | - private $internalPath; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var \OCP\Files\Mount\IMountPoint |
|
| 62 | - */ |
|
| 63 | - private $mount; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var IUser |
|
| 67 | - */ |
|
| 68 | - private $owner; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string[] |
|
| 72 | - */ |
|
| 73 | - private $childEtags = []; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var IMountPoint[] |
|
| 77 | - */ |
|
| 78 | - private $subMounts = []; |
|
| 79 | - |
|
| 80 | - private $subMountsUsed = false; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The size of the file/folder without any sub mount |
|
| 84 | - * |
|
| 85 | - * @var int |
|
| 86 | - */ |
|
| 87 | - private $rawSize = 0; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param string|boolean $path |
|
| 91 | - * @param Storage\Storage $storage |
|
| 92 | - * @param string $internalPath |
|
| 93 | - * @param array|ICacheEntry $data |
|
| 94 | - * @param \OCP\Files\Mount\IMountPoint $mount |
|
| 95 | - * @param \OCP\IUser|null $owner |
|
| 96 | - */ |
|
| 97 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { |
|
| 98 | - $this->path = $path; |
|
| 99 | - $this->storage = $storage; |
|
| 100 | - $this->internalPath = $internalPath; |
|
| 101 | - $this->data = $data; |
|
| 102 | - $this->mount = $mount; |
|
| 103 | - $this->owner = $owner; |
|
| 104 | - $this->rawSize = $this->data['size'] ?? 0; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function offsetSet($offset, $value): void { |
|
| 108 | - $this->data[$offset] = $value; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function offsetExists($offset): bool { |
|
| 112 | - return isset($this->data[$offset]); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function offsetUnset($offset): void { |
|
| 116 | - unset($this->data[$offset]); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return mixed |
|
| 121 | - */ |
|
| 122 | - #[\ReturnTypeWillChange] |
|
| 123 | - public function offsetGet($offset) { |
|
| 124 | - if ($offset === 'type') { |
|
| 125 | - return $this->getType(); |
|
| 126 | - } elseif ($offset === 'etag') { |
|
| 127 | - return $this->getEtag(); |
|
| 128 | - } elseif ($offset === 'size') { |
|
| 129 | - return $this->getSize(); |
|
| 130 | - } elseif ($offset === 'mtime') { |
|
| 131 | - return $this->getMTime(); |
|
| 132 | - } elseif ($offset === 'permissions') { |
|
| 133 | - return $this->getPermissions(); |
|
| 134 | - } elseif (isset($this->data[$offset])) { |
|
| 135 | - return $this->data[$offset]; |
|
| 136 | - } else { |
|
| 137 | - return null; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function getPath() { |
|
| 145 | - return $this->path; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return \OCP\Files\Storage |
|
| 150 | - */ |
|
| 151 | - public function getStorage() { |
|
| 152 | - return $this->storage; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function getInternalPath() { |
|
| 159 | - return $this->internalPath; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get FileInfo ID or null in case of part file |
|
| 164 | - * |
|
| 165 | - * @return int|null |
|
| 166 | - */ |
|
| 167 | - public function getId() { |
|
| 168 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @return string |
|
| 173 | - */ |
|
| 174 | - public function getMimetype() { |
|
| 175 | - return $this->data['mimetype']; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function getMimePart() { |
|
| 182 | - return $this->data['mimepart']; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function getName() { |
|
| 189 | - return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @return string |
|
| 194 | - */ |
|
| 195 | - public function getEtag() { |
|
| 196 | - $this->updateEntryfromSubMounts(); |
|
| 197 | - if (count($this->childEtags) > 0) { |
|
| 198 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 199 | - return md5($combinedEtag); |
|
| 200 | - } else { |
|
| 201 | - return $this->data['etag']; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @return int |
|
| 207 | - */ |
|
| 208 | - public function getSize($includeMounts = true) { |
|
| 209 | - if ($includeMounts) { |
|
| 210 | - $this->updateEntryfromSubMounts(); |
|
| 211 | - return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
| 212 | - } else { |
|
| 213 | - return $this->rawSize; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @return int |
|
| 219 | - */ |
|
| 220 | - public function getMTime() { |
|
| 221 | - $this->updateEntryfromSubMounts(); |
|
| 222 | - return (int) $this->data['mtime']; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @return bool |
|
| 227 | - */ |
|
| 228 | - public function isEncrypted() { |
|
| 229 | - return $this->data['encrypted']; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Return the currently version used for the HMAC in the encryption app |
|
| 234 | - * |
|
| 235 | - * @return int |
|
| 236 | - */ |
|
| 237 | - public function getEncryptedVersion() { |
|
| 238 | - return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @return int |
|
| 243 | - */ |
|
| 244 | - public function getPermissions() { |
|
| 245 | - $perms = (int) $this->data['permissions']; |
|
| 246 | - if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
| 247 | - $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
| 248 | - } |
|
| 249 | - return $perms; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
| 254 | - */ |
|
| 255 | - public function getType() { |
|
| 256 | - if (!isset($this->data['type'])) { |
|
| 257 | - $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
| 258 | - } |
|
| 259 | - return $this->data['type']; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function getData() { |
|
| 263 | - return $this->data; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param int $permissions |
|
| 268 | - * @return bool |
|
| 269 | - */ |
|
| 270 | - protected function checkPermissions($permissions) { |
|
| 271 | - return ($this->getPermissions() & $permissions) === $permissions; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @return bool |
|
| 276 | - */ |
|
| 277 | - public function isReadable() { |
|
| 278 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - public function isUpdateable() { |
|
| 285 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Check whether new files or folders can be created inside this folder |
|
| 290 | - * |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - public function isCreatable() { |
|
| 294 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @return bool |
|
| 299 | - */ |
|
| 300 | - public function isDeletable() { |
|
| 301 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @return bool |
|
| 306 | - */ |
|
| 307 | - public function isShareable() { |
|
| 308 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Check if a file or folder is shared |
|
| 313 | - * |
|
| 314 | - * @return bool |
|
| 315 | - */ |
|
| 316 | - public function isShared() { |
|
| 317 | - $sid = $this->getStorage()->getId(); |
|
| 318 | - if (!is_null($sid)) { |
|
| 319 | - $sid = explode(':', $sid); |
|
| 320 | - return ($sid[0] === 'shared'); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - public function isMounted() { |
|
| 327 | - $storage = $this->getStorage(); |
|
| 328 | - if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 329 | - return false; |
|
| 330 | - } |
|
| 331 | - $sid = $storage->getId(); |
|
| 332 | - if (!is_null($sid)) { |
|
| 333 | - $sid = explode(':', $sid); |
|
| 334 | - return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Get the mountpoint the file belongs to |
|
| 342 | - * |
|
| 343 | - * @return \OCP\Files\Mount\IMountPoint |
|
| 344 | - */ |
|
| 345 | - public function getMountPoint() { |
|
| 346 | - return $this->mount; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Get the owner of the file |
|
| 351 | - * |
|
| 352 | - * @return \OCP\IUser |
|
| 353 | - */ |
|
| 354 | - public function getOwner() { |
|
| 355 | - return $this->owner; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @param IMountPoint[] $mounts |
|
| 360 | - */ |
|
| 361 | - public function setSubMounts(array $mounts) { |
|
| 362 | - $this->subMounts = $mounts; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - private function updateEntryfromSubMounts() { |
|
| 366 | - if ($this->subMountsUsed) { |
|
| 367 | - return; |
|
| 368 | - } |
|
| 369 | - $this->subMountsUsed = true; |
|
| 370 | - foreach ($this->subMounts as $mount) { |
|
| 371 | - $subStorage = $mount->getStorage(); |
|
| 372 | - if ($subStorage) { |
|
| 373 | - $subCache = $subStorage->getCache(''); |
|
| 374 | - $rootEntry = $subCache->get(''); |
|
| 375 | - $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Add a cache entry which is the child of this folder |
|
| 382 | - * |
|
| 383 | - * Sets the size, etag and size to for cross-storage childs |
|
| 384 | - * |
|
| 385 | - * @param array|ICacheEntry $data cache entry for the child |
|
| 386 | - * @param string $entryPath full path of the child entry |
|
| 387 | - */ |
|
| 388 | - public function addSubEntry($data, $entryPath) { |
|
| 389 | - $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
| 390 | - if (isset($data['mtime'])) { |
|
| 391 | - $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
| 392 | - } |
|
| 393 | - if (isset($data['etag'])) { |
|
| 394 | - // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
| 395 | - $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
| 396 | - // attach the permissions to propagate etag on permision changes of submounts |
|
| 397 | - $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
| 398 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * @inheritdoc |
|
| 404 | - */ |
|
| 405 | - public function getChecksum() { |
|
| 406 | - return $this->data['checksum']; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - public function getExtension(): string { |
|
| 410 | - return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - public function getCreationTime(): int { |
|
| 414 | - return (int) $this->data['creation_time']; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - public function getUploadTime(): int { |
|
| 418 | - return (int) $this->data['upload_time']; |
|
| 419 | - } |
|
| 40 | + /** |
|
| 41 | + * @var array $data |
|
| 42 | + */ |
|
| 43 | + private $data; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string $path |
|
| 47 | + */ |
|
| 48 | + private $path; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var \OC\Files\Storage\Storage $storage |
|
| 52 | + */ |
|
| 53 | + private $storage; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var string $internalPath |
|
| 57 | + */ |
|
| 58 | + private $internalPath; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var \OCP\Files\Mount\IMountPoint |
|
| 62 | + */ |
|
| 63 | + private $mount; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var IUser |
|
| 67 | + */ |
|
| 68 | + private $owner; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string[] |
|
| 72 | + */ |
|
| 73 | + private $childEtags = []; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @var IMountPoint[] |
|
| 77 | + */ |
|
| 78 | + private $subMounts = []; |
|
| 79 | + |
|
| 80 | + private $subMountsUsed = false; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The size of the file/folder without any sub mount |
|
| 84 | + * |
|
| 85 | + * @var int |
|
| 86 | + */ |
|
| 87 | + private $rawSize = 0; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param string|boolean $path |
|
| 91 | + * @param Storage\Storage $storage |
|
| 92 | + * @param string $internalPath |
|
| 93 | + * @param array|ICacheEntry $data |
|
| 94 | + * @param \OCP\Files\Mount\IMountPoint $mount |
|
| 95 | + * @param \OCP\IUser|null $owner |
|
| 96 | + */ |
|
| 97 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { |
|
| 98 | + $this->path = $path; |
|
| 99 | + $this->storage = $storage; |
|
| 100 | + $this->internalPath = $internalPath; |
|
| 101 | + $this->data = $data; |
|
| 102 | + $this->mount = $mount; |
|
| 103 | + $this->owner = $owner; |
|
| 104 | + $this->rawSize = $this->data['size'] ?? 0; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function offsetSet($offset, $value): void { |
|
| 108 | + $this->data[$offset] = $value; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function offsetExists($offset): bool { |
|
| 112 | + return isset($this->data[$offset]); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function offsetUnset($offset): void { |
|
| 116 | + unset($this->data[$offset]); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return mixed |
|
| 121 | + */ |
|
| 122 | + #[\ReturnTypeWillChange] |
|
| 123 | + public function offsetGet($offset) { |
|
| 124 | + if ($offset === 'type') { |
|
| 125 | + return $this->getType(); |
|
| 126 | + } elseif ($offset === 'etag') { |
|
| 127 | + return $this->getEtag(); |
|
| 128 | + } elseif ($offset === 'size') { |
|
| 129 | + return $this->getSize(); |
|
| 130 | + } elseif ($offset === 'mtime') { |
|
| 131 | + return $this->getMTime(); |
|
| 132 | + } elseif ($offset === 'permissions') { |
|
| 133 | + return $this->getPermissions(); |
|
| 134 | + } elseif (isset($this->data[$offset])) { |
|
| 135 | + return $this->data[$offset]; |
|
| 136 | + } else { |
|
| 137 | + return null; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function getPath() { |
|
| 145 | + return $this->path; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return \OCP\Files\Storage |
|
| 150 | + */ |
|
| 151 | + public function getStorage() { |
|
| 152 | + return $this->storage; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function getInternalPath() { |
|
| 159 | + return $this->internalPath; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get FileInfo ID or null in case of part file |
|
| 164 | + * |
|
| 165 | + * @return int|null |
|
| 166 | + */ |
|
| 167 | + public function getId() { |
|
| 168 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @return string |
|
| 173 | + */ |
|
| 174 | + public function getMimetype() { |
|
| 175 | + return $this->data['mimetype']; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function getMimePart() { |
|
| 182 | + return $this->data['mimepart']; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function getName() { |
|
| 189 | + return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @return string |
|
| 194 | + */ |
|
| 195 | + public function getEtag() { |
|
| 196 | + $this->updateEntryfromSubMounts(); |
|
| 197 | + if (count($this->childEtags) > 0) { |
|
| 198 | + $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
| 199 | + return md5($combinedEtag); |
|
| 200 | + } else { |
|
| 201 | + return $this->data['etag']; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @return int |
|
| 207 | + */ |
|
| 208 | + public function getSize($includeMounts = true) { |
|
| 209 | + if ($includeMounts) { |
|
| 210 | + $this->updateEntryfromSubMounts(); |
|
| 211 | + return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
| 212 | + } else { |
|
| 213 | + return $this->rawSize; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @return int |
|
| 219 | + */ |
|
| 220 | + public function getMTime() { |
|
| 221 | + $this->updateEntryfromSubMounts(); |
|
| 222 | + return (int) $this->data['mtime']; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @return bool |
|
| 227 | + */ |
|
| 228 | + public function isEncrypted() { |
|
| 229 | + return $this->data['encrypted']; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Return the currently version used for the HMAC in the encryption app |
|
| 234 | + * |
|
| 235 | + * @return int |
|
| 236 | + */ |
|
| 237 | + public function getEncryptedVersion() { |
|
| 238 | + return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @return int |
|
| 243 | + */ |
|
| 244 | + public function getPermissions() { |
|
| 245 | + $perms = (int) $this->data['permissions']; |
|
| 246 | + if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
| 247 | + $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
| 248 | + } |
|
| 249 | + return $perms; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
| 254 | + */ |
|
| 255 | + public function getType() { |
|
| 256 | + if (!isset($this->data['type'])) { |
|
| 257 | + $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
| 258 | + } |
|
| 259 | + return $this->data['type']; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function getData() { |
|
| 263 | + return $this->data; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param int $permissions |
|
| 268 | + * @return bool |
|
| 269 | + */ |
|
| 270 | + protected function checkPermissions($permissions) { |
|
| 271 | + return ($this->getPermissions() & $permissions) === $permissions; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @return bool |
|
| 276 | + */ |
|
| 277 | + public function isReadable() { |
|
| 278 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + public function isUpdateable() { |
|
| 285 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Check whether new files or folders can be created inside this folder |
|
| 290 | + * |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + public function isCreatable() { |
|
| 294 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @return bool |
|
| 299 | + */ |
|
| 300 | + public function isDeletable() { |
|
| 301 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @return bool |
|
| 306 | + */ |
|
| 307 | + public function isShareable() { |
|
| 308 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Check if a file or folder is shared |
|
| 313 | + * |
|
| 314 | + * @return bool |
|
| 315 | + */ |
|
| 316 | + public function isShared() { |
|
| 317 | + $sid = $this->getStorage()->getId(); |
|
| 318 | + if (!is_null($sid)) { |
|
| 319 | + $sid = explode(':', $sid); |
|
| 320 | + return ($sid[0] === 'shared'); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + public function isMounted() { |
|
| 327 | + $storage = $this->getStorage(); |
|
| 328 | + if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
| 329 | + return false; |
|
| 330 | + } |
|
| 331 | + $sid = $storage->getId(); |
|
| 332 | + if (!is_null($sid)) { |
|
| 333 | + $sid = explode(':', $sid); |
|
| 334 | + return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Get the mountpoint the file belongs to |
|
| 342 | + * |
|
| 343 | + * @return \OCP\Files\Mount\IMountPoint |
|
| 344 | + */ |
|
| 345 | + public function getMountPoint() { |
|
| 346 | + return $this->mount; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Get the owner of the file |
|
| 351 | + * |
|
| 352 | + * @return \OCP\IUser |
|
| 353 | + */ |
|
| 354 | + public function getOwner() { |
|
| 355 | + return $this->owner; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @param IMountPoint[] $mounts |
|
| 360 | + */ |
|
| 361 | + public function setSubMounts(array $mounts) { |
|
| 362 | + $this->subMounts = $mounts; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + private function updateEntryfromSubMounts() { |
|
| 366 | + if ($this->subMountsUsed) { |
|
| 367 | + return; |
|
| 368 | + } |
|
| 369 | + $this->subMountsUsed = true; |
|
| 370 | + foreach ($this->subMounts as $mount) { |
|
| 371 | + $subStorage = $mount->getStorage(); |
|
| 372 | + if ($subStorage) { |
|
| 373 | + $subCache = $subStorage->getCache(''); |
|
| 374 | + $rootEntry = $subCache->get(''); |
|
| 375 | + $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Add a cache entry which is the child of this folder |
|
| 382 | + * |
|
| 383 | + * Sets the size, etag and size to for cross-storage childs |
|
| 384 | + * |
|
| 385 | + * @param array|ICacheEntry $data cache entry for the child |
|
| 386 | + * @param string $entryPath full path of the child entry |
|
| 387 | + */ |
|
| 388 | + public function addSubEntry($data, $entryPath) { |
|
| 389 | + $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
| 390 | + if (isset($data['mtime'])) { |
|
| 391 | + $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
| 392 | + } |
|
| 393 | + if (isset($data['etag'])) { |
|
| 394 | + // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
| 395 | + $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
| 396 | + // attach the permissions to propagate etag on permision changes of submounts |
|
| 397 | + $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
| 398 | + $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * @inheritdoc |
|
| 404 | + */ |
|
| 405 | + public function getChecksum() { |
|
| 406 | + return $this->data['checksum']; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + public function getExtension(): string { |
|
| 410 | + return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + public function getCreationTime(): int { |
|
| 414 | + return (int) $this->data['creation_time']; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + public function getUploadTime(): int { |
|
| 418 | + return (int) $this->data['upload_time']; |
|
| 419 | + } |
|
| 420 | 420 | } |
@@ -33,53 +33,53 @@ |
||
| 33 | 33 | namespace OC\Files\Storage; |
| 34 | 34 | |
| 35 | 35 | class CommonTest extends \OC\Files\Storage\Common { |
| 36 | - /** |
|
| 37 | - * underlying local storage used for missing functions |
|
| 38 | - * @var \OC\Files\Storage\Local |
|
| 39 | - */ |
|
| 40 | - private $storage; |
|
| 36 | + /** |
|
| 37 | + * underlying local storage used for missing functions |
|
| 38 | + * @var \OC\Files\Storage\Local |
|
| 39 | + */ |
|
| 40 | + private $storage; |
|
| 41 | 41 | |
| 42 | - public function __construct($params) { |
|
| 43 | - $this->storage = new \OC\Files\Storage\Local($params); |
|
| 44 | - } |
|
| 42 | + public function __construct($params) { |
|
| 43 | + $this->storage = new \OC\Files\Storage\Local($params); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function getId() { |
|
| 47 | - return 'test::'.$this->storage->getId(); |
|
| 48 | - } |
|
| 49 | - public function mkdir($path) { |
|
| 50 | - return $this->storage->mkdir($path); |
|
| 51 | - } |
|
| 52 | - public function rmdir($path) { |
|
| 53 | - return $this->storage->rmdir($path); |
|
| 54 | - } |
|
| 55 | - public function opendir($path) { |
|
| 56 | - return $this->storage->opendir($path); |
|
| 57 | - } |
|
| 58 | - public function stat($path) { |
|
| 59 | - return $this->storage->stat($path); |
|
| 60 | - } |
|
| 61 | - public function filetype($path) { |
|
| 62 | - return @$this->storage->filetype($path); |
|
| 63 | - } |
|
| 64 | - public function isReadable($path) { |
|
| 65 | - return $this->storage->isReadable($path); |
|
| 66 | - } |
|
| 67 | - public function isUpdatable($path) { |
|
| 68 | - return $this->storage->isUpdatable($path); |
|
| 69 | - } |
|
| 70 | - public function file_exists($path) { |
|
| 71 | - return $this->storage->file_exists($path); |
|
| 72 | - } |
|
| 73 | - public function unlink($path) { |
|
| 74 | - return $this->storage->unlink($path); |
|
| 75 | - } |
|
| 76 | - public function fopen($path, $mode) { |
|
| 77 | - return $this->storage->fopen($path, $mode); |
|
| 78 | - } |
|
| 79 | - public function free_space($path) { |
|
| 80 | - return $this->storage->free_space($path); |
|
| 81 | - } |
|
| 82 | - public function touch($path, $mtime = null) { |
|
| 83 | - return $this->storage->touch($path, $mtime); |
|
| 84 | - } |
|
| 46 | + public function getId() { |
|
| 47 | + return 'test::'.$this->storage->getId(); |
|
| 48 | + } |
|
| 49 | + public function mkdir($path) { |
|
| 50 | + return $this->storage->mkdir($path); |
|
| 51 | + } |
|
| 52 | + public function rmdir($path) { |
|
| 53 | + return $this->storage->rmdir($path); |
|
| 54 | + } |
|
| 55 | + public function opendir($path) { |
|
| 56 | + return $this->storage->opendir($path); |
|
| 57 | + } |
|
| 58 | + public function stat($path) { |
|
| 59 | + return $this->storage->stat($path); |
|
| 60 | + } |
|
| 61 | + public function filetype($path) { |
|
| 62 | + return @$this->storage->filetype($path); |
|
| 63 | + } |
|
| 64 | + public function isReadable($path) { |
|
| 65 | + return $this->storage->isReadable($path); |
|
| 66 | + } |
|
| 67 | + public function isUpdatable($path) { |
|
| 68 | + return $this->storage->isUpdatable($path); |
|
| 69 | + } |
|
| 70 | + public function file_exists($path) { |
|
| 71 | + return $this->storage->file_exists($path); |
|
| 72 | + } |
|
| 73 | + public function unlink($path) { |
|
| 74 | + return $this->storage->unlink($path); |
|
| 75 | + } |
|
| 76 | + public function fopen($path, $mode) { |
|
| 77 | + return $this->storage->fopen($path, $mode); |
|
| 78 | + } |
|
| 79 | + public function free_space($path) { |
|
| 80 | + return $this->storage->free_space($path); |
|
| 81 | + } |
|
| 82 | + public function touch($path, $mtime = null) { |
|
| 83 | + return $this->storage->touch($path, $mtime); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -29,20 +29,20 @@ |
||
| 29 | 29 | * local storage backend in temporary folder for testing purpose |
| 30 | 30 | */ |
| 31 | 31 | class Temporary extends Local { |
| 32 | - public function __construct($arguments = null) { |
|
| 33 | - parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
| 34 | - } |
|
| 32 | + public function __construct($arguments = null) { |
|
| 33 | + parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function cleanUp() { |
|
| 37 | - \OC_Helper::rmdirr($this->datadir); |
|
| 38 | - } |
|
| 36 | + public function cleanUp() { |
|
| 37 | + \OC_Helper::rmdirr($this->datadir); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function __destruct() { |
|
| 41 | - parent::__destruct(); |
|
| 42 | - $this->cleanUp(); |
|
| 43 | - } |
|
| 40 | + public function __destruct() { |
|
| 41 | + parent::__destruct(); |
|
| 42 | + $this->cleanUp(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function getDataDir() { |
|
| 46 | - return $this->datadir; |
|
| 47 | - } |
|
| 45 | + public function getDataDir() { |
|
| 46 | + return $this->datadir; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | public function __construct($arguments) { |
| 51 | 51 | $this->user = $arguments['user']; |
| 52 | 52 | $datadir = $this->user->getHome(); |
| 53 | - $this->id = 'home::' . $this->user->getUID(); |
|
| 53 | + $this->id = 'home::'.$this->user->getUID(); |
|
| 54 | 54 | |
| 55 | 55 | parent::__construct(['datadir' => $datadir]); |
| 56 | 56 | } |
@@ -33,80 +33,80 @@ |
||
| 33 | 33 | * Specialized version of Local storage for home directory usage |
| 34 | 34 | */ |
| 35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $id; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $id; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var \OC\User\User $user |
|
| 43 | - */ |
|
| 44 | - protected $user; |
|
| 41 | + /** |
|
| 42 | + * @var \OC\User\User $user |
|
| 43 | + */ |
|
| 44 | + protected $user; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Construct a Home storage instance |
|
| 48 | - * |
|
| 49 | - * @param array $arguments array with "user" containing the |
|
| 50 | - * storage owner |
|
| 51 | - */ |
|
| 52 | - public function __construct($arguments) { |
|
| 53 | - $this->user = $arguments['user']; |
|
| 54 | - $datadir = $this->user->getHome(); |
|
| 55 | - $this->id = 'home::' . $this->user->getUID(); |
|
| 46 | + /** |
|
| 47 | + * Construct a Home storage instance |
|
| 48 | + * |
|
| 49 | + * @param array $arguments array with "user" containing the |
|
| 50 | + * storage owner |
|
| 51 | + */ |
|
| 52 | + public function __construct($arguments) { |
|
| 53 | + $this->user = $arguments['user']; |
|
| 54 | + $datadir = $this->user->getHome(); |
|
| 55 | + $this->id = 'home::' . $this->user->getUID(); |
|
| 56 | 56 | |
| 57 | - parent::__construct(['datadir' => $datadir]); |
|
| 58 | - } |
|
| 57 | + parent::__construct(['datadir' => $datadir]); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function getId() { |
|
| 61 | - return $this->id; |
|
| 62 | - } |
|
| 60 | + public function getId() { |
|
| 61 | + return $this->id; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return \OC\Files\Cache\HomeCache |
|
| 66 | - */ |
|
| 67 | - public function getCache($path = '', $storage = null) { |
|
| 68 | - if (!$storage) { |
|
| 69 | - $storage = $this; |
|
| 70 | - } |
|
| 71 | - if (!isset($this->cache)) { |
|
| 72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
| 73 | - } |
|
| 74 | - return $this->cache; |
|
| 75 | - } |
|
| 64 | + /** |
|
| 65 | + * @return \OC\Files\Cache\HomeCache |
|
| 66 | + */ |
|
| 67 | + public function getCache($path = '', $storage = null) { |
|
| 68 | + if (!$storage) { |
|
| 69 | + $storage = $this; |
|
| 70 | + } |
|
| 71 | + if (!isset($this->cache)) { |
|
| 72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
| 73 | + } |
|
| 74 | + return $this->cache; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * get a propagator instance for the cache |
|
| 79 | - * |
|
| 80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
| 81 | - * @return \OC\Files\Cache\Propagator |
|
| 82 | - */ |
|
| 83 | - public function getPropagator($storage = null) { |
|
| 84 | - if (!$storage) { |
|
| 85 | - $storage = $this; |
|
| 86 | - } |
|
| 87 | - if (!isset($this->propagator)) { |
|
| 88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
| 89 | - } |
|
| 90 | - return $this->propagator; |
|
| 91 | - } |
|
| 77 | + /** |
|
| 78 | + * get a propagator instance for the cache |
|
| 79 | + * |
|
| 80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
| 81 | + * @return \OC\Files\Cache\Propagator |
|
| 82 | + */ |
|
| 83 | + public function getPropagator($storage = null) { |
|
| 84 | + if (!$storage) { |
|
| 85 | + $storage = $this; |
|
| 86 | + } |
|
| 87 | + if (!isset($this->propagator)) { |
|
| 88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
| 89 | + } |
|
| 90 | + return $this->propagator; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Returns the owner of this home storage |
|
| 96 | - * |
|
| 97 | - * @return \OC\User\User owner of this home storage |
|
| 98 | - */ |
|
| 99 | - public function getUser() { |
|
| 100 | - return $this->user; |
|
| 101 | - } |
|
| 94 | + /** |
|
| 95 | + * Returns the owner of this home storage |
|
| 96 | + * |
|
| 97 | + * @return \OC\User\User owner of this home storage |
|
| 98 | + */ |
|
| 99 | + public function getUser() { |
|
| 100 | + return $this->user; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * get the owner of a path |
|
| 105 | - * |
|
| 106 | - * @param string $path The path to get the owner |
|
| 107 | - * @return string uid or false |
|
| 108 | - */ |
|
| 109 | - public function getOwner($path) { |
|
| 110 | - return $this->user->getUID(); |
|
| 111 | - } |
|
| 103 | + /** |
|
| 104 | + * get the owner of a path |
|
| 105 | + * |
|
| 106 | + * @param string $path The path to get the owner |
|
| 107 | + * @return string uid or false |
|
| 108 | + */ |
|
| 109 | + public function getOwner($path) { |
|
| 110 | + return $this->user->getUID(); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | public function getDirectoryListing() { |
| 50 | 50 | $listing = $this->folder->getDirectoryListing(); |
| 51 | 51 | |
| 52 | - $fileListing = array_map(function (Node $file) { |
|
| 52 | + $fileListing = array_map(function(Node $file) { |
|
| 53 | 53 | if ($file instanceof File) { |
| 54 | 54 | return new SimpleFile($file); |
| 55 | 55 | } |
@@ -32,62 +32,62 @@ |
||
| 32 | 32 | |
| 33 | 33 | class SimpleFolder implements ISimpleFolder { |
| 34 | 34 | |
| 35 | - /** @var Folder */ |
|
| 36 | - private $folder; |
|
| 35 | + /** @var Folder */ |
|
| 36 | + private $folder; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Folder constructor. |
|
| 40 | - * |
|
| 41 | - * @param Folder $folder |
|
| 42 | - */ |
|
| 43 | - public function __construct(Folder $folder) { |
|
| 44 | - $this->folder = $folder; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * Folder constructor. |
|
| 40 | + * |
|
| 41 | + * @param Folder $folder |
|
| 42 | + */ |
|
| 43 | + public function __construct(Folder $folder) { |
|
| 44 | + $this->folder = $folder; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function getName() { |
|
| 48 | - return $this->folder->getName(); |
|
| 49 | - } |
|
| 47 | + public function getName() { |
|
| 48 | + return $this->folder->getName(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function getDirectoryListing() { |
|
| 52 | - $listing = $this->folder->getDirectoryListing(); |
|
| 51 | + public function getDirectoryListing() { |
|
| 52 | + $listing = $this->folder->getDirectoryListing(); |
|
| 53 | 53 | |
| 54 | - $fileListing = array_map(function (Node $file) { |
|
| 55 | - if ($file instanceof File) { |
|
| 56 | - return new SimpleFile($file); |
|
| 57 | - } |
|
| 58 | - return null; |
|
| 59 | - }, $listing); |
|
| 54 | + $fileListing = array_map(function (Node $file) { |
|
| 55 | + if ($file instanceof File) { |
|
| 56 | + return new SimpleFile($file); |
|
| 57 | + } |
|
| 58 | + return null; |
|
| 59 | + }, $listing); |
|
| 60 | 60 | |
| 61 | - $fileListing = array_filter($fileListing); |
|
| 61 | + $fileListing = array_filter($fileListing); |
|
| 62 | 62 | |
| 63 | - return array_values($fileListing); |
|
| 64 | - } |
|
| 63 | + return array_values($fileListing); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function delete() { |
|
| 67 | - $this->folder->delete(); |
|
| 68 | - } |
|
| 66 | + public function delete() { |
|
| 67 | + $this->folder->delete(); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function fileExists($name) { |
|
| 71 | - return $this->folder->nodeExists($name); |
|
| 72 | - } |
|
| 70 | + public function fileExists($name) { |
|
| 71 | + return $this->folder->nodeExists($name); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function getFile($name) { |
|
| 75 | - $file = $this->folder->get($name); |
|
| 74 | + public function getFile($name) { |
|
| 75 | + $file = $this->folder->get($name); |
|
| 76 | 76 | |
| 77 | - if (!($file instanceof File)) { |
|
| 78 | - throw new NotFoundException(); |
|
| 79 | - } |
|
| 77 | + if (!($file instanceof File)) { |
|
| 78 | + throw new NotFoundException(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return new SimpleFile($file); |
|
| 82 | - } |
|
| 81 | + return new SimpleFile($file); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function newFile($name, $content = null) { |
|
| 85 | - if ($content === null) { |
|
| 86 | - // delay creating the file until it's written to |
|
| 87 | - return new NewSimpleFile($this->folder, $name); |
|
| 88 | - } else { |
|
| 89 | - $file = $this->folder->newFile($name, $content); |
|
| 90 | - return new SimpleFile($file); |
|
| 91 | - } |
|
| 92 | - } |
|
| 84 | + public function newFile($name, $content = null) { |
|
| 85 | + if ($content === null) { |
|
| 86 | + // delay creating the file until it's written to |
|
| 87 | + return new NewSimpleFile($this->folder, $name); |
|
| 88 | + } else { |
|
| 89 | + $file = $this->folder->newFile($name, $content); |
|
| 90 | + return new SimpleFile($file); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -28,40 +28,40 @@ |
||
| 28 | 28 | |
| 29 | 29 | class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The home user storage requires a user object to create a unique storage id |
|
| 33 | - * @param array $params |
|
| 34 | - */ |
|
| 35 | - public function __construct($params) { |
|
| 36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 37 | - throw new \Exception('missing user object in parameters'); |
|
| 38 | - } |
|
| 39 | - $this->user = $params['user']; |
|
| 40 | - parent::__construct($params); |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * The home user storage requires a user object to create a unique storage id |
|
| 33 | + * @param array $params |
|
| 34 | + */ |
|
| 35 | + public function __construct($params) { |
|
| 36 | + if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 37 | + throw new \Exception('missing user object in parameters'); |
|
| 38 | + } |
|
| 39 | + $this->user = $params['user']; |
|
| 40 | + parent::__construct($params); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getId() { |
|
| 44 | - return 'object::user:' . $this->user->getUID(); |
|
| 45 | - } |
|
| 43 | + public function getId() { |
|
| 44 | + return 'object::user:' . $this->user->getUID(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * get the owner of a path |
|
| 49 | - * |
|
| 50 | - * @param string $path The path to get the owner |
|
| 51 | - * @return false|string uid |
|
| 52 | - */ |
|
| 53 | - public function getOwner($path) { |
|
| 54 | - if (is_object($this->user)) { |
|
| 55 | - return $this->user->getUID(); |
|
| 56 | - } |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 47 | + /** |
|
| 48 | + * get the owner of a path |
|
| 49 | + * |
|
| 50 | + * @param string $path The path to get the owner |
|
| 51 | + * @return false|string uid |
|
| 52 | + */ |
|
| 53 | + public function getOwner($path) { |
|
| 54 | + if (is_object($this->user)) { |
|
| 55 | + return $this->user->getUID(); |
|
| 56 | + } |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string $path, optional |
|
| 62 | - * @return \OC\User\User |
|
| 63 | - */ |
|
| 64 | - public function getUser($path = null) { |
|
| 65 | - return $this->user; |
|
| 66 | - } |
|
| 60 | + /** |
|
| 61 | + * @param string $path, optional |
|
| 62 | + * @return \OC\User\User |
|
| 63 | + */ |
|
| 64 | + public function getUser($path = null) { |
|
| 65 | + return $this->user; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param array $params |
| 34 | 34 | */ |
| 35 | 35 | public function __construct($params) { |
| 36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 36 | + if (!isset($params['user']) || !$params['user'] instanceof User) { |
|
| 37 | 37 | throw new \Exception('missing user object in parameters'); |
| 38 | 38 | } |
| 39 | 39 | $this->user = $params['user']; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function getId() { |
| 44 | - return 'object::user:' . $this->user->getUID(); |
|
| 44 | + return 'object::user:'.$this->user->getUID(); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -24,17 +24,17 @@ |
||
| 24 | 24 | namespace OC\DB; |
| 25 | 25 | |
| 26 | 26 | class MigrationException extends \Exception { |
| 27 | - private $table; |
|
| 27 | + private $table; |
|
| 28 | 28 | |
| 29 | - public function __construct($table, $message) { |
|
| 30 | - $this->table = $table; |
|
| 31 | - parent::__construct($message); |
|
| 32 | - } |
|
| 29 | + public function __construct($table, $message) { |
|
| 30 | + $this->table = $table; |
|
| 31 | + parent::__construct($message); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getTable() { |
|
| 38 | - return $this->table; |
|
| 39 | - } |
|
| 34 | + /** |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getTable() { |
|
| 38 | + return $this->table; |
|
| 39 | + } |
|
| 40 | 40 | } |