@@ -33,27 +33,27 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class CoreCapabilities implements ICapability { |
| 35 | 35 | |
| 36 | - /** @var IConfig */ |
|
| 37 | - private $config; |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + private $config; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param IConfig $config |
|
| 41 | - */ |
|
| 42 | - public function __construct(IConfig $config) { |
|
| 43 | - $this->config = $config; |
|
| 44 | - } |
|
| 39 | + /** |
|
| 40 | + * @param IConfig $config |
|
| 41 | + */ |
|
| 42 | + public function __construct(IConfig $config) { |
|
| 43 | + $this->config = $config; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Return this classes capabilities |
|
| 48 | - * |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function getCapabilities() { |
|
| 52 | - return [ |
|
| 53 | - 'core' => [ |
|
| 54 | - 'pollinterval' => $this->config->getSystemValue('pollinterval', 60), |
|
| 55 | - 'webdav-root' => $this->config->getSystemValue('webdav-root', 'remote.php/webdav'), |
|
| 56 | - ] |
|
| 57 | - ]; |
|
| 58 | - } |
|
| 46 | + /** |
|
| 47 | + * Return this classes capabilities |
|
| 48 | + * |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function getCapabilities() { |
|
| 52 | + return [ |
|
| 53 | + 'core' => [ |
|
| 54 | + 'pollinterval' => $this->config->getSystemValue('pollinterval', 60), |
|
| 55 | + 'webdav-root' => $this->config->getSystemValue('webdav-root', 'remote.php/webdav'), |
|
| 56 | + ] |
|
| 57 | + ]; |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -27,147 +27,147 @@ |
||
| 27 | 27 | use OCP\Files\NotFoundException; |
| 28 | 28 | |
| 29 | 29 | class NonExistingFolder extends Folder { |
| 30 | - /** |
|
| 31 | - * @param string $newPath |
|
| 32 | - * @throws \OCP\Files\NotFoundException |
|
| 33 | - */ |
|
| 34 | - public function rename($newPath) { |
|
| 35 | - throw new NotFoundException(); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function delete() { |
|
| 39 | - throw new NotFoundException(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function copy($newPath) { |
|
| 43 | - throw new NotFoundException(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function touch($mtime = null) { |
|
| 47 | - throw new NotFoundException(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function getId() { |
|
| 51 | - if ($this->fileInfo) { |
|
| 52 | - return parent::getId(); |
|
| 53 | - } else { |
|
| 54 | - throw new NotFoundException(); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function stat() { |
|
| 59 | - throw new NotFoundException(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function getMTime() { |
|
| 63 | - if ($this->fileInfo) { |
|
| 64 | - return parent::getMTime(); |
|
| 65 | - } else { |
|
| 66 | - throw new NotFoundException(); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function getSize() { |
|
| 71 | - if ($this->fileInfo) { |
|
| 72 | - return parent::getSize(); |
|
| 73 | - } else { |
|
| 74 | - throw new NotFoundException(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function getEtag() { |
|
| 79 | - if ($this->fileInfo) { |
|
| 80 | - return parent::getEtag(); |
|
| 81 | - } else { |
|
| 82 | - throw new NotFoundException(); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function getPermissions() { |
|
| 87 | - if ($this->fileInfo) { |
|
| 88 | - return parent::getPermissions(); |
|
| 89 | - } else { |
|
| 90 | - throw new NotFoundException(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function isReadable() { |
|
| 95 | - if ($this->fileInfo) { |
|
| 96 | - return parent::isReadable(); |
|
| 97 | - } else { |
|
| 98 | - throw new NotFoundException(); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function isUpdateable() { |
|
| 103 | - if ($this->fileInfo) { |
|
| 104 | - return parent::isUpdateable(); |
|
| 105 | - } else { |
|
| 106 | - throw new NotFoundException(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function isDeletable() { |
|
| 111 | - if ($this->fileInfo) { |
|
| 112 | - return parent::isDeletable(); |
|
| 113 | - } else { |
|
| 114 | - throw new NotFoundException(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - public function isShareable() { |
|
| 119 | - if ($this->fileInfo) { |
|
| 120 | - return parent::isShareable(); |
|
| 121 | - } else { |
|
| 122 | - throw new NotFoundException(); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function get($path) { |
|
| 127 | - throw new NotFoundException(); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function getDirectoryListing() { |
|
| 131 | - throw new NotFoundException(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function nodeExists($path) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function newFolder($path) { |
|
| 139 | - throw new NotFoundException(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function newFile($path) { |
|
| 143 | - throw new NotFoundException(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - public function search($pattern) { |
|
| 147 | - throw new NotFoundException(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function searchByMime($mime) { |
|
| 151 | - throw new NotFoundException(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function searchByTag($tag, $userId) { |
|
| 155 | - throw new NotFoundException(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function getById($id) { |
|
| 159 | - throw new NotFoundException(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - public function getFreeSpace() { |
|
| 163 | - throw new NotFoundException(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function isCreatable() { |
|
| 167 | - if ($this->fileInfo) { |
|
| 168 | - return parent::isCreatable(); |
|
| 169 | - } else { |
|
| 170 | - throw new NotFoundException(); |
|
| 171 | - } |
|
| 172 | - } |
|
| 30 | + /** |
|
| 31 | + * @param string $newPath |
|
| 32 | + * @throws \OCP\Files\NotFoundException |
|
| 33 | + */ |
|
| 34 | + public function rename($newPath) { |
|
| 35 | + throw new NotFoundException(); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function delete() { |
|
| 39 | + throw new NotFoundException(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function copy($newPath) { |
|
| 43 | + throw new NotFoundException(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function touch($mtime = null) { |
|
| 47 | + throw new NotFoundException(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function getId() { |
|
| 51 | + if ($this->fileInfo) { |
|
| 52 | + return parent::getId(); |
|
| 53 | + } else { |
|
| 54 | + throw new NotFoundException(); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function stat() { |
|
| 59 | + throw new NotFoundException(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function getMTime() { |
|
| 63 | + if ($this->fileInfo) { |
|
| 64 | + return parent::getMTime(); |
|
| 65 | + } else { |
|
| 66 | + throw new NotFoundException(); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function getSize() { |
|
| 71 | + if ($this->fileInfo) { |
|
| 72 | + return parent::getSize(); |
|
| 73 | + } else { |
|
| 74 | + throw new NotFoundException(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function getEtag() { |
|
| 79 | + if ($this->fileInfo) { |
|
| 80 | + return parent::getEtag(); |
|
| 81 | + } else { |
|
| 82 | + throw new NotFoundException(); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function getPermissions() { |
|
| 87 | + if ($this->fileInfo) { |
|
| 88 | + return parent::getPermissions(); |
|
| 89 | + } else { |
|
| 90 | + throw new NotFoundException(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function isReadable() { |
|
| 95 | + if ($this->fileInfo) { |
|
| 96 | + return parent::isReadable(); |
|
| 97 | + } else { |
|
| 98 | + throw new NotFoundException(); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function isUpdateable() { |
|
| 103 | + if ($this->fileInfo) { |
|
| 104 | + return parent::isUpdateable(); |
|
| 105 | + } else { |
|
| 106 | + throw new NotFoundException(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function isDeletable() { |
|
| 111 | + if ($this->fileInfo) { |
|
| 112 | + return parent::isDeletable(); |
|
| 113 | + } else { |
|
| 114 | + throw new NotFoundException(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + public function isShareable() { |
|
| 119 | + if ($this->fileInfo) { |
|
| 120 | + return parent::isShareable(); |
|
| 121 | + } else { |
|
| 122 | + throw new NotFoundException(); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function get($path) { |
|
| 127 | + throw new NotFoundException(); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function getDirectoryListing() { |
|
| 131 | + throw new NotFoundException(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function nodeExists($path) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function newFolder($path) { |
|
| 139 | + throw new NotFoundException(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function newFile($path) { |
|
| 143 | + throw new NotFoundException(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + public function search($pattern) { |
|
| 147 | + throw new NotFoundException(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function searchByMime($mime) { |
|
| 151 | + throw new NotFoundException(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function searchByTag($tag, $userId) { |
|
| 155 | + throw new NotFoundException(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function getById($id) { |
|
| 159 | + throw new NotFoundException(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + public function getFreeSpace() { |
|
| 163 | + throw new NotFoundException(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function isCreatable() { |
|
| 167 | + if ($this->fileInfo) { |
|
| 168 | + return parent::isCreatable(); |
|
| 169 | + } else { |
|
| 170 | + throw new NotFoundException(); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | 173 | } |
@@ -28,138 +28,138 @@ |
||
| 28 | 28 | use OCP\Util; |
| 29 | 29 | |
| 30 | 30 | class HookConnector { |
| 31 | - /** |
|
| 32 | - * @var Root |
|
| 33 | - */ |
|
| 34 | - private $root; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var View |
|
| 38 | - */ |
|
| 39 | - private $view; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var FileInfo[] |
|
| 43 | - */ |
|
| 44 | - private $deleteMetaCache = []; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * HookConnector constructor. |
|
| 48 | - * |
|
| 49 | - * @param Root $root |
|
| 50 | - * @param View $view |
|
| 51 | - */ |
|
| 52 | - public function __construct(Root $root, View $view) { |
|
| 53 | - $this->root = $root; |
|
| 54 | - $this->view = $view; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function viewToNode() { |
|
| 58 | - Util::connectHook('OC_Filesystem', 'write', $this, 'write'); |
|
| 59 | - Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite'); |
|
| 60 | - |
|
| 61 | - Util::connectHook('OC_Filesystem', 'create', $this, 'create'); |
|
| 62 | - Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate'); |
|
| 63 | - |
|
| 64 | - Util::connectHook('OC_Filesystem', 'delete', $this, 'delete'); |
|
| 65 | - Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete'); |
|
| 66 | - |
|
| 67 | - Util::connectHook('OC_Filesystem', 'rename', $this, 'rename'); |
|
| 68 | - Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename'); |
|
| 69 | - |
|
| 70 | - Util::connectHook('OC_Filesystem', 'copy', $this, 'copy'); |
|
| 71 | - Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy'); |
|
| 72 | - |
|
| 73 | - Util::connectHook('OC_Filesystem', 'touch', $this, 'touch'); |
|
| 74 | - Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch'); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function write($arguments) { |
|
| 78 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 79 | - $this->root->emit('\OC\Files', 'preWrite', [$node]); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function postWrite($arguments) { |
|
| 83 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 84 | - $this->root->emit('\OC\Files', 'postWrite', [$node]); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function create($arguments) { |
|
| 88 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 89 | - $this->root->emit('\OC\Files', 'preCreate', [$node]); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function postCreate($arguments) { |
|
| 93 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 94 | - $this->root->emit('\OC\Files', 'postCreate', [$node]); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function delete($arguments) { |
|
| 98 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 99 | - $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); |
|
| 100 | - $this->root->emit('\OC\Files', 'preDelete', [$node]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function postDelete($arguments) { |
|
| 104 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 105 | - unset($this->deleteMetaCache[$node->getPath()]); |
|
| 106 | - $this->root->emit('\OC\Files', 'postDelete', [$node]); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function touch($arguments) { |
|
| 110 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 111 | - $this->root->emit('\OC\Files', 'preTouch', [$node]); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - public function postTouch($arguments) { |
|
| 115 | - $node = $this->getNodeForPath($arguments['path']); |
|
| 116 | - $this->root->emit('\OC\Files', 'postTouch', [$node]); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function rename($arguments) { |
|
| 120 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 121 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
| 122 | - $this->root->emit('\OC\Files', 'preRename', [$source, $target]); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function postRename($arguments) { |
|
| 126 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 127 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
| 128 | - $this->root->emit('\OC\Files', 'postRename', [$source, $target]); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function copy($arguments) { |
|
| 132 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 133 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
| 134 | - $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function postCopy($arguments) { |
|
| 138 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 139 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
| 140 | - $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - private function getNodeForPath($path) { |
|
| 144 | - $info = Filesystem::getView()->getFileInfo($path); |
|
| 145 | - if (!$info) { |
|
| 146 | - |
|
| 147 | - $fullPath = Filesystem::getView()->getAbsolutePath($path); |
|
| 148 | - if (isset($this->deleteMetaCache[$fullPath])) { |
|
| 149 | - $info = $this->deleteMetaCache[$fullPath]; |
|
| 150 | - } else { |
|
| 151 | - $info = null; |
|
| 152 | - } |
|
| 153 | - if (Filesystem::is_dir($path)) { |
|
| 154 | - return new NonExistingFolder($this->root, $this->view, $fullPath, $info); |
|
| 155 | - } else { |
|
| 156 | - return new NonExistingFile($this->root, $this->view, $fullPath, $info); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - if ($info->getType() === FileInfo::TYPE_FILE) { |
|
| 160 | - return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 161 | - } else { |
|
| 162 | - return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 163 | - } |
|
| 164 | - } |
|
| 31 | + /** |
|
| 32 | + * @var Root |
|
| 33 | + */ |
|
| 34 | + private $root; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var View |
|
| 38 | + */ |
|
| 39 | + private $view; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var FileInfo[] |
|
| 43 | + */ |
|
| 44 | + private $deleteMetaCache = []; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * HookConnector constructor. |
|
| 48 | + * |
|
| 49 | + * @param Root $root |
|
| 50 | + * @param View $view |
|
| 51 | + */ |
|
| 52 | + public function __construct(Root $root, View $view) { |
|
| 53 | + $this->root = $root; |
|
| 54 | + $this->view = $view; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function viewToNode() { |
|
| 58 | + Util::connectHook('OC_Filesystem', 'write', $this, 'write'); |
|
| 59 | + Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite'); |
|
| 60 | + |
|
| 61 | + Util::connectHook('OC_Filesystem', 'create', $this, 'create'); |
|
| 62 | + Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate'); |
|
| 63 | + |
|
| 64 | + Util::connectHook('OC_Filesystem', 'delete', $this, 'delete'); |
|
| 65 | + Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete'); |
|
| 66 | + |
|
| 67 | + Util::connectHook('OC_Filesystem', 'rename', $this, 'rename'); |
|
| 68 | + Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename'); |
|
| 69 | + |
|
| 70 | + Util::connectHook('OC_Filesystem', 'copy', $this, 'copy'); |
|
| 71 | + Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy'); |
|
| 72 | + |
|
| 73 | + Util::connectHook('OC_Filesystem', 'touch', $this, 'touch'); |
|
| 74 | + Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch'); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function write($arguments) { |
|
| 78 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 79 | + $this->root->emit('\OC\Files', 'preWrite', [$node]); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function postWrite($arguments) { |
|
| 83 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 84 | + $this->root->emit('\OC\Files', 'postWrite', [$node]); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function create($arguments) { |
|
| 88 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 89 | + $this->root->emit('\OC\Files', 'preCreate', [$node]); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function postCreate($arguments) { |
|
| 93 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 94 | + $this->root->emit('\OC\Files', 'postCreate', [$node]); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function delete($arguments) { |
|
| 98 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 99 | + $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); |
|
| 100 | + $this->root->emit('\OC\Files', 'preDelete', [$node]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function postDelete($arguments) { |
|
| 104 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 105 | + unset($this->deleteMetaCache[$node->getPath()]); |
|
| 106 | + $this->root->emit('\OC\Files', 'postDelete', [$node]); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function touch($arguments) { |
|
| 110 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 111 | + $this->root->emit('\OC\Files', 'preTouch', [$node]); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + public function postTouch($arguments) { |
|
| 115 | + $node = $this->getNodeForPath($arguments['path']); |
|
| 116 | + $this->root->emit('\OC\Files', 'postTouch', [$node]); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function rename($arguments) { |
|
| 120 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 121 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
| 122 | + $this->root->emit('\OC\Files', 'preRename', [$source, $target]); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function postRename($arguments) { |
|
| 126 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 127 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
| 128 | + $this->root->emit('\OC\Files', 'postRename', [$source, $target]); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function copy($arguments) { |
|
| 132 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 133 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
| 134 | + $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function postCopy($arguments) { |
|
| 138 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
| 139 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
| 140 | + $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + private function getNodeForPath($path) { |
|
| 144 | + $info = Filesystem::getView()->getFileInfo($path); |
|
| 145 | + if (!$info) { |
|
| 146 | + |
|
| 147 | + $fullPath = Filesystem::getView()->getAbsolutePath($path); |
|
| 148 | + if (isset($this->deleteMetaCache[$fullPath])) { |
|
| 149 | + $info = $this->deleteMetaCache[$fullPath]; |
|
| 150 | + } else { |
|
| 151 | + $info = null; |
|
| 152 | + } |
|
| 153 | + if (Filesystem::is_dir($path)) { |
|
| 154 | + return new NonExistingFolder($this->root, $this->view, $fullPath, $info); |
|
| 155 | + } else { |
|
| 156 | + return new NonExistingFile($this->root, $this->view, $fullPath, $info); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + if ($info->getType() === FileInfo::TYPE_FILE) { |
|
| 160 | + return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 161 | + } else { |
|
| 162 | + return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | } |
@@ -26,119 +26,119 @@ |
||
| 26 | 26 | use OCP\Files\NotFoundException; |
| 27 | 27 | |
| 28 | 28 | class NonExistingFile extends File { |
| 29 | - /** |
|
| 30 | - * @param string $newPath |
|
| 31 | - * @throws \OCP\Files\NotFoundException |
|
| 32 | - */ |
|
| 33 | - public function rename($newPath) { |
|
| 34 | - throw new NotFoundException(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function delete() { |
|
| 38 | - throw new NotFoundException(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function copy($newPath) { |
|
| 42 | - throw new NotFoundException(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function touch($mtime = null) { |
|
| 46 | - throw new NotFoundException(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getId() { |
|
| 50 | - if ($this->fileInfo) { |
|
| 51 | - return parent::getId(); |
|
| 52 | - } else { |
|
| 53 | - throw new NotFoundException(); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function stat() { |
|
| 58 | - throw new NotFoundException(); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function getMTime() { |
|
| 62 | - if ($this->fileInfo) { |
|
| 63 | - return parent::getMTime(); |
|
| 64 | - } else { |
|
| 65 | - throw new NotFoundException(); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getSize() { |
|
| 70 | - if ($this->fileInfo) { |
|
| 71 | - return parent::getSize(); |
|
| 72 | - } else { |
|
| 73 | - throw new NotFoundException(); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function getEtag() { |
|
| 78 | - if ($this->fileInfo) { |
|
| 79 | - return parent::getEtag(); |
|
| 80 | - } else { |
|
| 81 | - throw new NotFoundException(); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function getPermissions() { |
|
| 86 | - if ($this->fileInfo) { |
|
| 87 | - return parent::getPermissions(); |
|
| 88 | - } else { |
|
| 89 | - throw new NotFoundException(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function isReadable() { |
|
| 94 | - if ($this->fileInfo) { |
|
| 95 | - return parent::isReadable(); |
|
| 96 | - } else { |
|
| 97 | - throw new NotFoundException(); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function isUpdateable() { |
|
| 102 | - if ($this->fileInfo) { |
|
| 103 | - return parent::isUpdateable(); |
|
| 104 | - } else { |
|
| 105 | - throw new NotFoundException(); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function isDeletable() { |
|
| 110 | - if ($this->fileInfo) { |
|
| 111 | - return parent::isDeletable(); |
|
| 112 | - } else { |
|
| 113 | - throw new NotFoundException(); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function isShareable() { |
|
| 118 | - if ($this->fileInfo) { |
|
| 119 | - return parent::isShareable(); |
|
| 120 | - } else { |
|
| 121 | - throw new NotFoundException(); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function getContent() { |
|
| 126 | - throw new NotFoundException(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function putContent($data) { |
|
| 130 | - throw new NotFoundException(); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function getMimeType() { |
|
| 134 | - if ($this->fileInfo) { |
|
| 135 | - return parent::getMimeType(); |
|
| 136 | - } else { |
|
| 137 | - throw new NotFoundException(); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function fopen($mode) { |
|
| 142 | - throw new NotFoundException(); |
|
| 143 | - } |
|
| 29 | + /** |
|
| 30 | + * @param string $newPath |
|
| 31 | + * @throws \OCP\Files\NotFoundException |
|
| 32 | + */ |
|
| 33 | + public function rename($newPath) { |
|
| 34 | + throw new NotFoundException(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function delete() { |
|
| 38 | + throw new NotFoundException(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function copy($newPath) { |
|
| 42 | + throw new NotFoundException(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function touch($mtime = null) { |
|
| 46 | + throw new NotFoundException(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getId() { |
|
| 50 | + if ($this->fileInfo) { |
|
| 51 | + return parent::getId(); |
|
| 52 | + } else { |
|
| 53 | + throw new NotFoundException(); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function stat() { |
|
| 58 | + throw new NotFoundException(); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function getMTime() { |
|
| 62 | + if ($this->fileInfo) { |
|
| 63 | + return parent::getMTime(); |
|
| 64 | + } else { |
|
| 65 | + throw new NotFoundException(); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getSize() { |
|
| 70 | + if ($this->fileInfo) { |
|
| 71 | + return parent::getSize(); |
|
| 72 | + } else { |
|
| 73 | + throw new NotFoundException(); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function getEtag() { |
|
| 78 | + if ($this->fileInfo) { |
|
| 79 | + return parent::getEtag(); |
|
| 80 | + } else { |
|
| 81 | + throw new NotFoundException(); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function getPermissions() { |
|
| 86 | + if ($this->fileInfo) { |
|
| 87 | + return parent::getPermissions(); |
|
| 88 | + } else { |
|
| 89 | + throw new NotFoundException(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function isReadable() { |
|
| 94 | + if ($this->fileInfo) { |
|
| 95 | + return parent::isReadable(); |
|
| 96 | + } else { |
|
| 97 | + throw new NotFoundException(); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function isUpdateable() { |
|
| 102 | + if ($this->fileInfo) { |
|
| 103 | + return parent::isUpdateable(); |
|
| 104 | + } else { |
|
| 105 | + throw new NotFoundException(); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function isDeletable() { |
|
| 110 | + if ($this->fileInfo) { |
|
| 111 | + return parent::isDeletable(); |
|
| 112 | + } else { |
|
| 113 | + throw new NotFoundException(); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function isShareable() { |
|
| 118 | + if ($this->fileInfo) { |
|
| 119 | + return parent::isShareable(); |
|
| 120 | + } else { |
|
| 121 | + throw new NotFoundException(); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function getContent() { |
|
| 126 | + throw new NotFoundException(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function putContent($data) { |
|
| 130 | + throw new NotFoundException(); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function getMimeType() { |
|
| 134 | + if ($this->fileInfo) { |
|
| 135 | + return parent::getMimeType(); |
|
| 136 | + } else { |
|
| 137 | + throw new NotFoundException(); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function fopen($mode) { |
|
| 142 | + throw new NotFoundException(); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -31,40 +31,40 @@ |
||
| 31 | 31 | * Mount provider for custom cache storages |
| 32 | 32 | */ |
| 33 | 33 | class CacheMountProvider implements IMountProvider { |
| 34 | - /** |
|
| 35 | - * @var IConfig |
|
| 36 | - */ |
|
| 37 | - private $config; |
|
| 34 | + /** |
|
| 35 | + * @var IConfig |
|
| 36 | + */ |
|
| 37 | + private $config; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * ObjectStoreHomeMountProvider constructor. |
|
| 41 | - * |
|
| 42 | - * @param IConfig $config |
|
| 43 | - */ |
|
| 44 | - public function __construct(IConfig $config) { |
|
| 45 | - $this->config = $config; |
|
| 46 | - } |
|
| 39 | + /** |
|
| 40 | + * ObjectStoreHomeMountProvider constructor. |
|
| 41 | + * |
|
| 42 | + * @param IConfig $config |
|
| 43 | + */ |
|
| 44 | + public function __construct(IConfig $config) { |
|
| 45 | + $this->config = $config; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Get the cache mount for a user |
|
| 50 | - * |
|
| 51 | - * @param IUser $user |
|
| 52 | - * @param IStorageFactory $loader |
|
| 53 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 54 | - */ |
|
| 55 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
| 56 | - $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
|
| 57 | - if ($cacheBaseDir !== '') { |
|
| 58 | - $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
| 59 | - if (!file_exists($cacheDir)) { |
|
| 60 | - mkdir($cacheDir, 0770, true); |
|
| 61 | - } |
|
| 48 | + /** |
|
| 49 | + * Get the cache mount for a user |
|
| 50 | + * |
|
| 51 | + * @param IUser $user |
|
| 52 | + * @param IStorageFactory $loader |
|
| 53 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 54 | + */ |
|
| 55 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
| 56 | + $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
|
| 57 | + if ($cacheBaseDir !== '') { |
|
| 58 | + $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
| 59 | + if (!file_exists($cacheDir)) { |
|
| 60 | + mkdir($cacheDir, 0770, true); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return [ |
|
| 64 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]) |
|
| 65 | - ]; |
|
| 66 | - } else { |
|
| 67 | - return []; |
|
| 68 | - } |
|
| 69 | - } |
|
| 63 | + return [ |
|
| 64 | + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]) |
|
| 65 | + ]; |
|
| 66 | + } else { |
|
| 67 | + return []; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -55,13 +55,13 @@ |
||
| 55 | 55 | public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
| 56 | 56 | $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
| 57 | 57 | if ($cacheBaseDir !== '') { |
| 58 | - $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
| 58 | + $cacheDir = rtrim($cacheBaseDir, '/').'/'.$user->getUID(); |
|
| 59 | 59 | if (!file_exists($cacheDir)) { |
| 60 | 60 | mkdir($cacheDir, 0770, true); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | return [ |
| 64 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]) |
|
| 64 | + new MountPoint('\OC\Files\Storage\Local', '/'.$user->getUID().'/cache', ['datadir' => $cacheDir, $loader]) |
|
| 65 | 65 | ]; |
| 66 | 66 | } else { |
| 67 | 67 | return []; |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | return null; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader); |
|
| 67 | + return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/'.$user->getUID(), $config['arguments'], $loader); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -32,105 +32,105 @@ |
||
| 32 | 32 | * Mount provider for object store home storages |
| 33 | 33 | */ |
| 34 | 34 | class ObjectHomeMountProvider implements IHomeMountProvider { |
| 35 | - /** |
|
| 36 | - * @var IConfig |
|
| 37 | - */ |
|
| 38 | - private $config; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * ObjectStoreHomeMountProvider constructor. |
|
| 42 | - * |
|
| 43 | - * @param IConfig $config |
|
| 44 | - */ |
|
| 45 | - public function __construct(IConfig $config) { |
|
| 46 | - $this->config = $config; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Get the cache mount for a user |
|
| 51 | - * |
|
| 52 | - * @param IUser $user |
|
| 53 | - * @param IStorageFactory $loader |
|
| 54 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
| 55 | - */ |
|
| 56 | - public function getHomeMountForUser(IUser $user, IStorageFactory $loader) { |
|
| 57 | - |
|
| 58 | - $config = $this->getMultiBucketObjectStoreConfig($user); |
|
| 59 | - if ($config === null) { |
|
| 60 | - $config = $this->getSingleBucketObjectStoreConfig($user); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if ($config === null) { |
|
| 64 | - return null; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param IUser $user |
|
| 72 | - * @return array|null |
|
| 73 | - */ |
|
| 74 | - private function getSingleBucketObjectStoreConfig(IUser $user) { |
|
| 75 | - $config = $this->config->getSystemValue('objectstore'); |
|
| 76 | - if (!is_array($config)) { |
|
| 77 | - return null; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // sanity checks |
|
| 81 | - if (empty($config['class'])) { |
|
| 82 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 83 | - } |
|
| 84 | - if (!isset($config['arguments'])) { |
|
| 85 | - $config['arguments'] = []; |
|
| 86 | - } |
|
| 87 | - $config['arguments']['user'] = $user; |
|
| 88 | - // instantiate object store implementation |
|
| 89 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 90 | - |
|
| 91 | - return $config; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param IUser $user |
|
| 96 | - * @return array|null |
|
| 97 | - */ |
|
| 98 | - private function getMultiBucketObjectStoreConfig(IUser $user) { |
|
| 99 | - $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
| 100 | - if (!is_array($config)) { |
|
| 101 | - return null; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // sanity checks |
|
| 105 | - if (empty($config['class'])) { |
|
| 106 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 107 | - } |
|
| 108 | - if (!isset($config['arguments'])) { |
|
| 109 | - $config['arguments'] = []; |
|
| 110 | - } |
|
| 111 | - $config['arguments']['user'] = $user; |
|
| 112 | - |
|
| 113 | - $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); |
|
| 114 | - |
|
| 115 | - if ($bucket === null) { |
|
| 116 | - /* |
|
| 35 | + /** |
|
| 36 | + * @var IConfig |
|
| 37 | + */ |
|
| 38 | + private $config; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * ObjectStoreHomeMountProvider constructor. |
|
| 42 | + * |
|
| 43 | + * @param IConfig $config |
|
| 44 | + */ |
|
| 45 | + public function __construct(IConfig $config) { |
|
| 46 | + $this->config = $config; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Get the cache mount for a user |
|
| 51 | + * |
|
| 52 | + * @param IUser $user |
|
| 53 | + * @param IStorageFactory $loader |
|
| 54 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
| 55 | + */ |
|
| 56 | + public function getHomeMountForUser(IUser $user, IStorageFactory $loader) { |
|
| 57 | + |
|
| 58 | + $config = $this->getMultiBucketObjectStoreConfig($user); |
|
| 59 | + if ($config === null) { |
|
| 60 | + $config = $this->getSingleBucketObjectStoreConfig($user); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if ($config === null) { |
|
| 64 | + return null; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return new MountPoint('\OC\Files\ObjectStore\HomeObjectStoreStorage', '/' . $user->getUID(), $config['arguments'], $loader); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param IUser $user |
|
| 72 | + * @return array|null |
|
| 73 | + */ |
|
| 74 | + private function getSingleBucketObjectStoreConfig(IUser $user) { |
|
| 75 | + $config = $this->config->getSystemValue('objectstore'); |
|
| 76 | + if (!is_array($config)) { |
|
| 77 | + return null; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // sanity checks |
|
| 81 | + if (empty($config['class'])) { |
|
| 82 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 83 | + } |
|
| 84 | + if (!isset($config['arguments'])) { |
|
| 85 | + $config['arguments'] = []; |
|
| 86 | + } |
|
| 87 | + $config['arguments']['user'] = $user; |
|
| 88 | + // instantiate object store implementation |
|
| 89 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 90 | + |
|
| 91 | + return $config; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param IUser $user |
|
| 96 | + * @return array|null |
|
| 97 | + */ |
|
| 98 | + private function getMultiBucketObjectStoreConfig(IUser $user) { |
|
| 99 | + $config = $this->config->getSystemValue('objectstore_multibucket'); |
|
| 100 | + if (!is_array($config)) { |
|
| 101 | + return null; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // sanity checks |
|
| 105 | + if (empty($config['class'])) { |
|
| 106 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 107 | + } |
|
| 108 | + if (!isset($config['arguments'])) { |
|
| 109 | + $config['arguments'] = []; |
|
| 110 | + } |
|
| 111 | + $config['arguments']['user'] = $user; |
|
| 112 | + |
|
| 113 | + $bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null); |
|
| 114 | + |
|
| 115 | + if ($bucket === null) { |
|
| 116 | + /* |
|
| 117 | 117 | * Use any provided bucket argument as prefix |
| 118 | 118 | * and add the mapping from username => bucket |
| 119 | 119 | */ |
| 120 | - if (!isset($config['arguments']['bucket'])) { |
|
| 121 | - $config['arguments']['bucket'] = ''; |
|
| 122 | - } |
|
| 123 | - $mapper = new \OC\Files\ObjectStore\Mapper($user); |
|
| 124 | - $config['arguments']['bucket'] .= $mapper->getBucket(); |
|
| 125 | - |
|
| 126 | - $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); |
|
| 127 | - } else { |
|
| 128 | - $config['arguments']['bucket'] = $bucket; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // instantiate object store implementation |
|
| 132 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 133 | - |
|
| 134 | - return $config; |
|
| 135 | - } |
|
| 120 | + if (!isset($config['arguments']['bucket'])) { |
|
| 121 | + $config['arguments']['bucket'] = ''; |
|
| 122 | + } |
|
| 123 | + $mapper = new \OC\Files\ObjectStore\Mapper($user); |
|
| 124 | + $config['arguments']['bucket'] .= $mapper->getBucket(); |
|
| 125 | + |
|
| 126 | + $this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']); |
|
| 127 | + } else { |
|
| 128 | + $config['arguments']['bucket'] = $bucket; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // instantiate object store implementation |
|
| 132 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 133 | + |
|
| 134 | + return $config; |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -27,19 +27,19 @@ |
||
| 27 | 27 | * Defines the mount point to be (re)moved by the user |
| 28 | 28 | */ |
| 29 | 29 | interface MoveableMount { |
| 30 | - /** |
|
| 31 | - * Move the mount point to $target |
|
| 32 | - * |
|
| 33 | - * @param string $target the target mount point |
|
| 34 | - * @return bool |
|
| 35 | - */ |
|
| 36 | - public function moveMount($target); |
|
| 30 | + /** |
|
| 31 | + * Move the mount point to $target |
|
| 32 | + * |
|
| 33 | + * @param string $target the target mount point |
|
| 34 | + * @return bool |
|
| 35 | + */ |
|
| 36 | + public function moveMount($target); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Remove the mount points |
|
| 40 | - * |
|
| 41 | - * @return mixed |
|
| 42 | - * @return bool |
|
| 43 | - */ |
|
| 44 | - public function removeMount(); |
|
| 38 | + /** |
|
| 39 | + * Remove the mount points |
|
| 40 | + * |
|
| 41 | + * @return mixed |
|
| 42 | + * @return bool |
|
| 43 | + */ |
|
| 44 | + public function removeMount(); |
|
| 45 | 45 | } |
@@ -30,137 +30,137 @@ |
||
| 30 | 30 | use OCP\Files\Mount\IMountPoint; |
| 31 | 31 | |
| 32 | 32 | class Manager implements IMountManager { |
| 33 | - /** |
|
| 34 | - * @var MountPoint[] |
|
| 35 | - */ |
|
| 36 | - private $mounts = array(); |
|
| 33 | + /** |
|
| 34 | + * @var MountPoint[] |
|
| 35 | + */ |
|
| 36 | + private $mounts = array(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param IMountPoint $mount |
|
| 40 | - */ |
|
| 41 | - public function addMount(IMountPoint $mount) { |
|
| 42 | - $this->mounts[$mount->getMountPoint()] = $mount; |
|
| 43 | - } |
|
| 38 | + /** |
|
| 39 | + * @param IMountPoint $mount |
|
| 40 | + */ |
|
| 41 | + public function addMount(IMountPoint $mount) { |
|
| 42 | + $this->mounts[$mount->getMountPoint()] = $mount; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $mountPoint |
|
| 47 | - */ |
|
| 48 | - public function removeMount($mountPoint) { |
|
| 49 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 50 | - if (strlen($mountPoint) > 1) { |
|
| 51 | - $mountPoint .= '/'; |
|
| 52 | - } |
|
| 53 | - unset($this->mounts[$mountPoint]); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $mountPoint |
|
| 47 | + */ |
|
| 48 | + public function removeMount($mountPoint) { |
|
| 49 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 50 | + if (strlen($mountPoint) > 1) { |
|
| 51 | + $mountPoint .= '/'; |
|
| 52 | + } |
|
| 53 | + unset($this->mounts[$mountPoint]); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param string $mountPoint |
|
| 58 | - * @param string $target |
|
| 59 | - */ |
|
| 60 | - public function moveMount($mountPoint, $target){ |
|
| 61 | - $this->mounts[$target] = $this->mounts[$mountPoint]; |
|
| 62 | - unset($this->mounts[$mountPoint]); |
|
| 63 | - } |
|
| 56 | + /** |
|
| 57 | + * @param string $mountPoint |
|
| 58 | + * @param string $target |
|
| 59 | + */ |
|
| 60 | + public function moveMount($mountPoint, $target){ |
|
| 61 | + $this->mounts[$target] = $this->mounts[$mountPoint]; |
|
| 62 | + unset($this->mounts[$mountPoint]); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Find the mount for $path |
|
| 67 | - * |
|
| 68 | - * @param string $path |
|
| 69 | - * @return MountPoint |
|
| 70 | - */ |
|
| 71 | - public function find($path) { |
|
| 72 | - \OC_Util::setupFS(); |
|
| 73 | - $path = $this->formatPath($path); |
|
| 74 | - if (isset($this->mounts[$path])) { |
|
| 75 | - return $this->mounts[$path]; |
|
| 76 | - } |
|
| 65 | + /** |
|
| 66 | + * Find the mount for $path |
|
| 67 | + * |
|
| 68 | + * @param string $path |
|
| 69 | + * @return MountPoint |
|
| 70 | + */ |
|
| 71 | + public function find($path) { |
|
| 72 | + \OC_Util::setupFS(); |
|
| 73 | + $path = $this->formatPath($path); |
|
| 74 | + if (isset($this->mounts[$path])) { |
|
| 75 | + return $this->mounts[$path]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', array('path' => $path)); |
|
| 79 | - $foundMountPoint = ''; |
|
| 80 | - $mountPoints = array_keys($this->mounts); |
|
| 81 | - foreach ($mountPoints as $mountpoint) { |
|
| 82 | - if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) { |
|
| 83 | - $foundMountPoint = $mountpoint; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - if (isset($this->mounts[$foundMountPoint])) { |
|
| 87 | - return $this->mounts[$foundMountPoint]; |
|
| 88 | - } else { |
|
| 89 | - return null; |
|
| 90 | - } |
|
| 91 | - } |
|
| 78 | + \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', array('path' => $path)); |
|
| 79 | + $foundMountPoint = ''; |
|
| 80 | + $mountPoints = array_keys($this->mounts); |
|
| 81 | + foreach ($mountPoints as $mountpoint) { |
|
| 82 | + if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) { |
|
| 83 | + $foundMountPoint = $mountpoint; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + if (isset($this->mounts[$foundMountPoint])) { |
|
| 87 | + return $this->mounts[$foundMountPoint]; |
|
| 88 | + } else { |
|
| 89 | + return null; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Find all mounts in $path |
|
| 95 | - * |
|
| 96 | - * @param string $path |
|
| 97 | - * @return MountPoint[] |
|
| 98 | - */ |
|
| 99 | - public function findIn($path) { |
|
| 100 | - \OC_Util::setupFS(); |
|
| 101 | - $path = $this->formatPath($path); |
|
| 102 | - $result = array(); |
|
| 103 | - $pathLength = strlen($path); |
|
| 104 | - $mountPoints = array_keys($this->mounts); |
|
| 105 | - foreach ($mountPoints as $mountPoint) { |
|
| 106 | - if (substr($mountPoint, 0, $pathLength) === $path and strlen($mountPoint) > $pathLength) { |
|
| 107 | - $result[] = $this->mounts[$mountPoint]; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - return $result; |
|
| 111 | - } |
|
| 93 | + /** |
|
| 94 | + * Find all mounts in $path |
|
| 95 | + * |
|
| 96 | + * @param string $path |
|
| 97 | + * @return MountPoint[] |
|
| 98 | + */ |
|
| 99 | + public function findIn($path) { |
|
| 100 | + \OC_Util::setupFS(); |
|
| 101 | + $path = $this->formatPath($path); |
|
| 102 | + $result = array(); |
|
| 103 | + $pathLength = strlen($path); |
|
| 104 | + $mountPoints = array_keys($this->mounts); |
|
| 105 | + foreach ($mountPoints as $mountPoint) { |
|
| 106 | + if (substr($mountPoint, 0, $pathLength) === $path and strlen($mountPoint) > $pathLength) { |
|
| 107 | + $result[] = $this->mounts[$mountPoint]; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + return $result; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public function clear() { |
|
| 114 | - $this->mounts = array(); |
|
| 115 | - } |
|
| 113 | + public function clear() { |
|
| 114 | + $this->mounts = array(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Find mounts by storage id |
|
| 119 | - * |
|
| 120 | - * @param string $id |
|
| 121 | - * @return MountPoint[] |
|
| 122 | - */ |
|
| 123 | - public function findByStorageId($id) { |
|
| 124 | - \OC_Util::setupFS(); |
|
| 125 | - if (strlen($id) > 64) { |
|
| 126 | - $id = md5($id); |
|
| 127 | - } |
|
| 128 | - $result = array(); |
|
| 129 | - foreach ($this->mounts as $mount) { |
|
| 130 | - if ($mount->getStorageId() === $id) { |
|
| 131 | - $result[] = $mount; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $result; |
|
| 135 | - } |
|
| 117 | + /** |
|
| 118 | + * Find mounts by storage id |
|
| 119 | + * |
|
| 120 | + * @param string $id |
|
| 121 | + * @return MountPoint[] |
|
| 122 | + */ |
|
| 123 | + public function findByStorageId($id) { |
|
| 124 | + \OC_Util::setupFS(); |
|
| 125 | + if (strlen($id) > 64) { |
|
| 126 | + $id = md5($id); |
|
| 127 | + } |
|
| 128 | + $result = array(); |
|
| 129 | + foreach ($this->mounts as $mount) { |
|
| 130 | + if ($mount->getStorageId() === $id) { |
|
| 131 | + $result[] = $mount; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $result; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * @return MountPoint[] |
|
| 139 | - */ |
|
| 140 | - public function getAll() { |
|
| 141 | - return $this->mounts; |
|
| 142 | - } |
|
| 137 | + /** |
|
| 138 | + * @return MountPoint[] |
|
| 139 | + */ |
|
| 140 | + public function getAll() { |
|
| 141 | + return $this->mounts; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Find mounts by numeric storage id |
|
| 146 | - * |
|
| 147 | - * @param int $id |
|
| 148 | - * @return MountPoint[] |
|
| 149 | - */ |
|
| 150 | - public function findByNumericId($id) { |
|
| 151 | - $storageId = \OC\Files\Cache\Storage::getStorageId($id); |
|
| 152 | - return $this->findByStorageId($storageId); |
|
| 153 | - } |
|
| 144 | + /** |
|
| 145 | + * Find mounts by numeric storage id |
|
| 146 | + * |
|
| 147 | + * @param int $id |
|
| 148 | + * @return MountPoint[] |
|
| 149 | + */ |
|
| 150 | + public function findByNumericId($id) { |
|
| 151 | + $storageId = \OC\Files\Cache\Storage::getStorageId($id); |
|
| 152 | + return $this->findByStorageId($storageId); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * @param string $path |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - private function formatPath($path) { |
|
| 160 | - $path = Filesystem::normalizePath($path); |
|
| 161 | - if (strlen($path) > 1) { |
|
| 162 | - $path .= '/'; |
|
| 163 | - } |
|
| 164 | - return $path; |
|
| 165 | - } |
|
| 155 | + /** |
|
| 156 | + * @param string $path |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + private function formatPath($path) { |
|
| 160 | + $path = Filesystem::normalizePath($path); |
|
| 161 | + if (strlen($path) > 1) { |
|
| 162 | + $path .= '/'; |
|
| 163 | + } |
|
| 164 | + return $path; |
|
| 165 | + } |
|
| 166 | 166 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | * @param string $mountPoint |
| 58 | 58 | * @param string $target |
| 59 | 59 | */ |
| 60 | - public function moveMount($mountPoint, $target){ |
|
| 60 | + public function moveMount($mountPoint, $target) { |
|
| 61 | 61 | $this->mounts[$target] = $this->mounts[$mountPoint]; |
| 62 | 62 | unset($this->mounts[$mountPoint]); |
| 63 | 63 | } |
@@ -32,470 +32,470 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Encryption extends Wrapper { |
| 34 | 34 | |
| 35 | - /** @var \OC\Encryption\Util */ |
|
| 36 | - protected $util; |
|
| 37 | - |
|
| 38 | - /** @var \OC\Encryption\File */ |
|
| 39 | - protected $file; |
|
| 40 | - |
|
| 41 | - /** @var \OCP\Encryption\IEncryptionModule */ |
|
| 42 | - protected $encryptionModule; |
|
| 43 | - |
|
| 44 | - /** @var \OC\Files\Storage\Storage */ |
|
| 45 | - protected $storage; |
|
| 46 | - |
|
| 47 | - /** @var \OC\Files\Storage\Wrapper\Encryption */ |
|
| 48 | - protected $encryptionStorage; |
|
| 49 | - |
|
| 50 | - /** @var string */ |
|
| 51 | - protected $internalPath; |
|
| 52 | - |
|
| 53 | - /** @var string */ |
|
| 54 | - protected $cache; |
|
| 55 | - |
|
| 56 | - /** @var integer */ |
|
| 57 | - protected $size; |
|
| 58 | - |
|
| 59 | - /** @var integer */ |
|
| 60 | - protected $position; |
|
| 61 | - |
|
| 62 | - /** @var integer */ |
|
| 63 | - protected $unencryptedSize; |
|
| 64 | - |
|
| 65 | - /** @var integer */ |
|
| 66 | - protected $headerSize; |
|
| 67 | - |
|
| 68 | - /** @var integer */ |
|
| 69 | - protected $unencryptedBlockSize; |
|
| 70 | - |
|
| 71 | - /** @var array */ |
|
| 72 | - protected $header; |
|
| 73 | - |
|
| 74 | - /** @var string */ |
|
| 75 | - protected $fullPath; |
|
| 76 | - |
|
| 77 | - /** @var bool */ |
|
| 78 | - protected $signed; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * header data returned by the encryption module, will be written to the file |
|
| 82 | - * in case of a write operation |
|
| 83 | - * |
|
| 84 | - * @var array |
|
| 85 | - */ |
|
| 86 | - protected $newHeader; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * user who perform the read/write operation null for public access |
|
| 90 | - * |
|
| 91 | - * @var string |
|
| 92 | - */ |
|
| 93 | - protected $uid; |
|
| 94 | - |
|
| 95 | - /** @var bool */ |
|
| 96 | - protected $readOnly; |
|
| 97 | - |
|
| 98 | - /** @var bool */ |
|
| 99 | - protected $writeFlag; |
|
| 100 | - |
|
| 101 | - /** @var array */ |
|
| 102 | - protected $expectedContextProperties; |
|
| 103 | - |
|
| 104 | - public function __construct() { |
|
| 105 | - $this->expectedContextProperties = array( |
|
| 106 | - 'source', |
|
| 107 | - 'storage', |
|
| 108 | - 'internalPath', |
|
| 109 | - 'fullPath', |
|
| 110 | - 'encryptionModule', |
|
| 111 | - 'header', |
|
| 112 | - 'uid', |
|
| 113 | - 'file', |
|
| 114 | - 'util', |
|
| 115 | - 'size', |
|
| 116 | - 'unencryptedSize', |
|
| 117 | - 'encryptionStorage', |
|
| 118 | - 'headerSize', |
|
| 119 | - 'signed' |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Wraps a stream with the provided callbacks |
|
| 126 | - * |
|
| 127 | - * @param resource $source |
|
| 128 | - * @param string $internalPath relative to mount point |
|
| 129 | - * @param string $fullPath relative to data/ |
|
| 130 | - * @param array $header |
|
| 131 | - * @param string $uid |
|
| 132 | - * @param \OCP\Encryption\IEncryptionModule $encryptionModule |
|
| 133 | - * @param \OC\Files\Storage\Storage $storage |
|
| 134 | - * @param \OC\Files\Storage\Wrapper\Encryption $encStorage |
|
| 135 | - * @param \OC\Encryption\Util $util |
|
| 136 | - * @param \OC\Encryption\File $file |
|
| 137 | - * @param string $mode |
|
| 138 | - * @param int $size |
|
| 139 | - * @param int $unencryptedSize |
|
| 140 | - * @param int $headerSize |
|
| 141 | - * @param bool $signed |
|
| 142 | - * @param string $wrapper stream wrapper class |
|
| 143 | - * @return resource |
|
| 144 | - * |
|
| 145 | - * @throws \BadMethodCallException |
|
| 146 | - */ |
|
| 147 | - public static function wrap($source, $internalPath, $fullPath, array $header, |
|
| 148 | - $uid, |
|
| 149 | - \OCP\Encryption\IEncryptionModule $encryptionModule, |
|
| 150 | - \OC\Files\Storage\Storage $storage, |
|
| 151 | - \OC\Files\Storage\Wrapper\Encryption $encStorage, |
|
| 152 | - \OC\Encryption\Util $util, |
|
| 153 | - \OC\Encryption\File $file, |
|
| 154 | - $mode, |
|
| 155 | - $size, |
|
| 156 | - $unencryptedSize, |
|
| 157 | - $headerSize, |
|
| 158 | - $signed, |
|
| 159 | - $wrapper = 'OC\Files\Stream\Encryption') { |
|
| 160 | - |
|
| 161 | - $context = stream_context_create(array( |
|
| 162 | - 'ocencryption' => array( |
|
| 163 | - 'source' => $source, |
|
| 164 | - 'storage' => $storage, |
|
| 165 | - 'internalPath' => $internalPath, |
|
| 166 | - 'fullPath' => $fullPath, |
|
| 167 | - 'encryptionModule' => $encryptionModule, |
|
| 168 | - 'header' => $header, |
|
| 169 | - 'uid' => $uid, |
|
| 170 | - 'util' => $util, |
|
| 171 | - 'file' => $file, |
|
| 172 | - 'size' => $size, |
|
| 173 | - 'unencryptedSize' => $unencryptedSize, |
|
| 174 | - 'encryptionStorage' => $encStorage, |
|
| 175 | - 'headerSize' => $headerSize, |
|
| 176 | - 'signed' => $signed |
|
| 177 | - ) |
|
| 178 | - )); |
|
| 179 | - |
|
| 180 | - return self::wrapSource($source, $context, 'ocencryption', $wrapper, $mode); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * add stream wrapper |
|
| 185 | - * |
|
| 186 | - * @param resource $source |
|
| 187 | - * @param string $mode |
|
| 188 | - * @param resource $context |
|
| 189 | - * @param string $protocol |
|
| 190 | - * @param string $class |
|
| 191 | - * @return resource |
|
| 192 | - * @throws \BadMethodCallException |
|
| 193 | - */ |
|
| 194 | - protected static function wrapSource($source, $context, $protocol, $class, $mode = 'r+') { |
|
| 195 | - try { |
|
| 196 | - stream_wrapper_register($protocol, $class); |
|
| 197 | - if (@rewinddir($source) === false) { |
|
| 198 | - $wrapped = fopen($protocol . '://', $mode, false, $context); |
|
| 199 | - } else { |
|
| 200 | - $wrapped = opendir($protocol . '://', $context); |
|
| 201 | - } |
|
| 202 | - } catch (\BadMethodCallException $e) { |
|
| 203 | - stream_wrapper_unregister($protocol); |
|
| 204 | - throw $e; |
|
| 205 | - } |
|
| 206 | - stream_wrapper_unregister($protocol); |
|
| 207 | - return $wrapped; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Load the source from the stream context and return the context options |
|
| 212 | - * |
|
| 213 | - * @param string $name |
|
| 214 | - * @return array |
|
| 215 | - * @throws \BadMethodCallException |
|
| 216 | - */ |
|
| 217 | - protected function loadContext($name) { |
|
| 218 | - $context = parent::loadContext($name); |
|
| 219 | - |
|
| 220 | - foreach ($this->expectedContextProperties as $property) { |
|
| 221 | - if (array_key_exists($property, $context)) { |
|
| 222 | - $this->{$property} = $context[$property]; |
|
| 223 | - } else { |
|
| 224 | - throw new \BadMethodCallException('Invalid context, "' . $property . '" options not set'); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - return $context; |
|
| 228 | - |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - public function stream_open($path, $mode, $options, &$opened_path) { |
|
| 232 | - $this->loadContext('ocencryption'); |
|
| 233 | - |
|
| 234 | - $this->position = 0; |
|
| 235 | - $this->cache = ''; |
|
| 236 | - $this->writeFlag = false; |
|
| 237 | - $this->unencryptedBlockSize = $this->encryptionModule->getUnencryptedBlockSize($this->signed); |
|
| 238 | - |
|
| 239 | - if ( |
|
| 240 | - $mode === 'w' |
|
| 241 | - || $mode === 'w+' |
|
| 242 | - || $mode === 'wb' |
|
| 243 | - || $mode === 'wb+' |
|
| 244 | - || $mode === 'r+' |
|
| 245 | - || $mode === 'rb+' |
|
| 246 | - ) { |
|
| 247 | - $this->readOnly = false; |
|
| 248 | - } else { |
|
| 249 | - $this->readOnly = true; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $sharePath = $this->fullPath; |
|
| 253 | - if (!$this->storage->file_exists($this->internalPath)) { |
|
| 254 | - $sharePath = dirname($sharePath); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $accessList = $this->file->getAccessList($sharePath); |
|
| 258 | - $this->newHeader = $this->encryptionModule->begin($this->fullPath, $this->uid, $mode, $this->header, $accessList); |
|
| 259 | - |
|
| 260 | - if ( |
|
| 261 | - $mode === 'w' |
|
| 262 | - || $mode === 'w+' |
|
| 263 | - || $mode === 'wb' |
|
| 264 | - || $mode === 'wb+' |
|
| 265 | - ) { |
|
| 266 | - // We're writing a new file so start write counter with 0 bytes |
|
| 267 | - $this->unencryptedSize = 0; |
|
| 268 | - $this->writeHeader(); |
|
| 269 | - $this->headerSize = $this->util->getHeaderSize(); |
|
| 270 | - $this->size = $this->headerSize; |
|
| 271 | - } else { |
|
| 272 | - $this->skipHeader(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return true; |
|
| 276 | - |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - public function stream_eof() { |
|
| 280 | - return $this->position >= $this->unencryptedSize; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - public function stream_read($count) { |
|
| 284 | - |
|
| 285 | - $result = ''; |
|
| 286 | - |
|
| 287 | - $count = min($count, $this->unencryptedSize - $this->position); |
|
| 288 | - while ($count > 0) { |
|
| 289 | - $remainingLength = $count; |
|
| 290 | - // update the cache of the current block |
|
| 291 | - $this->readCache(); |
|
| 292 | - // determine the relative position in the current block |
|
| 293 | - $blockPosition = ($this->position % $this->unencryptedBlockSize); |
|
| 294 | - // if entire read inside current block then only position needs to be updated |
|
| 295 | - if ($remainingLength < ($this->unencryptedBlockSize - $blockPosition)) { |
|
| 296 | - $result .= substr($this->cache, $blockPosition, $remainingLength); |
|
| 297 | - $this->position += $remainingLength; |
|
| 298 | - $count = 0; |
|
| 299 | - // otherwise remainder of current block is fetched, the block is flushed and the position updated |
|
| 300 | - } else { |
|
| 301 | - $result .= substr($this->cache, $blockPosition); |
|
| 302 | - $this->flush(); |
|
| 303 | - $this->position += ($this->unencryptedBlockSize - $blockPosition); |
|
| 304 | - $count -= ($this->unencryptedBlockSize - $blockPosition); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - return $result; |
|
| 308 | - |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - public function stream_write($data) { |
|
| 312 | - |
|
| 313 | - $length = 0; |
|
| 314 | - // loop over $data to fit it in 6126 sized unencrypted blocks |
|
| 315 | - while (isset($data[0])) { |
|
| 316 | - $remainingLength = strlen($data); |
|
| 317 | - |
|
| 318 | - // set the cache to the current 6126 block |
|
| 319 | - $this->readCache(); |
|
| 320 | - |
|
| 321 | - // for seekable streams the pointer is moved back to the beginning of the encrypted block |
|
| 322 | - // flush will start writing there when the position moves to another block |
|
| 323 | - $positionInFile = (int)floor($this->position / $this->unencryptedBlockSize) * |
|
| 324 | - $this->util->getBlockSize() + $this->headerSize; |
|
| 325 | - $resultFseek = $this->parentStreamSeek($positionInFile); |
|
| 326 | - |
|
| 327 | - // only allow writes on seekable streams, or at the end of the encrypted stream |
|
| 328 | - if (!($this->readOnly) && ($resultFseek || $positionInFile === $this->size)) { |
|
| 329 | - |
|
| 330 | - // switch the writeFlag so flush() will write the block |
|
| 331 | - $this->writeFlag = true; |
|
| 332 | - |
|
| 333 | - // determine the relative position in the current block |
|
| 334 | - $blockPosition = ($this->position % $this->unencryptedBlockSize); |
|
| 335 | - // check if $data fits in current block |
|
| 336 | - // if so, overwrite existing data (if any) |
|
| 337 | - // update position and liberate $data |
|
| 338 | - if ($remainingLength < ($this->unencryptedBlockSize - $blockPosition)) { |
|
| 339 | - $this->cache = substr($this->cache, 0, $blockPosition) |
|
| 340 | - . $data . substr($this->cache, $blockPosition + $remainingLength); |
|
| 341 | - $this->position += $remainingLength; |
|
| 342 | - $length += $remainingLength; |
|
| 343 | - $data = ''; |
|
| 344 | - // if $data doesn't fit the current block, the fill the current block and reiterate |
|
| 345 | - // after the block is filled, it is flushed and $data is updatedxxx |
|
| 346 | - } else { |
|
| 347 | - $this->cache = substr($this->cache, 0, $blockPosition) . |
|
| 348 | - substr($data, 0, $this->unencryptedBlockSize - $blockPosition); |
|
| 349 | - $this->flush(); |
|
| 350 | - $this->position += ($this->unencryptedBlockSize - $blockPosition); |
|
| 351 | - $length += ($this->unencryptedBlockSize - $blockPosition); |
|
| 352 | - $data = substr($data, $this->unencryptedBlockSize - $blockPosition); |
|
| 353 | - } |
|
| 354 | - } else { |
|
| 355 | - $data = ''; |
|
| 356 | - } |
|
| 357 | - $this->unencryptedSize = max($this->unencryptedSize, $this->position); |
|
| 358 | - } |
|
| 359 | - return $length; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public function stream_tell() { |
|
| 363 | - return $this->position; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - public function stream_seek($offset, $whence = SEEK_SET) { |
|
| 367 | - |
|
| 368 | - $return = false; |
|
| 369 | - |
|
| 370 | - switch ($whence) { |
|
| 371 | - case SEEK_SET: |
|
| 372 | - $newPosition = $offset; |
|
| 373 | - break; |
|
| 374 | - case SEEK_CUR: |
|
| 375 | - $newPosition = $this->position + $offset; |
|
| 376 | - break; |
|
| 377 | - case SEEK_END: |
|
| 378 | - $newPosition = $this->unencryptedSize + $offset; |
|
| 379 | - break; |
|
| 380 | - default: |
|
| 381 | - return $return; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ($newPosition > $this->unencryptedSize || $newPosition < 0) { |
|
| 385 | - return $return; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $newFilePosition = floor($newPosition / $this->unencryptedBlockSize) |
|
| 389 | - * $this->util->getBlockSize() + $this->headerSize; |
|
| 390 | - |
|
| 391 | - $oldFilePosition = parent::stream_tell(); |
|
| 392 | - if ($this->parentStreamSeek($newFilePosition)) { |
|
| 393 | - $this->parentStreamSeek($oldFilePosition); |
|
| 394 | - $this->flush(); |
|
| 395 | - $this->parentStreamSeek($newFilePosition); |
|
| 396 | - $this->position = $newPosition; |
|
| 397 | - $return = true; |
|
| 398 | - } |
|
| 399 | - return $return; |
|
| 400 | - |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - public function stream_close() { |
|
| 404 | - $this->flush('end'); |
|
| 405 | - $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 406 | - $remainingData = $this->encryptionModule->end($this->fullPath, $position . 'end'); |
|
| 407 | - if ($this->readOnly === false) { |
|
| 408 | - if(!empty($remainingData)) { |
|
| 409 | - parent::stream_write($remainingData); |
|
| 410 | - } |
|
| 411 | - $this->encryptionStorage->updateUnencryptedSize($this->fullPath, $this->unencryptedSize); |
|
| 412 | - } |
|
| 413 | - return parent::stream_close(); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * write block to file |
|
| 418 | - * @param string $positionPrefix |
|
| 419 | - */ |
|
| 420 | - protected function flush($positionPrefix = '') { |
|
| 421 | - // write to disk only when writeFlag was set to 1 |
|
| 422 | - if ($this->writeFlag) { |
|
| 423 | - // Disable the file proxies so that encryption is not |
|
| 424 | - // automatically attempted when the file is written to disk - |
|
| 425 | - // we are handling that separately here and we don't want to |
|
| 426 | - // get into an infinite loop |
|
| 427 | - $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 428 | - $encrypted = $this->encryptionModule->encrypt($this->cache, $position . $positionPrefix); |
|
| 429 | - $bytesWritten = parent::stream_write($encrypted); |
|
| 430 | - $this->writeFlag = false; |
|
| 431 | - // Check whether the write concerns the last block |
|
| 432 | - // If so then update the encrypted filesize |
|
| 433 | - // Note that the unencrypted pointer and filesize are NOT yet updated when flush() is called |
|
| 434 | - // We recalculate the encrypted filesize as we do not know the context of calling flush() |
|
| 435 | - $completeBlocksInFile=(int)floor($this->unencryptedSize/$this->unencryptedBlockSize); |
|
| 436 | - if ($completeBlocksInFile === (int)floor($this->position/$this->unencryptedBlockSize)) { |
|
| 437 | - $this->size = $this->util->getBlockSize() * $completeBlocksInFile; |
|
| 438 | - $this->size += $bytesWritten; |
|
| 439 | - $this->size += $this->headerSize; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - // always empty the cache (otherwise readCache() will not fill it with the new block) |
|
| 443 | - $this->cache = ''; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * read block to file |
|
| 448 | - */ |
|
| 449 | - protected function readCache() { |
|
| 450 | - // cache should always be empty string when this function is called |
|
| 451 | - // don't try to fill the cache when trying to write at the end of the unencrypted file when it coincides with new block |
|
| 452 | - if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) { |
|
| 453 | - // Get the data from the file handle |
|
| 454 | - $data = parent::stream_read($this->util->getBlockSize()); |
|
| 455 | - $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 456 | - $numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize); |
|
| 457 | - if($numberOfChunks === $position) { |
|
| 458 | - $position .= 'end'; |
|
| 459 | - } |
|
| 460 | - $this->cache = $this->encryptionModule->decrypt($data, $position); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * write header at beginning of encrypted file |
|
| 466 | - * |
|
| 467 | - * @return integer |
|
| 468 | - * @throws EncryptionHeaderKeyExistsException if header key is already in use |
|
| 469 | - */ |
|
| 470 | - protected function writeHeader() { |
|
| 471 | - $header = $this->util->createHeader($this->newHeader, $this->encryptionModule); |
|
| 472 | - return parent::stream_write($header); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * read first block to skip the header |
|
| 477 | - */ |
|
| 478 | - protected function skipHeader() { |
|
| 479 | - parent::stream_read($this->headerSize); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * call stream_seek() from parent class |
|
| 484 | - * |
|
| 485 | - * @param integer $position |
|
| 486 | - * @return bool |
|
| 487 | - */ |
|
| 488 | - protected function parentStreamSeek($position) { |
|
| 489 | - return parent::stream_seek($position); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @param string $path |
|
| 494 | - * @param array $options |
|
| 495 | - * @return bool |
|
| 496 | - */ |
|
| 497 | - public function dir_opendir($path, $options) { |
|
| 498 | - return false; |
|
| 499 | - } |
|
| 35 | + /** @var \OC\Encryption\Util */ |
|
| 36 | + protected $util; |
|
| 37 | + |
|
| 38 | + /** @var \OC\Encryption\File */ |
|
| 39 | + protected $file; |
|
| 40 | + |
|
| 41 | + /** @var \OCP\Encryption\IEncryptionModule */ |
|
| 42 | + protected $encryptionModule; |
|
| 43 | + |
|
| 44 | + /** @var \OC\Files\Storage\Storage */ |
|
| 45 | + protected $storage; |
|
| 46 | + |
|
| 47 | + /** @var \OC\Files\Storage\Wrapper\Encryption */ |
|
| 48 | + protected $encryptionStorage; |
|
| 49 | + |
|
| 50 | + /** @var string */ |
|
| 51 | + protected $internalPath; |
|
| 52 | + |
|
| 53 | + /** @var string */ |
|
| 54 | + protected $cache; |
|
| 55 | + |
|
| 56 | + /** @var integer */ |
|
| 57 | + protected $size; |
|
| 58 | + |
|
| 59 | + /** @var integer */ |
|
| 60 | + protected $position; |
|
| 61 | + |
|
| 62 | + /** @var integer */ |
|
| 63 | + protected $unencryptedSize; |
|
| 64 | + |
|
| 65 | + /** @var integer */ |
|
| 66 | + protected $headerSize; |
|
| 67 | + |
|
| 68 | + /** @var integer */ |
|
| 69 | + protected $unencryptedBlockSize; |
|
| 70 | + |
|
| 71 | + /** @var array */ |
|
| 72 | + protected $header; |
|
| 73 | + |
|
| 74 | + /** @var string */ |
|
| 75 | + protected $fullPath; |
|
| 76 | + |
|
| 77 | + /** @var bool */ |
|
| 78 | + protected $signed; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * header data returned by the encryption module, will be written to the file |
|
| 82 | + * in case of a write operation |
|
| 83 | + * |
|
| 84 | + * @var array |
|
| 85 | + */ |
|
| 86 | + protected $newHeader; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * user who perform the read/write operation null for public access |
|
| 90 | + * |
|
| 91 | + * @var string |
|
| 92 | + */ |
|
| 93 | + protected $uid; |
|
| 94 | + |
|
| 95 | + /** @var bool */ |
|
| 96 | + protected $readOnly; |
|
| 97 | + |
|
| 98 | + /** @var bool */ |
|
| 99 | + protected $writeFlag; |
|
| 100 | + |
|
| 101 | + /** @var array */ |
|
| 102 | + protected $expectedContextProperties; |
|
| 103 | + |
|
| 104 | + public function __construct() { |
|
| 105 | + $this->expectedContextProperties = array( |
|
| 106 | + 'source', |
|
| 107 | + 'storage', |
|
| 108 | + 'internalPath', |
|
| 109 | + 'fullPath', |
|
| 110 | + 'encryptionModule', |
|
| 111 | + 'header', |
|
| 112 | + 'uid', |
|
| 113 | + 'file', |
|
| 114 | + 'util', |
|
| 115 | + 'size', |
|
| 116 | + 'unencryptedSize', |
|
| 117 | + 'encryptionStorage', |
|
| 118 | + 'headerSize', |
|
| 119 | + 'signed' |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Wraps a stream with the provided callbacks |
|
| 126 | + * |
|
| 127 | + * @param resource $source |
|
| 128 | + * @param string $internalPath relative to mount point |
|
| 129 | + * @param string $fullPath relative to data/ |
|
| 130 | + * @param array $header |
|
| 131 | + * @param string $uid |
|
| 132 | + * @param \OCP\Encryption\IEncryptionModule $encryptionModule |
|
| 133 | + * @param \OC\Files\Storage\Storage $storage |
|
| 134 | + * @param \OC\Files\Storage\Wrapper\Encryption $encStorage |
|
| 135 | + * @param \OC\Encryption\Util $util |
|
| 136 | + * @param \OC\Encryption\File $file |
|
| 137 | + * @param string $mode |
|
| 138 | + * @param int $size |
|
| 139 | + * @param int $unencryptedSize |
|
| 140 | + * @param int $headerSize |
|
| 141 | + * @param bool $signed |
|
| 142 | + * @param string $wrapper stream wrapper class |
|
| 143 | + * @return resource |
|
| 144 | + * |
|
| 145 | + * @throws \BadMethodCallException |
|
| 146 | + */ |
|
| 147 | + public static function wrap($source, $internalPath, $fullPath, array $header, |
|
| 148 | + $uid, |
|
| 149 | + \OCP\Encryption\IEncryptionModule $encryptionModule, |
|
| 150 | + \OC\Files\Storage\Storage $storage, |
|
| 151 | + \OC\Files\Storage\Wrapper\Encryption $encStorage, |
|
| 152 | + \OC\Encryption\Util $util, |
|
| 153 | + \OC\Encryption\File $file, |
|
| 154 | + $mode, |
|
| 155 | + $size, |
|
| 156 | + $unencryptedSize, |
|
| 157 | + $headerSize, |
|
| 158 | + $signed, |
|
| 159 | + $wrapper = 'OC\Files\Stream\Encryption') { |
|
| 160 | + |
|
| 161 | + $context = stream_context_create(array( |
|
| 162 | + 'ocencryption' => array( |
|
| 163 | + 'source' => $source, |
|
| 164 | + 'storage' => $storage, |
|
| 165 | + 'internalPath' => $internalPath, |
|
| 166 | + 'fullPath' => $fullPath, |
|
| 167 | + 'encryptionModule' => $encryptionModule, |
|
| 168 | + 'header' => $header, |
|
| 169 | + 'uid' => $uid, |
|
| 170 | + 'util' => $util, |
|
| 171 | + 'file' => $file, |
|
| 172 | + 'size' => $size, |
|
| 173 | + 'unencryptedSize' => $unencryptedSize, |
|
| 174 | + 'encryptionStorage' => $encStorage, |
|
| 175 | + 'headerSize' => $headerSize, |
|
| 176 | + 'signed' => $signed |
|
| 177 | + ) |
|
| 178 | + )); |
|
| 179 | + |
|
| 180 | + return self::wrapSource($source, $context, 'ocencryption', $wrapper, $mode); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * add stream wrapper |
|
| 185 | + * |
|
| 186 | + * @param resource $source |
|
| 187 | + * @param string $mode |
|
| 188 | + * @param resource $context |
|
| 189 | + * @param string $protocol |
|
| 190 | + * @param string $class |
|
| 191 | + * @return resource |
|
| 192 | + * @throws \BadMethodCallException |
|
| 193 | + */ |
|
| 194 | + protected static function wrapSource($source, $context, $protocol, $class, $mode = 'r+') { |
|
| 195 | + try { |
|
| 196 | + stream_wrapper_register($protocol, $class); |
|
| 197 | + if (@rewinddir($source) === false) { |
|
| 198 | + $wrapped = fopen($protocol . '://', $mode, false, $context); |
|
| 199 | + } else { |
|
| 200 | + $wrapped = opendir($protocol . '://', $context); |
|
| 201 | + } |
|
| 202 | + } catch (\BadMethodCallException $e) { |
|
| 203 | + stream_wrapper_unregister($protocol); |
|
| 204 | + throw $e; |
|
| 205 | + } |
|
| 206 | + stream_wrapper_unregister($protocol); |
|
| 207 | + return $wrapped; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Load the source from the stream context and return the context options |
|
| 212 | + * |
|
| 213 | + * @param string $name |
|
| 214 | + * @return array |
|
| 215 | + * @throws \BadMethodCallException |
|
| 216 | + */ |
|
| 217 | + protected function loadContext($name) { |
|
| 218 | + $context = parent::loadContext($name); |
|
| 219 | + |
|
| 220 | + foreach ($this->expectedContextProperties as $property) { |
|
| 221 | + if (array_key_exists($property, $context)) { |
|
| 222 | + $this->{$property} = $context[$property]; |
|
| 223 | + } else { |
|
| 224 | + throw new \BadMethodCallException('Invalid context, "' . $property . '" options not set'); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + return $context; |
|
| 228 | + |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + public function stream_open($path, $mode, $options, &$opened_path) { |
|
| 232 | + $this->loadContext('ocencryption'); |
|
| 233 | + |
|
| 234 | + $this->position = 0; |
|
| 235 | + $this->cache = ''; |
|
| 236 | + $this->writeFlag = false; |
|
| 237 | + $this->unencryptedBlockSize = $this->encryptionModule->getUnencryptedBlockSize($this->signed); |
|
| 238 | + |
|
| 239 | + if ( |
|
| 240 | + $mode === 'w' |
|
| 241 | + || $mode === 'w+' |
|
| 242 | + || $mode === 'wb' |
|
| 243 | + || $mode === 'wb+' |
|
| 244 | + || $mode === 'r+' |
|
| 245 | + || $mode === 'rb+' |
|
| 246 | + ) { |
|
| 247 | + $this->readOnly = false; |
|
| 248 | + } else { |
|
| 249 | + $this->readOnly = true; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $sharePath = $this->fullPath; |
|
| 253 | + if (!$this->storage->file_exists($this->internalPath)) { |
|
| 254 | + $sharePath = dirname($sharePath); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $accessList = $this->file->getAccessList($sharePath); |
|
| 258 | + $this->newHeader = $this->encryptionModule->begin($this->fullPath, $this->uid, $mode, $this->header, $accessList); |
|
| 259 | + |
|
| 260 | + if ( |
|
| 261 | + $mode === 'w' |
|
| 262 | + || $mode === 'w+' |
|
| 263 | + || $mode === 'wb' |
|
| 264 | + || $mode === 'wb+' |
|
| 265 | + ) { |
|
| 266 | + // We're writing a new file so start write counter with 0 bytes |
|
| 267 | + $this->unencryptedSize = 0; |
|
| 268 | + $this->writeHeader(); |
|
| 269 | + $this->headerSize = $this->util->getHeaderSize(); |
|
| 270 | + $this->size = $this->headerSize; |
|
| 271 | + } else { |
|
| 272 | + $this->skipHeader(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return true; |
|
| 276 | + |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + public function stream_eof() { |
|
| 280 | + return $this->position >= $this->unencryptedSize; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + public function stream_read($count) { |
|
| 284 | + |
|
| 285 | + $result = ''; |
|
| 286 | + |
|
| 287 | + $count = min($count, $this->unencryptedSize - $this->position); |
|
| 288 | + while ($count > 0) { |
|
| 289 | + $remainingLength = $count; |
|
| 290 | + // update the cache of the current block |
|
| 291 | + $this->readCache(); |
|
| 292 | + // determine the relative position in the current block |
|
| 293 | + $blockPosition = ($this->position % $this->unencryptedBlockSize); |
|
| 294 | + // if entire read inside current block then only position needs to be updated |
|
| 295 | + if ($remainingLength < ($this->unencryptedBlockSize - $blockPosition)) { |
|
| 296 | + $result .= substr($this->cache, $blockPosition, $remainingLength); |
|
| 297 | + $this->position += $remainingLength; |
|
| 298 | + $count = 0; |
|
| 299 | + // otherwise remainder of current block is fetched, the block is flushed and the position updated |
|
| 300 | + } else { |
|
| 301 | + $result .= substr($this->cache, $blockPosition); |
|
| 302 | + $this->flush(); |
|
| 303 | + $this->position += ($this->unencryptedBlockSize - $blockPosition); |
|
| 304 | + $count -= ($this->unencryptedBlockSize - $blockPosition); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + return $result; |
|
| 308 | + |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + public function stream_write($data) { |
|
| 312 | + |
|
| 313 | + $length = 0; |
|
| 314 | + // loop over $data to fit it in 6126 sized unencrypted blocks |
|
| 315 | + while (isset($data[0])) { |
|
| 316 | + $remainingLength = strlen($data); |
|
| 317 | + |
|
| 318 | + // set the cache to the current 6126 block |
|
| 319 | + $this->readCache(); |
|
| 320 | + |
|
| 321 | + // for seekable streams the pointer is moved back to the beginning of the encrypted block |
|
| 322 | + // flush will start writing there when the position moves to another block |
|
| 323 | + $positionInFile = (int)floor($this->position / $this->unencryptedBlockSize) * |
|
| 324 | + $this->util->getBlockSize() + $this->headerSize; |
|
| 325 | + $resultFseek = $this->parentStreamSeek($positionInFile); |
|
| 326 | + |
|
| 327 | + // only allow writes on seekable streams, or at the end of the encrypted stream |
|
| 328 | + if (!($this->readOnly) && ($resultFseek || $positionInFile === $this->size)) { |
|
| 329 | + |
|
| 330 | + // switch the writeFlag so flush() will write the block |
|
| 331 | + $this->writeFlag = true; |
|
| 332 | + |
|
| 333 | + // determine the relative position in the current block |
|
| 334 | + $blockPosition = ($this->position % $this->unencryptedBlockSize); |
|
| 335 | + // check if $data fits in current block |
|
| 336 | + // if so, overwrite existing data (if any) |
|
| 337 | + // update position and liberate $data |
|
| 338 | + if ($remainingLength < ($this->unencryptedBlockSize - $blockPosition)) { |
|
| 339 | + $this->cache = substr($this->cache, 0, $blockPosition) |
|
| 340 | + . $data . substr($this->cache, $blockPosition + $remainingLength); |
|
| 341 | + $this->position += $remainingLength; |
|
| 342 | + $length += $remainingLength; |
|
| 343 | + $data = ''; |
|
| 344 | + // if $data doesn't fit the current block, the fill the current block and reiterate |
|
| 345 | + // after the block is filled, it is flushed and $data is updatedxxx |
|
| 346 | + } else { |
|
| 347 | + $this->cache = substr($this->cache, 0, $blockPosition) . |
|
| 348 | + substr($data, 0, $this->unencryptedBlockSize - $blockPosition); |
|
| 349 | + $this->flush(); |
|
| 350 | + $this->position += ($this->unencryptedBlockSize - $blockPosition); |
|
| 351 | + $length += ($this->unencryptedBlockSize - $blockPosition); |
|
| 352 | + $data = substr($data, $this->unencryptedBlockSize - $blockPosition); |
|
| 353 | + } |
|
| 354 | + } else { |
|
| 355 | + $data = ''; |
|
| 356 | + } |
|
| 357 | + $this->unencryptedSize = max($this->unencryptedSize, $this->position); |
|
| 358 | + } |
|
| 359 | + return $length; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public function stream_tell() { |
|
| 363 | + return $this->position; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + public function stream_seek($offset, $whence = SEEK_SET) { |
|
| 367 | + |
|
| 368 | + $return = false; |
|
| 369 | + |
|
| 370 | + switch ($whence) { |
|
| 371 | + case SEEK_SET: |
|
| 372 | + $newPosition = $offset; |
|
| 373 | + break; |
|
| 374 | + case SEEK_CUR: |
|
| 375 | + $newPosition = $this->position + $offset; |
|
| 376 | + break; |
|
| 377 | + case SEEK_END: |
|
| 378 | + $newPosition = $this->unencryptedSize + $offset; |
|
| 379 | + break; |
|
| 380 | + default: |
|
| 381 | + return $return; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ($newPosition > $this->unencryptedSize || $newPosition < 0) { |
|
| 385 | + return $return; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $newFilePosition = floor($newPosition / $this->unencryptedBlockSize) |
|
| 389 | + * $this->util->getBlockSize() + $this->headerSize; |
|
| 390 | + |
|
| 391 | + $oldFilePosition = parent::stream_tell(); |
|
| 392 | + if ($this->parentStreamSeek($newFilePosition)) { |
|
| 393 | + $this->parentStreamSeek($oldFilePosition); |
|
| 394 | + $this->flush(); |
|
| 395 | + $this->parentStreamSeek($newFilePosition); |
|
| 396 | + $this->position = $newPosition; |
|
| 397 | + $return = true; |
|
| 398 | + } |
|
| 399 | + return $return; |
|
| 400 | + |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + public function stream_close() { |
|
| 404 | + $this->flush('end'); |
|
| 405 | + $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 406 | + $remainingData = $this->encryptionModule->end($this->fullPath, $position . 'end'); |
|
| 407 | + if ($this->readOnly === false) { |
|
| 408 | + if(!empty($remainingData)) { |
|
| 409 | + parent::stream_write($remainingData); |
|
| 410 | + } |
|
| 411 | + $this->encryptionStorage->updateUnencryptedSize($this->fullPath, $this->unencryptedSize); |
|
| 412 | + } |
|
| 413 | + return parent::stream_close(); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * write block to file |
|
| 418 | + * @param string $positionPrefix |
|
| 419 | + */ |
|
| 420 | + protected function flush($positionPrefix = '') { |
|
| 421 | + // write to disk only when writeFlag was set to 1 |
|
| 422 | + if ($this->writeFlag) { |
|
| 423 | + // Disable the file proxies so that encryption is not |
|
| 424 | + // automatically attempted when the file is written to disk - |
|
| 425 | + // we are handling that separately here and we don't want to |
|
| 426 | + // get into an infinite loop |
|
| 427 | + $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 428 | + $encrypted = $this->encryptionModule->encrypt($this->cache, $position . $positionPrefix); |
|
| 429 | + $bytesWritten = parent::stream_write($encrypted); |
|
| 430 | + $this->writeFlag = false; |
|
| 431 | + // Check whether the write concerns the last block |
|
| 432 | + // If so then update the encrypted filesize |
|
| 433 | + // Note that the unencrypted pointer and filesize are NOT yet updated when flush() is called |
|
| 434 | + // We recalculate the encrypted filesize as we do not know the context of calling flush() |
|
| 435 | + $completeBlocksInFile=(int)floor($this->unencryptedSize/$this->unencryptedBlockSize); |
|
| 436 | + if ($completeBlocksInFile === (int)floor($this->position/$this->unencryptedBlockSize)) { |
|
| 437 | + $this->size = $this->util->getBlockSize() * $completeBlocksInFile; |
|
| 438 | + $this->size += $bytesWritten; |
|
| 439 | + $this->size += $this->headerSize; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + // always empty the cache (otherwise readCache() will not fill it with the new block) |
|
| 443 | + $this->cache = ''; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * read block to file |
|
| 448 | + */ |
|
| 449 | + protected function readCache() { |
|
| 450 | + // cache should always be empty string when this function is called |
|
| 451 | + // don't try to fill the cache when trying to write at the end of the unencrypted file when it coincides with new block |
|
| 452 | + if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) { |
|
| 453 | + // Get the data from the file handle |
|
| 454 | + $data = parent::stream_read($this->util->getBlockSize()); |
|
| 455 | + $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 456 | + $numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize); |
|
| 457 | + if($numberOfChunks === $position) { |
|
| 458 | + $position .= 'end'; |
|
| 459 | + } |
|
| 460 | + $this->cache = $this->encryptionModule->decrypt($data, $position); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * write header at beginning of encrypted file |
|
| 466 | + * |
|
| 467 | + * @return integer |
|
| 468 | + * @throws EncryptionHeaderKeyExistsException if header key is already in use |
|
| 469 | + */ |
|
| 470 | + protected function writeHeader() { |
|
| 471 | + $header = $this->util->createHeader($this->newHeader, $this->encryptionModule); |
|
| 472 | + return parent::stream_write($header); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * read first block to skip the header |
|
| 477 | + */ |
|
| 478 | + protected function skipHeader() { |
|
| 479 | + parent::stream_read($this->headerSize); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * call stream_seek() from parent class |
|
| 484 | + * |
|
| 485 | + * @param integer $position |
|
| 486 | + * @return bool |
|
| 487 | + */ |
|
| 488 | + protected function parentStreamSeek($position) { |
|
| 489 | + return parent::stream_seek($position); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @param string $path |
|
| 494 | + * @param array $options |
|
| 495 | + * @return bool |
|
| 496 | + */ |
|
| 497 | + public function dir_opendir($path, $options) { |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | 501 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $unencryptedSize, |
| 157 | 157 | $headerSize, |
| 158 | 158 | $signed, |
| 159 | - $wrapper = 'OC\Files\Stream\Encryption') { |
|
| 159 | + $wrapper = 'OC\Files\Stream\Encryption') { |
|
| 160 | 160 | |
| 161 | 161 | $context = stream_context_create(array( |
| 162 | 162 | 'ocencryption' => array( |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | try { |
| 196 | 196 | stream_wrapper_register($protocol, $class); |
| 197 | 197 | if (@rewinddir($source) === false) { |
| 198 | - $wrapped = fopen($protocol . '://', $mode, false, $context); |
|
| 198 | + $wrapped = fopen($protocol.'://', $mode, false, $context); |
|
| 199 | 199 | } else { |
| 200 | - $wrapped = opendir($protocol . '://', $context); |
|
| 200 | + $wrapped = opendir($protocol.'://', $context); |
|
| 201 | 201 | } |
| 202 | 202 | } catch (\BadMethodCallException $e) { |
| 203 | 203 | stream_wrapper_unregister($protocol); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | if (array_key_exists($property, $context)) { |
| 222 | 222 | $this->{$property} = $context[$property]; |
| 223 | 223 | } else { |
| 224 | - throw new \BadMethodCallException('Invalid context, "' . $property . '" options not set'); |
|
| 224 | + throw new \BadMethodCallException('Invalid context, "'.$property.'" options not set'); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | return $context; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | // for seekable streams the pointer is moved back to the beginning of the encrypted block |
| 322 | 322 | // flush will start writing there when the position moves to another block |
| 323 | - $positionInFile = (int)floor($this->position / $this->unencryptedBlockSize) * |
|
| 323 | + $positionInFile = (int) floor($this->position / $this->unencryptedBlockSize) * |
|
| 324 | 324 | $this->util->getBlockSize() + $this->headerSize; |
| 325 | 325 | $resultFseek = $this->parentStreamSeek($positionInFile); |
| 326 | 326 | |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | // update position and liberate $data |
| 338 | 338 | if ($remainingLength < ($this->unencryptedBlockSize - $blockPosition)) { |
| 339 | 339 | $this->cache = substr($this->cache, 0, $blockPosition) |
| 340 | - . $data . substr($this->cache, $blockPosition + $remainingLength); |
|
| 340 | + . $data.substr($this->cache, $blockPosition + $remainingLength); |
|
| 341 | 341 | $this->position += $remainingLength; |
| 342 | 342 | $length += $remainingLength; |
| 343 | 343 | $data = ''; |
| 344 | 344 | // if $data doesn't fit the current block, the fill the current block and reiterate |
| 345 | 345 | // after the block is filled, it is flushed and $data is updatedxxx |
| 346 | 346 | } else { |
| 347 | - $this->cache = substr($this->cache, 0, $blockPosition) . |
|
| 347 | + $this->cache = substr($this->cache, 0, $blockPosition). |
|
| 348 | 348 | substr($data, 0, $this->unencryptedBlockSize - $blockPosition); |
| 349 | 349 | $this->flush(); |
| 350 | 350 | $this->position += ($this->unencryptedBlockSize - $blockPosition); |
@@ -402,10 +402,10 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | public function stream_close() { |
| 404 | 404 | $this->flush('end'); |
| 405 | - $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 406 | - $remainingData = $this->encryptionModule->end($this->fullPath, $position . 'end'); |
|
| 405 | + $position = (int) floor($this->position / $this->unencryptedBlockSize); |
|
| 406 | + $remainingData = $this->encryptionModule->end($this->fullPath, $position.'end'); |
|
| 407 | 407 | if ($this->readOnly === false) { |
| 408 | - if(!empty($remainingData)) { |
|
| 408 | + if (!empty($remainingData)) { |
|
| 409 | 409 | parent::stream_write($remainingData); |
| 410 | 410 | } |
| 411 | 411 | $this->encryptionStorage->updateUnencryptedSize($this->fullPath, $this->unencryptedSize); |
@@ -424,16 +424,16 @@ discard block |
||
| 424 | 424 | // automatically attempted when the file is written to disk - |
| 425 | 425 | // we are handling that separately here and we don't want to |
| 426 | 426 | // get into an infinite loop |
| 427 | - $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 428 | - $encrypted = $this->encryptionModule->encrypt($this->cache, $position . $positionPrefix); |
|
| 427 | + $position = (int) floor($this->position / $this->unencryptedBlockSize); |
|
| 428 | + $encrypted = $this->encryptionModule->encrypt($this->cache, $position.$positionPrefix); |
|
| 429 | 429 | $bytesWritten = parent::stream_write($encrypted); |
| 430 | 430 | $this->writeFlag = false; |
| 431 | 431 | // Check whether the write concerns the last block |
| 432 | 432 | // If so then update the encrypted filesize |
| 433 | 433 | // Note that the unencrypted pointer and filesize are NOT yet updated when flush() is called |
| 434 | 434 | // We recalculate the encrypted filesize as we do not know the context of calling flush() |
| 435 | - $completeBlocksInFile=(int)floor($this->unencryptedSize/$this->unencryptedBlockSize); |
|
| 436 | - if ($completeBlocksInFile === (int)floor($this->position/$this->unencryptedBlockSize)) { |
|
| 435 | + $completeBlocksInFile = (int) floor($this->unencryptedSize / $this->unencryptedBlockSize); |
|
| 436 | + if ($completeBlocksInFile === (int) floor($this->position / $this->unencryptedBlockSize)) { |
|
| 437 | 437 | $this->size = $this->util->getBlockSize() * $completeBlocksInFile; |
| 438 | 438 | $this->size += $bytesWritten; |
| 439 | 439 | $this->size += $this->headerSize; |
@@ -452,9 +452,9 @@ discard block |
||
| 452 | 452 | if ($this->cache === '' && !($this->position === $this->unencryptedSize && ($this->position % $this->unencryptedBlockSize) === 0)) { |
| 453 | 453 | // Get the data from the file handle |
| 454 | 454 | $data = parent::stream_read($this->util->getBlockSize()); |
| 455 | - $position = (int)floor($this->position/$this->unencryptedBlockSize); |
|
| 456 | - $numberOfChunks = (int)($this->unencryptedSize / $this->unencryptedBlockSize); |
|
| 457 | - if($numberOfChunks === $position) { |
|
| 455 | + $position = (int) floor($this->position / $this->unencryptedBlockSize); |
|
| 456 | + $numberOfChunks = (int) ($this->unencryptedSize / $this->unencryptedBlockSize); |
|
| 457 | + if ($numberOfChunks === $position) { |
|
| 458 | 458 | $position .= 'end'; |
| 459 | 459 | } |
| 460 | 460 | $this->cache = $this->encryptionModule->decrypt($data, $position); |