@@ -55,187 +55,187 @@ |
||
| 55 | 55 | |
| 56 | 56 | class Server { |
| 57 | 57 | |
| 58 | - /** @var IRequest */ |
|
| 59 | - private $request; |
|
| 60 | - |
|
| 61 | - /** @var string */ |
|
| 62 | - private $baseUri; |
|
| 63 | - |
|
| 64 | - /** @var Connector\Sabre\Server */ |
|
| 65 | - private $server; |
|
| 66 | - |
|
| 67 | - public function __construct(IRequest $request, $baseUri) { |
|
| 68 | - $this->request = $request; |
|
| 69 | - $this->baseUri = $baseUri; |
|
| 70 | - $logger = \OC::$server->getLogger(); |
|
| 71 | - $mailer = \OC::$server->getMailer(); |
|
| 72 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 73 | - |
|
| 74 | - $root = new RootCollection(); |
|
| 75 | - $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
| 76 | - |
|
| 77 | - // Backends |
|
| 78 | - $authBackend = new Auth( |
|
| 79 | - \OC::$server->getSession(), |
|
| 80 | - \OC::$server->getUserSession(), |
|
| 81 | - \OC::$server->getRequest(), |
|
| 82 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 83 | - \OC::$server->getBruteForceThrottler() |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - // Set URL explicitly due to reverse-proxy situations |
|
| 87 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 88 | - $this->server->setBaseUri($this->baseUri); |
|
| 89 | - |
|
| 90 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 91 | - $authPlugin = new Plugin(); |
|
| 92 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 93 | - $this->server->addPlugin($authPlugin); |
|
| 94 | - |
|
| 95 | - // allow setup of additional auth backends |
|
| 96 | - $event = new SabrePluginEvent($this->server); |
|
| 97 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 98 | - |
|
| 99 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 100 | - $authPlugin->addBackend($authBackend); |
|
| 101 | - |
|
| 102 | - // debugging |
|
| 103 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 104 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 105 | - } else { |
|
| 106 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 110 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 111 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 112 | - |
|
| 113 | - // acl |
|
| 114 | - $acl = new DavAclPlugin(); |
|
| 115 | - $acl->principalCollectionSet = [ |
|
| 116 | - 'principals/users', 'principals/groups' |
|
| 117 | - ]; |
|
| 118 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 119 | - $this->server->addPlugin($acl); |
|
| 120 | - |
|
| 121 | - // calendar plugins |
|
| 122 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 123 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 124 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 125 | - $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 126 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 127 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 128 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 129 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 130 | - \OC::$server->getConfig(), |
|
| 131 | - \OC::$server->getURLGenerator() |
|
| 132 | - )); |
|
| 133 | - |
|
| 134 | - // addressbook plugins |
|
| 135 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 136 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 137 | - $this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger())); |
|
| 138 | - |
|
| 139 | - // system tags plugins |
|
| 140 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 141 | - \OC::$server->getSystemTagManager(), |
|
| 142 | - \OC::$server->getGroupManager(), |
|
| 143 | - \OC::$server->getUserSession() |
|
| 144 | - )); |
|
| 145 | - |
|
| 146 | - // comments plugin |
|
| 147 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 148 | - \OC::$server->getCommentsManager(), |
|
| 149 | - \OC::$server->getUserSession() |
|
| 150 | - )); |
|
| 151 | - |
|
| 152 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 153 | - |
|
| 154 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 155 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 156 | - if($request->isUserAgent([ |
|
| 157 | - '/WebDAVFS/', |
|
| 158 | - '/Microsoft Office OneNote 2013/', |
|
| 159 | - ])) { |
|
| 160 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 164 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 168 | - $this->server->on('beforeMethod', function () { |
|
| 169 | - // custom properties plugin must be the last one |
|
| 170 | - $userSession = \OC::$server->getUserSession(); |
|
| 171 | - $user = $userSession->getUser(); |
|
| 172 | - if ($user !== null) { |
|
| 173 | - $view = \OC\Files\Filesystem::getView(); |
|
| 174 | - $this->server->addPlugin( |
|
| 175 | - new FilesPlugin( |
|
| 176 | - $this->server->tree, |
|
| 177 | - \OC::$server->getConfig(), |
|
| 178 | - $this->request, |
|
| 179 | - \OC::$server->getPreviewManager(), |
|
| 180 | - false, |
|
| 181 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 182 | - ) |
|
| 183 | - ); |
|
| 184 | - |
|
| 185 | - $this->server->addPlugin( |
|
| 186 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 187 | - new CustomPropertiesBackend( |
|
| 188 | - $this->server->tree, |
|
| 189 | - \OC::$server->getDatabaseConnection(), |
|
| 190 | - \OC::$server->getUserSession()->getUser() |
|
| 191 | - ) |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - if ($view !== null) { |
|
| 195 | - $this->server->addPlugin( |
|
| 196 | - new QuotaPlugin($view)); |
|
| 197 | - } |
|
| 198 | - $this->server->addPlugin( |
|
| 199 | - new TagsPlugin( |
|
| 200 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 201 | - ) |
|
| 202 | - ); |
|
| 203 | - // TODO: switch to LazyUserFolder |
|
| 204 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 205 | - $this->server->addPlugin(new SharesPlugin( |
|
| 206 | - $this->server->tree, |
|
| 207 | - $userSession, |
|
| 208 | - $userFolder, |
|
| 209 | - \OC::$server->getShareManager() |
|
| 210 | - )); |
|
| 211 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 212 | - \OC::$server->getCommentsManager(), |
|
| 213 | - $userSession |
|
| 214 | - )); |
|
| 215 | - if ($view !== null) { |
|
| 216 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 217 | - $this->server->tree, |
|
| 218 | - $view, |
|
| 219 | - \OC::$server->getSystemTagManager(), |
|
| 220 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 221 | - \OC::$server->getTagManager(), |
|
| 222 | - $userSession, |
|
| 223 | - \OC::$server->getGroupManager(), |
|
| 224 | - $userFolder |
|
| 225 | - )); |
|
| 226 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 227 | - $this->server->tree, |
|
| 228 | - $user, |
|
| 229 | - \OC::$server->getRootFolder(), |
|
| 230 | - \OC::$server->getShareManager(), |
|
| 231 | - $view |
|
| 232 | - ))); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - }); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function exec() { |
|
| 239 | - $this->server->exec(); |
|
| 240 | - } |
|
| 58 | + /** @var IRequest */ |
|
| 59 | + private $request; |
|
| 60 | + |
|
| 61 | + /** @var string */ |
|
| 62 | + private $baseUri; |
|
| 63 | + |
|
| 64 | + /** @var Connector\Sabre\Server */ |
|
| 65 | + private $server; |
|
| 66 | + |
|
| 67 | + public function __construct(IRequest $request, $baseUri) { |
|
| 68 | + $this->request = $request; |
|
| 69 | + $this->baseUri = $baseUri; |
|
| 70 | + $logger = \OC::$server->getLogger(); |
|
| 71 | + $mailer = \OC::$server->getMailer(); |
|
| 72 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 73 | + |
|
| 74 | + $root = new RootCollection(); |
|
| 75 | + $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
| 76 | + |
|
| 77 | + // Backends |
|
| 78 | + $authBackend = new Auth( |
|
| 79 | + \OC::$server->getSession(), |
|
| 80 | + \OC::$server->getUserSession(), |
|
| 81 | + \OC::$server->getRequest(), |
|
| 82 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 83 | + \OC::$server->getBruteForceThrottler() |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + // Set URL explicitly due to reverse-proxy situations |
|
| 87 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 88 | + $this->server->setBaseUri($this->baseUri); |
|
| 89 | + |
|
| 90 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 91 | + $authPlugin = new Plugin(); |
|
| 92 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 93 | + $this->server->addPlugin($authPlugin); |
|
| 94 | + |
|
| 95 | + // allow setup of additional auth backends |
|
| 96 | + $event = new SabrePluginEvent($this->server); |
|
| 97 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 98 | + |
|
| 99 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 100 | + $authPlugin->addBackend($authBackend); |
|
| 101 | + |
|
| 102 | + // debugging |
|
| 103 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 104 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 105 | + } else { |
|
| 106 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 110 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 111 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 112 | + |
|
| 113 | + // acl |
|
| 114 | + $acl = new DavAclPlugin(); |
|
| 115 | + $acl->principalCollectionSet = [ |
|
| 116 | + 'principals/users', 'principals/groups' |
|
| 117 | + ]; |
|
| 118 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 119 | + $this->server->addPlugin($acl); |
|
| 120 | + |
|
| 121 | + // calendar plugins |
|
| 122 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 123 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 124 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 125 | + $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 126 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 127 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 128 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 129 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 130 | + \OC::$server->getConfig(), |
|
| 131 | + \OC::$server->getURLGenerator() |
|
| 132 | + )); |
|
| 133 | + |
|
| 134 | + // addressbook plugins |
|
| 135 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 136 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 137 | + $this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger())); |
|
| 138 | + |
|
| 139 | + // system tags plugins |
|
| 140 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 141 | + \OC::$server->getSystemTagManager(), |
|
| 142 | + \OC::$server->getGroupManager(), |
|
| 143 | + \OC::$server->getUserSession() |
|
| 144 | + )); |
|
| 145 | + |
|
| 146 | + // comments plugin |
|
| 147 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 148 | + \OC::$server->getCommentsManager(), |
|
| 149 | + \OC::$server->getUserSession() |
|
| 150 | + )); |
|
| 151 | + |
|
| 152 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 153 | + |
|
| 154 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 155 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 156 | + if($request->isUserAgent([ |
|
| 157 | + '/WebDAVFS/', |
|
| 158 | + '/Microsoft Office OneNote 2013/', |
|
| 159 | + ])) { |
|
| 160 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 164 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 168 | + $this->server->on('beforeMethod', function () { |
|
| 169 | + // custom properties plugin must be the last one |
|
| 170 | + $userSession = \OC::$server->getUserSession(); |
|
| 171 | + $user = $userSession->getUser(); |
|
| 172 | + if ($user !== null) { |
|
| 173 | + $view = \OC\Files\Filesystem::getView(); |
|
| 174 | + $this->server->addPlugin( |
|
| 175 | + new FilesPlugin( |
|
| 176 | + $this->server->tree, |
|
| 177 | + \OC::$server->getConfig(), |
|
| 178 | + $this->request, |
|
| 179 | + \OC::$server->getPreviewManager(), |
|
| 180 | + false, |
|
| 181 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 182 | + ) |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + $this->server->addPlugin( |
|
| 186 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 187 | + new CustomPropertiesBackend( |
|
| 188 | + $this->server->tree, |
|
| 189 | + \OC::$server->getDatabaseConnection(), |
|
| 190 | + \OC::$server->getUserSession()->getUser() |
|
| 191 | + ) |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + if ($view !== null) { |
|
| 195 | + $this->server->addPlugin( |
|
| 196 | + new QuotaPlugin($view)); |
|
| 197 | + } |
|
| 198 | + $this->server->addPlugin( |
|
| 199 | + new TagsPlugin( |
|
| 200 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 201 | + ) |
|
| 202 | + ); |
|
| 203 | + // TODO: switch to LazyUserFolder |
|
| 204 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 205 | + $this->server->addPlugin(new SharesPlugin( |
|
| 206 | + $this->server->tree, |
|
| 207 | + $userSession, |
|
| 208 | + $userFolder, |
|
| 209 | + \OC::$server->getShareManager() |
|
| 210 | + )); |
|
| 211 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 212 | + \OC::$server->getCommentsManager(), |
|
| 213 | + $userSession |
|
| 214 | + )); |
|
| 215 | + if ($view !== null) { |
|
| 216 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 217 | + $this->server->tree, |
|
| 218 | + $view, |
|
| 219 | + \OC::$server->getSystemTagManager(), |
|
| 220 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 221 | + \OC::$server->getTagManager(), |
|
| 222 | + $userSession, |
|
| 223 | + \OC::$server->getGroupManager(), |
|
| 224 | + $userFolder |
|
| 225 | + )); |
|
| 226 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 227 | + $this->server->tree, |
|
| 228 | + $user, |
|
| 229 | + \OC::$server->getRootFolder(), |
|
| 230 | + \OC::$server->getShareManager(), |
|
| 231 | + $view |
|
| 232 | + ))); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + }); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function exec() { |
|
| 239 | + $this->server->exec(); |
|
| 240 | + } |
|
| 241 | 241 | } |
@@ -25,22 +25,22 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchOrder { |
| 28 | - const DIRECTION_ASCENDING = 'asc'; |
|
| 29 | - const DIRECTION_DESCENDING = 'desc'; |
|
| 28 | + const DIRECTION_ASCENDING = 'asc'; |
|
| 29 | + const DIRECTION_DESCENDING = 'desc'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The direction to sort in, either ISearchOrder::DIRECTION_ASCENDING or ISearchOrder::DIRECTION_DESCENDING |
|
| 33 | - * |
|
| 34 | - * @return string |
|
| 35 | - * @since 12.0.0 |
|
| 36 | - */ |
|
| 37 | - public function getDirection(); |
|
| 31 | + /** |
|
| 32 | + * The direction to sort in, either ISearchOrder::DIRECTION_ASCENDING or ISearchOrder::DIRECTION_DESCENDING |
|
| 33 | + * |
|
| 34 | + * @return string |
|
| 35 | + * @since 12.0.0 |
|
| 36 | + */ |
|
| 37 | + public function getDirection(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * The field to sort on |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - * @since 12.0.0 |
|
| 44 | - */ |
|
| 45 | - public function getField(); |
|
| 39 | + /** |
|
| 40 | + * The field to sort on |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + * @since 12.0.0 |
|
| 44 | + */ |
|
| 45 | + public function getField(); |
|
| 46 | 46 | } |
@@ -25,36 +25,36 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchComparison extends ISearchOperator { |
| 28 | - const COMPARE_EQUAL = 'eq'; |
|
| 29 | - const COMPARE_GREATER_THAN = 'gt'; |
|
| 30 | - const COMPARE_GREATER_THAN_EQUAL = 'gte'; |
|
| 31 | - const COMPARE_LESS_THAN = 'lt'; |
|
| 32 | - const COMPARE_LESS_THAN_EQUAL = 'lte'; |
|
| 33 | - const COMPARE_LIKE = 'like'; |
|
| 28 | + const COMPARE_EQUAL = 'eq'; |
|
| 29 | + const COMPARE_GREATER_THAN = 'gt'; |
|
| 30 | + const COMPARE_GREATER_THAN_EQUAL = 'gte'; |
|
| 31 | + const COMPARE_LESS_THAN = 'lt'; |
|
| 32 | + const COMPARE_LESS_THAN_EQUAL = 'lte'; |
|
| 33 | + const COMPARE_LIKE = 'like'; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the type of comparison, one of the ISearchComparison::COMPARE_* constants |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - * @since 12.0.0 |
|
| 40 | - */ |
|
| 41 | - public function getType(); |
|
| 35 | + /** |
|
| 36 | + * Get the type of comparison, one of the ISearchComparison::COMPARE_* constants |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + * @since 12.0.0 |
|
| 40 | + */ |
|
| 41 | + public function getType(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Get the name of the field to compare with |
|
| 45 | - * |
|
| 46 | - * i.e. 'size', 'name' or 'mimetype' |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - * @since 12.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getField(); |
|
| 43 | + /** |
|
| 44 | + * Get the name of the field to compare with |
|
| 45 | + * |
|
| 46 | + * i.e. 'size', 'name' or 'mimetype' |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + * @since 12.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getField(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the value to compare the field with |
|
| 55 | - * |
|
| 56 | - * @return string|integer|\DateTime |
|
| 57 | - * @since 12.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getValue(); |
|
| 53 | + /** |
|
| 54 | + * Get the value to compare the field with |
|
| 55 | + * |
|
| 56 | + * @return string|integer|\DateTime |
|
| 57 | + * @since 12.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getValue(); |
|
| 60 | 60 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchQuery { |
| 28 | - /** |
|
| 29 | - * @return ISearchOperator |
|
| 30 | - * @since 12.0.0 |
|
| 31 | - */ |
|
| 32 | - public function getSearchOperation(); |
|
| 28 | + /** |
|
| 29 | + * @return ISearchOperator |
|
| 30 | + * @since 12.0.0 |
|
| 31 | + */ |
|
| 32 | + public function getSearchOperation(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get the maximum number of results to return |
|
| 36 | - * |
|
| 37 | - * @return integer |
|
| 38 | - * @since 12.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getLimit(); |
|
| 34 | + /** |
|
| 35 | + * Get the maximum number of results to return |
|
| 36 | + * |
|
| 37 | + * @return integer |
|
| 38 | + * @since 12.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getLimit(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Get the offset for returned results |
|
| 44 | - * |
|
| 45 | - * @return integer |
|
| 46 | - * @since 12.0.0 |
|
| 47 | - */ |
|
| 48 | - public function getOffset(); |
|
| 42 | + /** |
|
| 43 | + * Get the offset for returned results |
|
| 44 | + * |
|
| 45 | + * @return integer |
|
| 46 | + * @since 12.0.0 |
|
| 47 | + */ |
|
| 48 | + public function getOffset(); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * The fields and directions to order by |
|
| 52 | - * |
|
| 53 | - * @return ISearchOrder[] |
|
| 54 | - * @since 12.0.0 |
|
| 55 | - */ |
|
| 56 | - public function getOrder(); |
|
| 50 | + /** |
|
| 51 | + * The fields and directions to order by |
|
| 52 | + * |
|
| 53 | + * @return ISearchOrder[] |
|
| 54 | + * @since 12.0.0 |
|
| 55 | + */ |
|
| 56 | + public function getOrder(); |
|
| 57 | 57 | } |
@@ -25,27 +25,27 @@ |
||
| 25 | 25 | * @since 12.0.0 |
| 26 | 26 | */ |
| 27 | 27 | interface ISearchBinaryOperator extends ISearchOperator { |
| 28 | - const OPERATOR_AND = 'and'; |
|
| 29 | - const OPERATOR_OR = 'or'; |
|
| 30 | - const OPERATOR_NOT = 'not'; |
|
| 28 | + const OPERATOR_AND = 'and'; |
|
| 29 | + const OPERATOR_OR = 'or'; |
|
| 30 | + const OPERATOR_NOT = 'not'; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The type of binary operator |
|
| 34 | - * |
|
| 35 | - * One of the ISearchBinaryOperator::OPERATOR_* constants |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - * @since 12.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getType(); |
|
| 32 | + /** |
|
| 33 | + * The type of binary operator |
|
| 34 | + * |
|
| 35 | + * One of the ISearchBinaryOperator::OPERATOR_* constants |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + * @since 12.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getType(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The arguments for the binary operator |
|
| 44 | - * |
|
| 45 | - * One argument for the 'not' operator and two for 'and' and 'or' |
|
| 46 | - * |
|
| 47 | - * @return ISearchOperator[] |
|
| 48 | - * @since 12.0.0 |
|
| 49 | - */ |
|
| 50 | - public function getArguments(); |
|
| 42 | + /** |
|
| 43 | + * The arguments for the binary operator |
|
| 44 | + * |
|
| 45 | + * One argument for the 'not' operator and two for 'and' and 'or' |
|
| 46 | + * |
|
| 47 | + * @return ISearchOperator[] |
|
| 48 | + * @since 12.0.0 |
|
| 49 | + */ |
|
| 50 | + public function getArguments(); |
|
| 51 | 51 | } |
@@ -36,152 +36,152 @@ |
||
| 36 | 36 | * @since 6.0.0 |
| 37 | 37 | */ |
| 38 | 38 | interface Folder extends Node { |
| 39 | - /** |
|
| 40 | - * Get the full path of an item in the folder within owncloud's filesystem |
|
| 41 | - * |
|
| 42 | - * @param string $path relative path of an item in the folder |
|
| 43 | - * @return string |
|
| 44 | - * @throws \OCP\Files\NotPermittedException |
|
| 45 | - * @since 6.0.0 |
|
| 46 | - */ |
|
| 47 | - public function getFullPath($path); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Get the path of an item in the folder relative to the folder |
|
| 51 | - * |
|
| 52 | - * @param string $path absolute path of an item in the folder |
|
| 53 | - * @throws \OCP\Files\NotFoundException |
|
| 54 | - * @return string |
|
| 55 | - * @since 6.0.0 |
|
| 56 | - */ |
|
| 57 | - public function getRelativePath($path); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * check if a node is a (grand-)child of the folder |
|
| 61 | - * |
|
| 62 | - * @param \OCP\Files\Node $node |
|
| 63 | - * @return bool |
|
| 64 | - * @since 6.0.0 |
|
| 65 | - */ |
|
| 66 | - public function isSubNode($node); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * get the content of this directory |
|
| 70 | - * |
|
| 71 | - * @throws \OCP\Files\NotFoundException |
|
| 72 | - * @return \OCP\Files\Node[] |
|
| 73 | - * @since 6.0.0 |
|
| 74 | - */ |
|
| 75 | - public function getDirectoryListing(); |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get the node at $path |
|
| 79 | - * |
|
| 80 | - * @param string $path relative path of the file or folder |
|
| 81 | - * @return \OCP\Files\Node |
|
| 82 | - * @throws \OCP\Files\NotFoundException |
|
| 83 | - * @since 6.0.0 |
|
| 84 | - */ |
|
| 85 | - public function get($path); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Check if a file or folder exists in the folder |
|
| 89 | - * |
|
| 90 | - * @param string $path relative path of the file or folder |
|
| 91 | - * @return bool |
|
| 92 | - * @since 6.0.0 |
|
| 93 | - */ |
|
| 94 | - public function nodeExists($path); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Create a new folder |
|
| 98 | - * |
|
| 99 | - * @param string $path relative path of the new folder |
|
| 100 | - * @return \OCP\Files\Folder |
|
| 101 | - * @throws \OCP\Files\NotPermittedException |
|
| 102 | - * @since 6.0.0 |
|
| 103 | - */ |
|
| 104 | - public function newFolder($path); |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Create a new file |
|
| 108 | - * |
|
| 109 | - * @param string $path relative path of the new file |
|
| 110 | - * @return \OCP\Files\File |
|
| 111 | - * @throws \OCP\Files\NotPermittedException |
|
| 112 | - * @since 6.0.0 |
|
| 113 | - */ |
|
| 114 | - public function newFile($path); |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * search for files with the name matching $query |
|
| 118 | - * |
|
| 119 | - * @param string|ISearchQuery $query |
|
| 120 | - * @return \OCP\Files\Node[] |
|
| 121 | - * @since 6.0.0 |
|
| 122 | - */ |
|
| 123 | - public function search($query); |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * search for files by mimetype |
|
| 127 | - * $mimetype can either be a full mimetype (image/png) or a wildcard mimetype (image) |
|
| 128 | - * |
|
| 129 | - * @param string $mimetype |
|
| 130 | - * @return \OCP\Files\Node[] |
|
| 131 | - * @since 6.0.0 |
|
| 132 | - */ |
|
| 133 | - public function searchByMime($mimetype); |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * search for files by tag |
|
| 137 | - * |
|
| 138 | - * @param string|int $tag tag name or tag id |
|
| 139 | - * @param string $userId owner of the tags |
|
| 140 | - * @return \OCP\Files\Node[] |
|
| 141 | - * @since 8.0.0 |
|
| 142 | - */ |
|
| 143 | - public function searchByTag($tag, $userId); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * get a file or folder inside the folder by it's internal id |
|
| 147 | - * |
|
| 148 | - * @param int $id |
|
| 149 | - * @return \OCP\Files\Node[] |
|
| 150 | - * @since 6.0.0 |
|
| 151 | - */ |
|
| 152 | - public function getById($id); |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Get the amount of free space inside the folder |
|
| 156 | - * |
|
| 157 | - * @return int |
|
| 158 | - * @since 6.0.0 |
|
| 159 | - */ |
|
| 160 | - public function getFreeSpace(); |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Check if new files or folders can be created within the folder |
|
| 164 | - * |
|
| 165 | - * @return bool |
|
| 166 | - * @since 6.0.0 |
|
| 167 | - */ |
|
| 168 | - public function isCreatable(); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Add a suffix to the name in case the file exists |
|
| 172 | - * |
|
| 173 | - * @param string $name |
|
| 174 | - * @return string |
|
| 175 | - * @throws NotPermittedException |
|
| 176 | - * @since 8.1.0 |
|
| 177 | - */ |
|
| 178 | - public function getNonExistingName($name); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param int $limit |
|
| 182 | - * @param int $offset |
|
| 183 | - * @return \OCP\Files\Node[] |
|
| 184 | - * @since 9.1.0 |
|
| 185 | - */ |
|
| 186 | - public function getRecent($limit, $offset = 0); |
|
| 39 | + /** |
|
| 40 | + * Get the full path of an item in the folder within owncloud's filesystem |
|
| 41 | + * |
|
| 42 | + * @param string $path relative path of an item in the folder |
|
| 43 | + * @return string |
|
| 44 | + * @throws \OCP\Files\NotPermittedException |
|
| 45 | + * @since 6.0.0 |
|
| 46 | + */ |
|
| 47 | + public function getFullPath($path); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Get the path of an item in the folder relative to the folder |
|
| 51 | + * |
|
| 52 | + * @param string $path absolute path of an item in the folder |
|
| 53 | + * @throws \OCP\Files\NotFoundException |
|
| 54 | + * @return string |
|
| 55 | + * @since 6.0.0 |
|
| 56 | + */ |
|
| 57 | + public function getRelativePath($path); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * check if a node is a (grand-)child of the folder |
|
| 61 | + * |
|
| 62 | + * @param \OCP\Files\Node $node |
|
| 63 | + * @return bool |
|
| 64 | + * @since 6.0.0 |
|
| 65 | + */ |
|
| 66 | + public function isSubNode($node); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * get the content of this directory |
|
| 70 | + * |
|
| 71 | + * @throws \OCP\Files\NotFoundException |
|
| 72 | + * @return \OCP\Files\Node[] |
|
| 73 | + * @since 6.0.0 |
|
| 74 | + */ |
|
| 75 | + public function getDirectoryListing(); |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get the node at $path |
|
| 79 | + * |
|
| 80 | + * @param string $path relative path of the file or folder |
|
| 81 | + * @return \OCP\Files\Node |
|
| 82 | + * @throws \OCP\Files\NotFoundException |
|
| 83 | + * @since 6.0.0 |
|
| 84 | + */ |
|
| 85 | + public function get($path); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Check if a file or folder exists in the folder |
|
| 89 | + * |
|
| 90 | + * @param string $path relative path of the file or folder |
|
| 91 | + * @return bool |
|
| 92 | + * @since 6.0.0 |
|
| 93 | + */ |
|
| 94 | + public function nodeExists($path); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Create a new folder |
|
| 98 | + * |
|
| 99 | + * @param string $path relative path of the new folder |
|
| 100 | + * @return \OCP\Files\Folder |
|
| 101 | + * @throws \OCP\Files\NotPermittedException |
|
| 102 | + * @since 6.0.0 |
|
| 103 | + */ |
|
| 104 | + public function newFolder($path); |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Create a new file |
|
| 108 | + * |
|
| 109 | + * @param string $path relative path of the new file |
|
| 110 | + * @return \OCP\Files\File |
|
| 111 | + * @throws \OCP\Files\NotPermittedException |
|
| 112 | + * @since 6.0.0 |
|
| 113 | + */ |
|
| 114 | + public function newFile($path); |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * search for files with the name matching $query |
|
| 118 | + * |
|
| 119 | + * @param string|ISearchQuery $query |
|
| 120 | + * @return \OCP\Files\Node[] |
|
| 121 | + * @since 6.0.0 |
|
| 122 | + */ |
|
| 123 | + public function search($query); |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * search for files by mimetype |
|
| 127 | + * $mimetype can either be a full mimetype (image/png) or a wildcard mimetype (image) |
|
| 128 | + * |
|
| 129 | + * @param string $mimetype |
|
| 130 | + * @return \OCP\Files\Node[] |
|
| 131 | + * @since 6.0.0 |
|
| 132 | + */ |
|
| 133 | + public function searchByMime($mimetype); |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * search for files by tag |
|
| 137 | + * |
|
| 138 | + * @param string|int $tag tag name or tag id |
|
| 139 | + * @param string $userId owner of the tags |
|
| 140 | + * @return \OCP\Files\Node[] |
|
| 141 | + * @since 8.0.0 |
|
| 142 | + */ |
|
| 143 | + public function searchByTag($tag, $userId); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * get a file or folder inside the folder by it's internal id |
|
| 147 | + * |
|
| 148 | + * @param int $id |
|
| 149 | + * @return \OCP\Files\Node[] |
|
| 150 | + * @since 6.0.0 |
|
| 151 | + */ |
|
| 152 | + public function getById($id); |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Get the amount of free space inside the folder |
|
| 156 | + * |
|
| 157 | + * @return int |
|
| 158 | + * @since 6.0.0 |
|
| 159 | + */ |
|
| 160 | + public function getFreeSpace(); |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Check if new files or folders can be created within the folder |
|
| 164 | + * |
|
| 165 | + * @return bool |
|
| 166 | + * @since 6.0.0 |
|
| 167 | + */ |
|
| 168 | + public function isCreatable(); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Add a suffix to the name in case the file exists |
|
| 172 | + * |
|
| 173 | + * @param string $name |
|
| 174 | + * @return string |
|
| 175 | + * @throws NotPermittedException |
|
| 176 | + * @since 8.1.0 |
|
| 177 | + */ |
|
| 178 | + public function getNonExistingName($name); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param int $limit |
|
| 182 | + * @param int $offset |
|
| 183 | + * @return \OCP\Files\Node[] |
|
| 184 | + * @since 9.1.0 |
|
| 185 | + */ |
|
| 186 | + public function getRecent($limit, $offset = 0); |
|
| 187 | 187 | } |
@@ -37,233 +37,233 @@ |
||
| 37 | 37 | * @since 9.0.0 |
| 38 | 38 | */ |
| 39 | 39 | interface ICache { |
| 40 | - const NOT_FOUND = 0; |
|
| 41 | - const PARTIAL = 1; //only partial data available, file not cached in the database |
|
| 42 | - const SHALLOW = 2; //folder in cache, but not all child files are completely scanned |
|
| 43 | - const COMPLETE = 3; |
|
| 40 | + const NOT_FOUND = 0; |
|
| 41 | + const PARTIAL = 1; //only partial data available, file not cached in the database |
|
| 42 | + const SHALLOW = 2; //folder in cache, but not all child files are completely scanned |
|
| 43 | + const COMPLETE = 3; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Get the numeric storage id for this cache's storage |
|
| 47 | - * |
|
| 48 | - * @return int |
|
| 49 | - * @since 9.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getNumericStorageId(); |
|
| 45 | + /** |
|
| 46 | + * Get the numeric storage id for this cache's storage |
|
| 47 | + * |
|
| 48 | + * @return int |
|
| 49 | + * @since 9.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getNumericStorageId(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * get the stored metadata of a file or folder |
|
| 55 | - * |
|
| 56 | - * @param string | int $file either the path of a file or folder or the file id for a file or folder |
|
| 57 | - * @return ICacheEntry|false the cache entry or false if the file is not found in the cache |
|
| 58 | - * @since 9.0.0 |
|
| 59 | - */ |
|
| 60 | - public function get($file); |
|
| 53 | + /** |
|
| 54 | + * get the stored metadata of a file or folder |
|
| 55 | + * |
|
| 56 | + * @param string | int $file either the path of a file or folder or the file id for a file or folder |
|
| 57 | + * @return ICacheEntry|false the cache entry or false if the file is not found in the cache |
|
| 58 | + * @since 9.0.0 |
|
| 59 | + */ |
|
| 60 | + public function get($file); |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * get the metadata of all files stored in $folder |
|
| 64 | - * |
|
| 65 | - * Only returns files one level deep, no recursion |
|
| 66 | - * |
|
| 67 | - * @param string $folder |
|
| 68 | - * @return ICacheEntry[] |
|
| 69 | - * @since 9.0.0 |
|
| 70 | - */ |
|
| 71 | - public function getFolderContents($folder); |
|
| 62 | + /** |
|
| 63 | + * get the metadata of all files stored in $folder |
|
| 64 | + * |
|
| 65 | + * Only returns files one level deep, no recursion |
|
| 66 | + * |
|
| 67 | + * @param string $folder |
|
| 68 | + * @return ICacheEntry[] |
|
| 69 | + * @since 9.0.0 |
|
| 70 | + */ |
|
| 71 | + public function getFolderContents($folder); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * get the metadata of all files stored in $folder |
|
| 75 | - * |
|
| 76 | - * Only returns files one level deep, no recursion |
|
| 77 | - * |
|
| 78 | - * @param int $fileId the file id of the folder |
|
| 79 | - * @return ICacheEntry[] |
|
| 80 | - * @since 9.0.0 |
|
| 81 | - */ |
|
| 82 | - public function getFolderContentsById($fileId); |
|
| 73 | + /** |
|
| 74 | + * get the metadata of all files stored in $folder |
|
| 75 | + * |
|
| 76 | + * Only returns files one level deep, no recursion |
|
| 77 | + * |
|
| 78 | + * @param int $fileId the file id of the folder |
|
| 79 | + * @return ICacheEntry[] |
|
| 80 | + * @since 9.0.0 |
|
| 81 | + */ |
|
| 82 | + public function getFolderContentsById($fileId); |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * store meta data for a file or folder |
|
| 86 | - * This will automatically call either insert or update depending on if the file exists |
|
| 87 | - * |
|
| 88 | - * @param string $file |
|
| 89 | - * @param array $data |
|
| 90 | - * |
|
| 91 | - * @return int file id |
|
| 92 | - * @throws \RuntimeException |
|
| 93 | - * @since 9.0.0 |
|
| 94 | - */ |
|
| 95 | - public function put($file, array $data); |
|
| 84 | + /** |
|
| 85 | + * store meta data for a file or folder |
|
| 86 | + * This will automatically call either insert or update depending on if the file exists |
|
| 87 | + * |
|
| 88 | + * @param string $file |
|
| 89 | + * @param array $data |
|
| 90 | + * |
|
| 91 | + * @return int file id |
|
| 92 | + * @throws \RuntimeException |
|
| 93 | + * @since 9.0.0 |
|
| 94 | + */ |
|
| 95 | + public function put($file, array $data); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * insert meta data for a new file or folder |
|
| 99 | - * |
|
| 100 | - * @param string $file |
|
| 101 | - * @param array $data |
|
| 102 | - * |
|
| 103 | - * @return int file id |
|
| 104 | - * @throws \RuntimeException |
|
| 105 | - * @since 9.0.0 |
|
| 106 | - */ |
|
| 107 | - public function insert($file, array $data); |
|
| 97 | + /** |
|
| 98 | + * insert meta data for a new file or folder |
|
| 99 | + * |
|
| 100 | + * @param string $file |
|
| 101 | + * @param array $data |
|
| 102 | + * |
|
| 103 | + * @return int file id |
|
| 104 | + * @throws \RuntimeException |
|
| 105 | + * @since 9.0.0 |
|
| 106 | + */ |
|
| 107 | + public function insert($file, array $data); |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * update the metadata of an existing file or folder in the cache |
|
| 111 | - * |
|
| 112 | - * @param int $id the fileid of the existing file or folder |
|
| 113 | - * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged |
|
| 114 | - * @since 9.0.0 |
|
| 115 | - */ |
|
| 116 | - public function update($id, array $data); |
|
| 109 | + /** |
|
| 110 | + * update the metadata of an existing file or folder in the cache |
|
| 111 | + * |
|
| 112 | + * @param int $id the fileid of the existing file or folder |
|
| 113 | + * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged |
|
| 114 | + * @since 9.0.0 |
|
| 115 | + */ |
|
| 116 | + public function update($id, array $data); |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * get the file id for a file |
|
| 120 | - * |
|
| 121 | - * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file |
|
| 122 | - * |
|
| 123 | - * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 124 | - * |
|
| 125 | - * @param string $file |
|
| 126 | - * @return int |
|
| 127 | - * @since 9.0.0 |
|
| 128 | - */ |
|
| 129 | - public function getId($file); |
|
| 118 | + /** |
|
| 119 | + * get the file id for a file |
|
| 120 | + * |
|
| 121 | + * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file |
|
| 122 | + * |
|
| 123 | + * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing |
|
| 124 | + * |
|
| 125 | + * @param string $file |
|
| 126 | + * @return int |
|
| 127 | + * @since 9.0.0 |
|
| 128 | + */ |
|
| 129 | + public function getId($file); |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * get the id of the parent folder of a file |
|
| 133 | - * |
|
| 134 | - * @param string $file |
|
| 135 | - * @return int |
|
| 136 | - * @since 9.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getParentId($file); |
|
| 131 | + /** |
|
| 132 | + * get the id of the parent folder of a file |
|
| 133 | + * |
|
| 134 | + * @param string $file |
|
| 135 | + * @return int |
|
| 136 | + * @since 9.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getParentId($file); |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * check if a file is available in the cache |
|
| 142 | - * |
|
| 143 | - * @param string $file |
|
| 144 | - * @return bool |
|
| 145 | - * @since 9.0.0 |
|
| 146 | - */ |
|
| 147 | - public function inCache($file); |
|
| 140 | + /** |
|
| 141 | + * check if a file is available in the cache |
|
| 142 | + * |
|
| 143 | + * @param string $file |
|
| 144 | + * @return bool |
|
| 145 | + * @since 9.0.0 |
|
| 146 | + */ |
|
| 147 | + public function inCache($file); |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * remove a file or folder from the cache |
|
| 151 | - * |
|
| 152 | - * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 153 | - * |
|
| 154 | - * @param string $file |
|
| 155 | - * @since 9.0.0 |
|
| 156 | - */ |
|
| 157 | - public function remove($file); |
|
| 149 | + /** |
|
| 150 | + * remove a file or folder from the cache |
|
| 151 | + * |
|
| 152 | + * when removing a folder from the cache all files and folders inside the folder will be removed as well |
|
| 153 | + * |
|
| 154 | + * @param string $file |
|
| 155 | + * @since 9.0.0 |
|
| 156 | + */ |
|
| 157 | + public function remove($file); |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Move a file or folder in the cache |
|
| 161 | - * |
|
| 162 | - * @param string $source |
|
| 163 | - * @param string $target |
|
| 164 | - * @since 9.0.0 |
|
| 165 | - */ |
|
| 166 | - public function move($source, $target); |
|
| 159 | + /** |
|
| 160 | + * Move a file or folder in the cache |
|
| 161 | + * |
|
| 162 | + * @param string $source |
|
| 163 | + * @param string $target |
|
| 164 | + * @since 9.0.0 |
|
| 165 | + */ |
|
| 166 | + public function move($source, $target); |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Move a file or folder in the cache |
|
| 170 | - * |
|
| 171 | - * Note that this should make sure the entries are removed from the source cache |
|
| 172 | - * |
|
| 173 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 174 | - * @param string $sourcePath |
|
| 175 | - * @param string $targetPath |
|
| 176 | - * @throws \OC\DatabaseException |
|
| 177 | - * @since 9.0.0 |
|
| 178 | - */ |
|
| 179 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath); |
|
| 168 | + /** |
|
| 169 | + * Move a file or folder in the cache |
|
| 170 | + * |
|
| 171 | + * Note that this should make sure the entries are removed from the source cache |
|
| 172 | + * |
|
| 173 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 174 | + * @param string $sourcePath |
|
| 175 | + * @param string $targetPath |
|
| 176 | + * @throws \OC\DatabaseException |
|
| 177 | + * @since 9.0.0 |
|
| 178 | + */ |
|
| 179 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath); |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Get the scan status of a file |
|
| 183 | - * |
|
| 184 | - * - ICache::NOT_FOUND: File is not in the cache |
|
| 185 | - * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 186 | - * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 187 | - * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 188 | - * |
|
| 189 | - * @param string $file |
|
| 190 | - * |
|
| 191 | - * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE |
|
| 192 | - * @since 9.0.0 |
|
| 193 | - */ |
|
| 194 | - public function getStatus($file); |
|
| 181 | + /** |
|
| 182 | + * Get the scan status of a file |
|
| 183 | + * |
|
| 184 | + * - ICache::NOT_FOUND: File is not in the cache |
|
| 185 | + * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known |
|
| 186 | + * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned |
|
| 187 | + * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned |
|
| 188 | + * |
|
| 189 | + * @param string $file |
|
| 190 | + * |
|
| 191 | + * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE |
|
| 192 | + * @since 9.0.0 |
|
| 193 | + */ |
|
| 194 | + public function getStatus($file); |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * search for files matching $pattern, files are matched if their filename matches the search pattern |
|
| 198 | - * |
|
| 199 | - * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
|
| 200 | - * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 201 | - * @since 9.0.0 |
|
| 202 | - * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 203 | - */ |
|
| 204 | - public function search($pattern); |
|
| 196 | + /** |
|
| 197 | + * search for files matching $pattern, files are matched if their filename matches the search pattern |
|
| 198 | + * |
|
| 199 | + * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') |
|
| 200 | + * @return ICacheEntry[] an array of cache entries where the name matches the search pattern |
|
| 201 | + * @since 9.0.0 |
|
| 202 | + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 203 | + */ |
|
| 204 | + public function search($pattern); |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * search for files by mimetype |
|
| 208 | - * |
|
| 209 | - * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 210 | - * where it will search for all mimetypes in the group ('image/*') |
|
| 211 | - * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 212 | - * @since 9.0.0 |
|
| 213 | - * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 214 | - */ |
|
| 215 | - public function searchByMime($mimetype); |
|
| 206 | + /** |
|
| 207 | + * search for files by mimetype |
|
| 208 | + * |
|
| 209 | + * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') |
|
| 210 | + * where it will search for all mimetypes in the group ('image/*') |
|
| 211 | + * @return ICacheEntry[] an array of cache entries where the mimetype matches the search |
|
| 212 | + * @since 9.0.0 |
|
| 213 | + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 214 | + */ |
|
| 215 | + public function searchByMime($mimetype); |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Search for files with a flexible query |
|
| 219 | - * |
|
| 220 | - * @param ISearchQuery $query |
|
| 221 | - * @return ICacheEntry[] |
|
| 222 | - * @throw \InvalidArgumentException if the cache is unable to perform the query |
|
| 223 | - * @since 12.0.0 |
|
| 224 | - */ |
|
| 225 | - public function searchQuery(ISearchQuery $query); |
|
| 217 | + /** |
|
| 218 | + * Search for files with a flexible query |
|
| 219 | + * |
|
| 220 | + * @param ISearchQuery $query |
|
| 221 | + * @return ICacheEntry[] |
|
| 222 | + * @throw \InvalidArgumentException if the cache is unable to perform the query |
|
| 223 | + * @since 12.0.0 |
|
| 224 | + */ |
|
| 225 | + public function searchQuery(ISearchQuery $query); |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Search for files by tag of a given users. |
|
| 229 | - * |
|
| 230 | - * Note that every user can tag files differently. |
|
| 231 | - * |
|
| 232 | - * @param string|int $tag name or tag id |
|
| 233 | - * @param string $userId owner of the tags |
|
| 234 | - * @return ICacheEntry[] file data |
|
| 235 | - * @since 9.0.0 |
|
| 236 | - * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 237 | - */ |
|
| 238 | - public function searchByTag($tag, $userId); |
|
| 227 | + /** |
|
| 228 | + * Search for files by tag of a given users. |
|
| 229 | + * |
|
| 230 | + * Note that every user can tag files differently. |
|
| 231 | + * |
|
| 232 | + * @param string|int $tag name or tag id |
|
| 233 | + * @param string $userId owner of the tags |
|
| 234 | + * @return ICacheEntry[] file data |
|
| 235 | + * @since 9.0.0 |
|
| 236 | + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this |
|
| 237 | + */ |
|
| 238 | + public function searchByTag($tag, $userId); |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * find a folder in the cache which has not been fully scanned |
|
| 242 | - * |
|
| 243 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 244 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 245 | - * likely the folder where we stopped scanning previously |
|
| 246 | - * |
|
| 247 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 248 | - * @since 9.0.0 |
|
| 249 | - */ |
|
| 250 | - public function getIncomplete(); |
|
| 240 | + /** |
|
| 241 | + * find a folder in the cache which has not been fully scanned |
|
| 242 | + * |
|
| 243 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 244 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 245 | + * likely the folder where we stopped scanning previously |
|
| 246 | + * |
|
| 247 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 248 | + * @since 9.0.0 |
|
| 249 | + */ |
|
| 250 | + public function getIncomplete(); |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * get the path of a file on this storage by it's file id |
|
| 254 | - * |
|
| 255 | - * @param int $id the file id of the file or folder to search |
|
| 256 | - * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache |
|
| 257 | - * @since 9.0.0 |
|
| 258 | - */ |
|
| 259 | - public function getPathById($id); |
|
| 252 | + /** |
|
| 253 | + * get the path of a file on this storage by it's file id |
|
| 254 | + * |
|
| 255 | + * @param int $id the file id of the file or folder to search |
|
| 256 | + * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache |
|
| 257 | + * @since 9.0.0 |
|
| 258 | + */ |
|
| 259 | + public function getPathById($id); |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * normalize the given path for usage in the cache |
|
| 263 | - * |
|
| 264 | - * @param string $path |
|
| 265 | - * @return string |
|
| 266 | - * @since 9.0.0 |
|
| 267 | - */ |
|
| 268 | - public function normalize($path); |
|
| 261 | + /** |
|
| 262 | + * normalize the given path for usage in the cache |
|
| 263 | + * |
|
| 264 | + * @param string $path |
|
| 265 | + * @return string |
|
| 266 | + * @since 9.0.0 |
|
| 267 | + */ |
|
| 268 | + public function normalize($path); |
|
| 269 | 269 | } |
@@ -36,394 +36,394 @@ |
||
| 36 | 36 | use OCP\Files\Search\ISearchOperator; |
| 37 | 37 | |
| 38 | 38 | class Folder extends Node implements \OCP\Files\Folder { |
| 39 | - /** |
|
| 40 | - * Creates a Folder that represents a non-existing path |
|
| 41 | - * |
|
| 42 | - * @param string $path path |
|
| 43 | - * @return string non-existing node class |
|
| 44 | - */ |
|
| 45 | - protected function createNonExistingNode($path) { |
|
| 46 | - return new NonExistingFolder($this->root, $this->view, $path); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $path path relative to the folder |
|
| 51 | - * @return string |
|
| 52 | - * @throws \OCP\Files\NotPermittedException |
|
| 53 | - */ |
|
| 54 | - public function getFullPath($path) { |
|
| 55 | - if (!$this->isValidPath($path)) { |
|
| 56 | - throw new NotPermittedException('Invalid path'); |
|
| 57 | - } |
|
| 58 | - return $this->path . $this->normalizePath($path); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $path |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function getRelativePath($path) { |
|
| 66 | - if ($this->path === '' or $this->path === '/') { |
|
| 67 | - return $this->normalizePath($path); |
|
| 68 | - } |
|
| 69 | - if ($path === $this->path) { |
|
| 70 | - return '/'; |
|
| 71 | - } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 72 | - return null; |
|
| 73 | - } else { |
|
| 74 | - $path = substr($path, strlen($this->path)); |
|
| 75 | - return $this->normalizePath($path); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * check if a node is a (grand-)child of the folder |
|
| 81 | - * |
|
| 82 | - * @param \OC\Files\Node\Node $node |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function isSubNode($node) { |
|
| 86 | - return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * get the content of this directory |
|
| 91 | - * |
|
| 92 | - * @throws \OCP\Files\NotFoundException |
|
| 93 | - * @return Node[] |
|
| 94 | - */ |
|
| 95 | - public function getDirectoryListing() { |
|
| 96 | - $folderContent = $this->view->getDirectoryContent($this->path); |
|
| 97 | - |
|
| 98 | - return array_map(function (FileInfo $info) { |
|
| 99 | - if ($info->getMimetype() === 'httpd/unix-directory') { |
|
| 100 | - return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 101 | - } else { |
|
| 102 | - return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 103 | - } |
|
| 104 | - }, $folderContent); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $path |
|
| 109 | - * @param FileInfo $info |
|
| 110 | - * @return File|Folder |
|
| 111 | - */ |
|
| 112 | - protected function createNode($path, FileInfo $info = null) { |
|
| 113 | - if (is_null($info)) { |
|
| 114 | - $isDir = $this->view->is_dir($path); |
|
| 115 | - } else { |
|
| 116 | - $isDir = $info->getType() === FileInfo::TYPE_FOLDER; |
|
| 117 | - } |
|
| 118 | - if ($isDir) { |
|
| 119 | - return new Folder($this->root, $this->view, $path, $info); |
|
| 120 | - } else { |
|
| 121 | - return new File($this->root, $this->view, $path, $info); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get the node at $path |
|
| 127 | - * |
|
| 128 | - * @param string $path |
|
| 129 | - * @return \OC\Files\Node\Node |
|
| 130 | - * @throws \OCP\Files\NotFoundException |
|
| 131 | - */ |
|
| 132 | - public function get($path) { |
|
| 133 | - return $this->root->get($this->getFullPath($path)); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param string $path |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function nodeExists($path) { |
|
| 141 | - try { |
|
| 142 | - $this->get($path); |
|
| 143 | - return true; |
|
| 144 | - } catch (NotFoundException $e) { |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $path |
|
| 151 | - * @return \OC\Files\Node\Folder |
|
| 152 | - * @throws \OCP\Files\NotPermittedException |
|
| 153 | - */ |
|
| 154 | - public function newFolder($path) { |
|
| 155 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 156 | - $fullPath = $this->getFullPath($path); |
|
| 157 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); |
|
| 158 | - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 159 | - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 160 | - $this->view->mkdir($fullPath); |
|
| 161 | - $node = new Folder($this->root, $this->view, $fullPath); |
|
| 162 | - $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 163 | - $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 164 | - return $node; |
|
| 165 | - } else { |
|
| 166 | - throw new NotPermittedException('No create permission for folder'); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $path |
|
| 172 | - * @return \OC\Files\Node\File |
|
| 173 | - * @throws \OCP\Files\NotPermittedException |
|
| 174 | - */ |
|
| 175 | - public function newFile($path) { |
|
| 176 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 177 | - $fullPath = $this->getFullPath($path); |
|
| 178 | - $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); |
|
| 179 | - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 180 | - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 181 | - $this->view->touch($fullPath); |
|
| 182 | - $node = new File($this->root, $this->view, $fullPath); |
|
| 183 | - $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 184 | - $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 185 | - return $node; |
|
| 186 | - } else { |
|
| 187 | - throw new NotPermittedException('No create permission for path'); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * search for files with the name matching $query |
|
| 193 | - * |
|
| 194 | - * @param string|ISearchOperator $query |
|
| 195 | - * @return \OC\Files\Node\Node[] |
|
| 196 | - */ |
|
| 197 | - public function search($query) { |
|
| 198 | - if (is_string($query)) { |
|
| 199 | - return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 200 | - } else { |
|
| 201 | - return $this->searchCommon('searchQuery', array($query)); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * search for files by mimetype |
|
| 207 | - * |
|
| 208 | - * @param string $mimetype |
|
| 209 | - * @return Node[] |
|
| 210 | - */ |
|
| 211 | - public function searchByMime($mimetype) { |
|
| 212 | - return $this->searchCommon('searchByMime', array($mimetype)); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * search for files by tag |
|
| 217 | - * |
|
| 218 | - * @param string|int $tag name or tag id |
|
| 219 | - * @param string $userId owner of the tags |
|
| 220 | - * @return Node[] |
|
| 221 | - */ |
|
| 222 | - public function searchByTag($tag, $userId) { |
|
| 223 | - return $this->searchCommon('searchByTag', array($tag, $userId)); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $method cache method |
|
| 228 | - * @param array $args call args |
|
| 229 | - * @return \OC\Files\Node\Node[] |
|
| 230 | - */ |
|
| 231 | - private function searchCommon($method, $args) { |
|
| 232 | - $files = array(); |
|
| 233 | - $rootLength = strlen($this->path); |
|
| 234 | - $mount = $this->root->getMount($this->path); |
|
| 235 | - $storage = $mount->getStorage(); |
|
| 236 | - $internalPath = $mount->getInternalPath($this->path); |
|
| 237 | - $internalPath = rtrim($internalPath, '/'); |
|
| 238 | - if ($internalPath !== '') { |
|
| 239 | - $internalPath = $internalPath . '/'; |
|
| 240 | - } |
|
| 241 | - $internalRootLength = strlen($internalPath); |
|
| 242 | - |
|
| 243 | - $cache = $storage->getCache(''); |
|
| 244 | - |
|
| 245 | - $results = call_user_func_array(array($cache, $method), $args); |
|
| 246 | - foreach ($results as $result) { |
|
| 247 | - if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { |
|
| 248 | - $result['internalPath'] = $result['path']; |
|
| 249 | - $result['path'] = substr($result['path'], $internalRootLength); |
|
| 250 | - $result['storage'] = $storage; |
|
| 251 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 256 | - foreach ($mounts as $mount) { |
|
| 257 | - $storage = $mount->getStorage(); |
|
| 258 | - if ($storage) { |
|
| 259 | - $cache = $storage->getCache(''); |
|
| 260 | - |
|
| 261 | - $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); |
|
| 262 | - $results = call_user_func_array(array($cache, $method), $args); |
|
| 263 | - foreach ($results as $result) { |
|
| 264 | - $result['internalPath'] = $result['path']; |
|
| 265 | - $result['path'] = $relativeMountPoint . $result['path']; |
|
| 266 | - $result['storage'] = $storage; |
|
| 267 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return array_map(function (FileInfo $file) { |
|
| 273 | - return $this->createNode($file->getPath(), $file); |
|
| 274 | - }, $files); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param int $id |
|
| 279 | - * @return \OC\Files\Node\Node[] |
|
| 280 | - */ |
|
| 281 | - public function getById($id) { |
|
| 282 | - $mountCache = $this->root->getUserMountCache(); |
|
| 283 | - $mountsContainingFile = $mountCache->getMountsForFileId((int)$id); |
|
| 284 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 285 | - $mounts[] = $this->root->getMount($this->path); |
|
| 286 | - /** @var IMountPoint[] $folderMounts */ |
|
| 287 | - $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 288 | - return $mountPoint->getMountPoint(); |
|
| 289 | - }, $mounts), $mounts); |
|
| 290 | - |
|
| 291 | - /** @var ICachedMountInfo[] $mountsContainingFile */ |
|
| 292 | - $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 293 | - return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
|
| 294 | - })); |
|
| 295 | - |
|
| 296 | - if (count($mountsContainingFile) === 0) { |
|
| 297 | - return []; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // we only need to get the cache info once, since all mounts we found point to the same storage |
|
| 301 | - |
|
| 302 | - $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
|
| 303 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 304 | - if (!$cacheEntry) { |
|
| 305 | - return []; |
|
| 306 | - } |
|
| 307 | - // cache jails will hide the "true" internal path |
|
| 308 | - $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 309 | - |
|
| 310 | - $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 311 | - $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
|
| 312 | - $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
|
| 313 | - $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
|
| 314 | - $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 315 | - return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
|
| 316 | - $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
|
| 317 | - \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
|
| 318 | - )); |
|
| 319 | - }, $mountsContainingFile); |
|
| 320 | - |
|
| 321 | - return array_filter($nodes, function (Node $node) { |
|
| 322 | - return $this->getRelativePath($node->getPath()); |
|
| 323 | - }); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - public function getFreeSpace() { |
|
| 327 | - return $this->view->free_space($this->path); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public function delete() { |
|
| 331 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { |
|
| 332 | - $this->sendHooks(array('preDelete')); |
|
| 333 | - $fileInfo = $this->getFileInfo(); |
|
| 334 | - $this->view->rmdir($this->path); |
|
| 335 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); |
|
| 336 | - $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); |
|
| 337 | - $this->exists = false; |
|
| 338 | - } else { |
|
| 339 | - throw new NotPermittedException('No delete permission for path'); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Add a suffix to the name in case the file exists |
|
| 345 | - * |
|
| 346 | - * @param string $name |
|
| 347 | - * @return string |
|
| 348 | - * @throws NotPermittedException |
|
| 349 | - */ |
|
| 350 | - public function getNonExistingName($name) { |
|
| 351 | - $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); |
|
| 352 | - return trim($this->getRelativePath($uniqueName), '/'); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * @param int $limit |
|
| 357 | - * @param int $offset |
|
| 358 | - * @return \OCP\Files\Node[] |
|
| 359 | - */ |
|
| 360 | - public function getRecent($limit, $offset = 0) { |
|
| 361 | - $mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 362 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 363 | - $mounts[] = $this->getMountPoint(); |
|
| 364 | - |
|
| 365 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 366 | - return $mount->getStorage(); |
|
| 367 | - }); |
|
| 368 | - $storageIds = array_map(function (IMountPoint $mount) { |
|
| 369 | - return $mount->getStorage()->getCache()->getNumericStorageId(); |
|
| 370 | - }, $mounts); |
|
| 371 | - /** @var IMountPoint[] $mountMap */ |
|
| 372 | - $mountMap = array_combine($storageIds, $mounts); |
|
| 373 | - $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); |
|
| 374 | - |
|
| 375 | - //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) |
|
| 376 | - |
|
| 377 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 378 | - $query = $builder |
|
| 379 | - ->select('f.*') |
|
| 380 | - ->from('filecache', 'f') |
|
| 381 | - ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 382 | - ->andWhere($builder->expr()->orX( |
|
| 383 | - // handle non empty folders separate |
|
| 384 | - $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), |
|
| 385 | - $builder->expr()->eq('f.size', new Literal(0)) |
|
| 386 | - )) |
|
| 387 | - ->orderBy('f.mtime', 'DESC') |
|
| 388 | - ->setMaxResults($limit) |
|
| 389 | - ->setFirstResult($offset); |
|
| 390 | - |
|
| 391 | - $result = $query->execute()->fetchAll(); |
|
| 392 | - |
|
| 393 | - $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 394 | - $mount = $mountMap[$entry['storage']]; |
|
| 395 | - $entry['internalPath'] = $entry['path']; |
|
| 396 | - $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
|
| 397 | - $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); |
|
| 398 | - $path = $this->getAbsolutePath($mount, $entry['path']); |
|
| 399 | - if (is_null($path)) { |
|
| 400 | - return null; |
|
| 401 | - } |
|
| 402 | - $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); |
|
| 403 | - return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
|
| 404 | - }, $result)); |
|
| 405 | - |
|
| 406 | - return array_values(array_filter($files, function (Node $node) { |
|
| 407 | - $relative = $this->getRelativePath($node->getPath()); |
|
| 408 | - return $relative !== null && $relative !== '/'; |
|
| 409 | - })); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - private function getAbsolutePath(IMountPoint $mount, $path) { |
|
| 413 | - $storage = $mount->getStorage(); |
|
| 414 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { |
|
| 415 | - /** @var \OC\Files\Storage\Wrapper\Jail $storage */ |
|
| 416 | - $jailRoot = $storage->getSourcePath(''); |
|
| 417 | - $rootLength = strlen($jailRoot) + 1; |
|
| 418 | - if ($path === $jailRoot) { |
|
| 419 | - return $mount->getMountPoint(); |
|
| 420 | - } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 421 | - return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 422 | - } else { |
|
| 423 | - return null; |
|
| 424 | - } |
|
| 425 | - } else { |
|
| 426 | - return $mount->getMountPoint() . $path; |
|
| 427 | - } |
|
| 428 | - } |
|
| 39 | + /** |
|
| 40 | + * Creates a Folder that represents a non-existing path |
|
| 41 | + * |
|
| 42 | + * @param string $path path |
|
| 43 | + * @return string non-existing node class |
|
| 44 | + */ |
|
| 45 | + protected function createNonExistingNode($path) { |
|
| 46 | + return new NonExistingFolder($this->root, $this->view, $path); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $path path relative to the folder |
|
| 51 | + * @return string |
|
| 52 | + * @throws \OCP\Files\NotPermittedException |
|
| 53 | + */ |
|
| 54 | + public function getFullPath($path) { |
|
| 55 | + if (!$this->isValidPath($path)) { |
|
| 56 | + throw new NotPermittedException('Invalid path'); |
|
| 57 | + } |
|
| 58 | + return $this->path . $this->normalizePath($path); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $path |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function getRelativePath($path) { |
|
| 66 | + if ($this->path === '' or $this->path === '/') { |
|
| 67 | + return $this->normalizePath($path); |
|
| 68 | + } |
|
| 69 | + if ($path === $this->path) { |
|
| 70 | + return '/'; |
|
| 71 | + } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 72 | + return null; |
|
| 73 | + } else { |
|
| 74 | + $path = substr($path, strlen($this->path)); |
|
| 75 | + return $this->normalizePath($path); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * check if a node is a (grand-)child of the folder |
|
| 81 | + * |
|
| 82 | + * @param \OC\Files\Node\Node $node |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function isSubNode($node) { |
|
| 86 | + return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * get the content of this directory |
|
| 91 | + * |
|
| 92 | + * @throws \OCP\Files\NotFoundException |
|
| 93 | + * @return Node[] |
|
| 94 | + */ |
|
| 95 | + public function getDirectoryListing() { |
|
| 96 | + $folderContent = $this->view->getDirectoryContent($this->path); |
|
| 97 | + |
|
| 98 | + return array_map(function (FileInfo $info) { |
|
| 99 | + if ($info->getMimetype() === 'httpd/unix-directory') { |
|
| 100 | + return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 101 | + } else { |
|
| 102 | + return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 103 | + } |
|
| 104 | + }, $folderContent); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $path |
|
| 109 | + * @param FileInfo $info |
|
| 110 | + * @return File|Folder |
|
| 111 | + */ |
|
| 112 | + protected function createNode($path, FileInfo $info = null) { |
|
| 113 | + if (is_null($info)) { |
|
| 114 | + $isDir = $this->view->is_dir($path); |
|
| 115 | + } else { |
|
| 116 | + $isDir = $info->getType() === FileInfo::TYPE_FOLDER; |
|
| 117 | + } |
|
| 118 | + if ($isDir) { |
|
| 119 | + return new Folder($this->root, $this->view, $path, $info); |
|
| 120 | + } else { |
|
| 121 | + return new File($this->root, $this->view, $path, $info); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get the node at $path |
|
| 127 | + * |
|
| 128 | + * @param string $path |
|
| 129 | + * @return \OC\Files\Node\Node |
|
| 130 | + * @throws \OCP\Files\NotFoundException |
|
| 131 | + */ |
|
| 132 | + public function get($path) { |
|
| 133 | + return $this->root->get($this->getFullPath($path)); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param string $path |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function nodeExists($path) { |
|
| 141 | + try { |
|
| 142 | + $this->get($path); |
|
| 143 | + return true; |
|
| 144 | + } catch (NotFoundException $e) { |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param string $path |
|
| 151 | + * @return \OC\Files\Node\Folder |
|
| 152 | + * @throws \OCP\Files\NotPermittedException |
|
| 153 | + */ |
|
| 154 | + public function newFolder($path) { |
|
| 155 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 156 | + $fullPath = $this->getFullPath($path); |
|
| 157 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); |
|
| 158 | + $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 159 | + $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 160 | + $this->view->mkdir($fullPath); |
|
| 161 | + $node = new Folder($this->root, $this->view, $fullPath); |
|
| 162 | + $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 163 | + $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 164 | + return $node; |
|
| 165 | + } else { |
|
| 166 | + throw new NotPermittedException('No create permission for folder'); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $path |
|
| 172 | + * @return \OC\Files\Node\File |
|
| 173 | + * @throws \OCP\Files\NotPermittedException |
|
| 174 | + */ |
|
| 175 | + public function newFile($path) { |
|
| 176 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 177 | + $fullPath = $this->getFullPath($path); |
|
| 178 | + $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); |
|
| 179 | + $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 180 | + $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 181 | + $this->view->touch($fullPath); |
|
| 182 | + $node = new File($this->root, $this->view, $fullPath); |
|
| 183 | + $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 184 | + $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 185 | + return $node; |
|
| 186 | + } else { |
|
| 187 | + throw new NotPermittedException('No create permission for path'); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * search for files with the name matching $query |
|
| 193 | + * |
|
| 194 | + * @param string|ISearchOperator $query |
|
| 195 | + * @return \OC\Files\Node\Node[] |
|
| 196 | + */ |
|
| 197 | + public function search($query) { |
|
| 198 | + if (is_string($query)) { |
|
| 199 | + return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 200 | + } else { |
|
| 201 | + return $this->searchCommon('searchQuery', array($query)); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * search for files by mimetype |
|
| 207 | + * |
|
| 208 | + * @param string $mimetype |
|
| 209 | + * @return Node[] |
|
| 210 | + */ |
|
| 211 | + public function searchByMime($mimetype) { |
|
| 212 | + return $this->searchCommon('searchByMime', array($mimetype)); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * search for files by tag |
|
| 217 | + * |
|
| 218 | + * @param string|int $tag name or tag id |
|
| 219 | + * @param string $userId owner of the tags |
|
| 220 | + * @return Node[] |
|
| 221 | + */ |
|
| 222 | + public function searchByTag($tag, $userId) { |
|
| 223 | + return $this->searchCommon('searchByTag', array($tag, $userId)); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $method cache method |
|
| 228 | + * @param array $args call args |
|
| 229 | + * @return \OC\Files\Node\Node[] |
|
| 230 | + */ |
|
| 231 | + private function searchCommon($method, $args) { |
|
| 232 | + $files = array(); |
|
| 233 | + $rootLength = strlen($this->path); |
|
| 234 | + $mount = $this->root->getMount($this->path); |
|
| 235 | + $storage = $mount->getStorage(); |
|
| 236 | + $internalPath = $mount->getInternalPath($this->path); |
|
| 237 | + $internalPath = rtrim($internalPath, '/'); |
|
| 238 | + if ($internalPath !== '') { |
|
| 239 | + $internalPath = $internalPath . '/'; |
|
| 240 | + } |
|
| 241 | + $internalRootLength = strlen($internalPath); |
|
| 242 | + |
|
| 243 | + $cache = $storage->getCache(''); |
|
| 244 | + |
|
| 245 | + $results = call_user_func_array(array($cache, $method), $args); |
|
| 246 | + foreach ($results as $result) { |
|
| 247 | + if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { |
|
| 248 | + $result['internalPath'] = $result['path']; |
|
| 249 | + $result['path'] = substr($result['path'], $internalRootLength); |
|
| 250 | + $result['storage'] = $storage; |
|
| 251 | + $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 256 | + foreach ($mounts as $mount) { |
|
| 257 | + $storage = $mount->getStorage(); |
|
| 258 | + if ($storage) { |
|
| 259 | + $cache = $storage->getCache(''); |
|
| 260 | + |
|
| 261 | + $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); |
|
| 262 | + $results = call_user_func_array(array($cache, $method), $args); |
|
| 263 | + foreach ($results as $result) { |
|
| 264 | + $result['internalPath'] = $result['path']; |
|
| 265 | + $result['path'] = $relativeMountPoint . $result['path']; |
|
| 266 | + $result['storage'] = $storage; |
|
| 267 | + $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return array_map(function (FileInfo $file) { |
|
| 273 | + return $this->createNode($file->getPath(), $file); |
|
| 274 | + }, $files); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param int $id |
|
| 279 | + * @return \OC\Files\Node\Node[] |
|
| 280 | + */ |
|
| 281 | + public function getById($id) { |
|
| 282 | + $mountCache = $this->root->getUserMountCache(); |
|
| 283 | + $mountsContainingFile = $mountCache->getMountsForFileId((int)$id); |
|
| 284 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 285 | + $mounts[] = $this->root->getMount($this->path); |
|
| 286 | + /** @var IMountPoint[] $folderMounts */ |
|
| 287 | + $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 288 | + return $mountPoint->getMountPoint(); |
|
| 289 | + }, $mounts), $mounts); |
|
| 290 | + |
|
| 291 | + /** @var ICachedMountInfo[] $mountsContainingFile */ |
|
| 292 | + $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 293 | + return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
|
| 294 | + })); |
|
| 295 | + |
|
| 296 | + if (count($mountsContainingFile) === 0) { |
|
| 297 | + return []; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // we only need to get the cache info once, since all mounts we found point to the same storage |
|
| 301 | + |
|
| 302 | + $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
|
| 303 | + $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 304 | + if (!$cacheEntry) { |
|
| 305 | + return []; |
|
| 306 | + } |
|
| 307 | + // cache jails will hide the "true" internal path |
|
| 308 | + $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 309 | + |
|
| 310 | + $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 311 | + $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
|
| 312 | + $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
|
| 313 | + $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
|
| 314 | + $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 315 | + return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
|
| 316 | + $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
|
| 317 | + \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
|
| 318 | + )); |
|
| 319 | + }, $mountsContainingFile); |
|
| 320 | + |
|
| 321 | + return array_filter($nodes, function (Node $node) { |
|
| 322 | + return $this->getRelativePath($node->getPath()); |
|
| 323 | + }); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + public function getFreeSpace() { |
|
| 327 | + return $this->view->free_space($this->path); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public function delete() { |
|
| 331 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { |
|
| 332 | + $this->sendHooks(array('preDelete')); |
|
| 333 | + $fileInfo = $this->getFileInfo(); |
|
| 334 | + $this->view->rmdir($this->path); |
|
| 335 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); |
|
| 336 | + $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); |
|
| 337 | + $this->exists = false; |
|
| 338 | + } else { |
|
| 339 | + throw new NotPermittedException('No delete permission for path'); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Add a suffix to the name in case the file exists |
|
| 345 | + * |
|
| 346 | + * @param string $name |
|
| 347 | + * @return string |
|
| 348 | + * @throws NotPermittedException |
|
| 349 | + */ |
|
| 350 | + public function getNonExistingName($name) { |
|
| 351 | + $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); |
|
| 352 | + return trim($this->getRelativePath($uniqueName), '/'); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * @param int $limit |
|
| 357 | + * @param int $offset |
|
| 358 | + * @return \OCP\Files\Node[] |
|
| 359 | + */ |
|
| 360 | + public function getRecent($limit, $offset = 0) { |
|
| 361 | + $mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 362 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 363 | + $mounts[] = $this->getMountPoint(); |
|
| 364 | + |
|
| 365 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 366 | + return $mount->getStorage(); |
|
| 367 | + }); |
|
| 368 | + $storageIds = array_map(function (IMountPoint $mount) { |
|
| 369 | + return $mount->getStorage()->getCache()->getNumericStorageId(); |
|
| 370 | + }, $mounts); |
|
| 371 | + /** @var IMountPoint[] $mountMap */ |
|
| 372 | + $mountMap = array_combine($storageIds, $mounts); |
|
| 373 | + $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); |
|
| 374 | + |
|
| 375 | + //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) |
|
| 376 | + |
|
| 377 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 378 | + $query = $builder |
|
| 379 | + ->select('f.*') |
|
| 380 | + ->from('filecache', 'f') |
|
| 381 | + ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 382 | + ->andWhere($builder->expr()->orX( |
|
| 383 | + // handle non empty folders separate |
|
| 384 | + $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), |
|
| 385 | + $builder->expr()->eq('f.size', new Literal(0)) |
|
| 386 | + )) |
|
| 387 | + ->orderBy('f.mtime', 'DESC') |
|
| 388 | + ->setMaxResults($limit) |
|
| 389 | + ->setFirstResult($offset); |
|
| 390 | + |
|
| 391 | + $result = $query->execute()->fetchAll(); |
|
| 392 | + |
|
| 393 | + $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 394 | + $mount = $mountMap[$entry['storage']]; |
|
| 395 | + $entry['internalPath'] = $entry['path']; |
|
| 396 | + $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
|
| 397 | + $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); |
|
| 398 | + $path = $this->getAbsolutePath($mount, $entry['path']); |
|
| 399 | + if (is_null($path)) { |
|
| 400 | + return null; |
|
| 401 | + } |
|
| 402 | + $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); |
|
| 403 | + return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
|
| 404 | + }, $result)); |
|
| 405 | + |
|
| 406 | + return array_values(array_filter($files, function (Node $node) { |
|
| 407 | + $relative = $this->getRelativePath($node->getPath()); |
|
| 408 | + return $relative !== null && $relative !== '/'; |
|
| 409 | + })); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + private function getAbsolutePath(IMountPoint $mount, $path) { |
|
| 413 | + $storage = $mount->getStorage(); |
|
| 414 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { |
|
| 415 | + /** @var \OC\Files\Storage\Wrapper\Jail $storage */ |
|
| 416 | + $jailRoot = $storage->getSourcePath(''); |
|
| 417 | + $rootLength = strlen($jailRoot) + 1; |
|
| 418 | + if ($path === $jailRoot) { |
|
| 419 | + return $mount->getMountPoint(); |
|
| 420 | + } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 421 | + return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 422 | + } else { |
|
| 423 | + return null; |
|
| 424 | + } |
|
| 425 | + } else { |
|
| 426 | + return $mount->getMountPoint() . $path; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | 429 | } |
@@ -26,55 +26,55 @@ |
||
| 26 | 26 | use OCP\Files\Search\ISearchQuery; |
| 27 | 27 | |
| 28 | 28 | class SearchQuery implements ISearchQuery { |
| 29 | - /** @var ISearchOperator */ |
|
| 30 | - private $searchOperation; |
|
| 31 | - /** @var integer */ |
|
| 32 | - private $limit; |
|
| 33 | - /** @var integer */ |
|
| 34 | - private $offset; |
|
| 35 | - /** @var ISearchOrder[] */ |
|
| 36 | - private $order; |
|
| 29 | + /** @var ISearchOperator */ |
|
| 30 | + private $searchOperation; |
|
| 31 | + /** @var integer */ |
|
| 32 | + private $limit; |
|
| 33 | + /** @var integer */ |
|
| 34 | + private $offset; |
|
| 35 | + /** @var ISearchOrder[] */ |
|
| 36 | + private $order; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * SearchQuery constructor. |
|
| 40 | - * |
|
| 41 | - * @param ISearchOperator $searchOperation |
|
| 42 | - * @param int $limit |
|
| 43 | - * @param int $offset |
|
| 44 | - * @param array $order |
|
| 45 | - */ |
|
| 46 | - public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order) { |
|
| 47 | - $this->searchOperation = $searchOperation; |
|
| 48 | - $this->limit = $limit; |
|
| 49 | - $this->offset = $offset; |
|
| 50 | - $this->order = $order; |
|
| 51 | - } |
|
| 38 | + /** |
|
| 39 | + * SearchQuery constructor. |
|
| 40 | + * |
|
| 41 | + * @param ISearchOperator $searchOperation |
|
| 42 | + * @param int $limit |
|
| 43 | + * @param int $offset |
|
| 44 | + * @param array $order |
|
| 45 | + */ |
|
| 46 | + public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order) { |
|
| 47 | + $this->searchOperation = $searchOperation; |
|
| 48 | + $this->limit = $limit; |
|
| 49 | + $this->offset = $offset; |
|
| 50 | + $this->order = $order; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return ISearchOperator |
|
| 55 | - */ |
|
| 56 | - public function getSearchOperation() { |
|
| 57 | - return $this->searchOperation; |
|
| 58 | - } |
|
| 53 | + /** |
|
| 54 | + * @return ISearchOperator |
|
| 55 | + */ |
|
| 56 | + public function getSearchOperation() { |
|
| 57 | + return $this->searchOperation; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return int |
|
| 62 | - */ |
|
| 63 | - public function getLimit() { |
|
| 64 | - return $this->limit; |
|
| 65 | - } |
|
| 60 | + /** |
|
| 61 | + * @return int |
|
| 62 | + */ |
|
| 63 | + public function getLimit() { |
|
| 64 | + return $this->limit; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 70 | - public function getOffset() { |
|
| 71 | - return $this->offset; |
|
| 72 | - } |
|
| 67 | + /** |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | + public function getOffset() { |
|
| 71 | + return $this->offset; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return ISearchOrder[] |
|
| 76 | - */ |
|
| 77 | - public function getOrder() { |
|
| 78 | - return $this->order; |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * @return ISearchOrder[] |
|
| 76 | + */ |
|
| 77 | + public function getOrder() { |
|
| 78 | + return $this->order; |
|
| 79 | + } |
|
| 80 | 80 | } |