@@ -182,6 +182,7 @@ |
||
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | 184 | * @param string $dir |
| 185 | + * @param boolean $recursive |
|
| 185 | 186 | * @throws \OC\ForbiddenException |
| 186 | 187 | * @throws \OCP\Files\NotFoundException |
| 187 | 188 | */ |
@@ -50,233 +50,233 @@ |
||
| 50 | 50 | * @package OC\Files\Utils |
| 51 | 51 | */ |
| 52 | 52 | class Scanner extends PublicEmitter { |
| 53 | - const MAX_ENTRIES_TO_COMMIT = 10000; |
|
| 53 | + const MAX_ENTRIES_TO_COMMIT = 10000; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string $user |
|
| 57 | - */ |
|
| 58 | - private $user; |
|
| 55 | + /** |
|
| 56 | + * @var string $user |
|
| 57 | + */ |
|
| 58 | + private $user; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var \OCP\IDBConnection |
|
| 62 | - */ |
|
| 63 | - protected $db; |
|
| 60 | + /** |
|
| 61 | + * @var \OCP\IDBConnection |
|
| 62 | + */ |
|
| 63 | + protected $db; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var ILogger |
|
| 67 | - */ |
|
| 68 | - protected $logger; |
|
| 65 | + /** |
|
| 66 | + * @var ILogger |
|
| 67 | + */ |
|
| 68 | + protected $logger; |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Whether to use a DB transaction |
|
| 72 | - * |
|
| 73 | - * @var bool |
|
| 74 | - */ |
|
| 75 | - protected $useTransaction; |
|
| 70 | + /** |
|
| 71 | + * Whether to use a DB transaction |
|
| 72 | + * |
|
| 73 | + * @var bool |
|
| 74 | + */ |
|
| 75 | + protected $useTransaction; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Number of entries scanned to commit |
|
| 79 | - * |
|
| 80 | - * @var int |
|
| 81 | - */ |
|
| 82 | - protected $entriesToCommit; |
|
| 77 | + /** |
|
| 78 | + * Number of entries scanned to commit |
|
| 79 | + * |
|
| 80 | + * @var int |
|
| 81 | + */ |
|
| 82 | + protected $entriesToCommit; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @param string $user |
|
| 86 | - * @param \OCP\IDBConnection $db |
|
| 87 | - * @param ILogger $logger |
|
| 88 | - */ |
|
| 89 | - public function __construct($user, $db, ILogger $logger) { |
|
| 90 | - $this->logger = $logger; |
|
| 91 | - $this->user = $user; |
|
| 92 | - $this->db = $db; |
|
| 93 | - // when DB locking is used, no DB transactions will be used |
|
| 94 | - $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); |
|
| 95 | - } |
|
| 84 | + /** |
|
| 85 | + * @param string $user |
|
| 86 | + * @param \OCP\IDBConnection $db |
|
| 87 | + * @param ILogger $logger |
|
| 88 | + */ |
|
| 89 | + public function __construct($user, $db, ILogger $logger) { |
|
| 90 | + $this->logger = $logger; |
|
| 91 | + $this->user = $user; |
|
| 92 | + $this->db = $db; |
|
| 93 | + // when DB locking is used, no DB transactions will be used |
|
| 94 | + $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * get all storages for $dir |
|
| 99 | - * |
|
| 100 | - * @param string $dir |
|
| 101 | - * @return \OC\Files\Mount\MountPoint[] |
|
| 102 | - */ |
|
| 103 | - protected function getMounts($dir) { |
|
| 104 | - //TODO: move to the node based fileapi once that's done |
|
| 105 | - \OC_Util::tearDownFS(); |
|
| 106 | - \OC_Util::setupFS($this->user); |
|
| 97 | + /** |
|
| 98 | + * get all storages for $dir |
|
| 99 | + * |
|
| 100 | + * @param string $dir |
|
| 101 | + * @return \OC\Files\Mount\MountPoint[] |
|
| 102 | + */ |
|
| 103 | + protected function getMounts($dir) { |
|
| 104 | + //TODO: move to the node based fileapi once that's done |
|
| 105 | + \OC_Util::tearDownFS(); |
|
| 106 | + \OC_Util::setupFS($this->user); |
|
| 107 | 107 | |
| 108 | - $mountManager = Filesystem::getMountManager(); |
|
| 109 | - $mounts = $mountManager->findIn($dir); |
|
| 110 | - $mounts[] = $mountManager->find($dir); |
|
| 111 | - $mounts = array_reverse($mounts); //start with the mount of $dir |
|
| 108 | + $mountManager = Filesystem::getMountManager(); |
|
| 109 | + $mounts = $mountManager->findIn($dir); |
|
| 110 | + $mounts[] = $mountManager->find($dir); |
|
| 111 | + $mounts = array_reverse($mounts); //start with the mount of $dir |
|
| 112 | 112 | |
| 113 | - return $mounts; |
|
| 114 | - } |
|
| 113 | + return $mounts; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * attach listeners to the scanner |
|
| 118 | - * |
|
| 119 | - * @param \OC\Files\Mount\MountPoint $mount |
|
| 120 | - */ |
|
| 121 | - protected function attachListener($mount) { |
|
| 122 | - $scanner = $mount->getStorage()->getScanner(); |
|
| 123 | - $emitter = $this; |
|
| 124 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
| 125 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
| 126 | - }); |
|
| 127 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
| 128 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
| 129 | - }); |
|
| 130 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
| 131 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
| 132 | - }); |
|
| 133 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
| 134 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
| 135 | - }); |
|
| 136 | - } |
|
| 116 | + /** |
|
| 117 | + * attach listeners to the scanner |
|
| 118 | + * |
|
| 119 | + * @param \OC\Files\Mount\MountPoint $mount |
|
| 120 | + */ |
|
| 121 | + protected function attachListener($mount) { |
|
| 122 | + $scanner = $mount->getStorage()->getScanner(); |
|
| 123 | + $emitter = $this; |
|
| 124 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
| 125 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
| 126 | + }); |
|
| 127 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
| 128 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
| 129 | + }); |
|
| 130 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
| 131 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
| 132 | + }); |
|
| 133 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
| 134 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
| 135 | + }); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * @param string $dir |
|
| 140 | - */ |
|
| 141 | - public function backgroundScan($dir) { |
|
| 142 | - $mounts = $this->getMounts($dir); |
|
| 143 | - foreach ($mounts as $mount) { |
|
| 144 | - $storage = $mount->getStorage(); |
|
| 145 | - if (is_null($storage)) { |
|
| 146 | - continue; |
|
| 147 | - } |
|
| 138 | + /** |
|
| 139 | + * @param string $dir |
|
| 140 | + */ |
|
| 141 | + public function backgroundScan($dir) { |
|
| 142 | + $mounts = $this->getMounts($dir); |
|
| 143 | + foreach ($mounts as $mount) { |
|
| 144 | + $storage = $mount->getStorage(); |
|
| 145 | + if (is_null($storage)) { |
|
| 146 | + continue; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - // don't bother scanning failed storages (shortcut for same result) |
|
| 150 | - if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
| 151 | - continue; |
|
| 152 | - } |
|
| 149 | + // don't bother scanning failed storages (shortcut for same result) |
|
| 150 | + if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
| 151 | + continue; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - // don't scan the root storage |
|
| 155 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Local') && $mount->getMountPoint() === '/') { |
|
| 156 | - continue; |
|
| 157 | - } |
|
| 154 | + // don't scan the root storage |
|
| 155 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Local') && $mount->getMountPoint() === '/') { |
|
| 156 | + continue; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
| 160 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
| 161 | - continue; |
|
| 162 | - } |
|
| 163 | - $scanner = $storage->getScanner(); |
|
| 164 | - $this->attachListener($mount); |
|
| 159 | + // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
| 160 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
| 161 | + continue; |
|
| 162 | + } |
|
| 163 | + $scanner = $storage->getScanner(); |
|
| 164 | + $this->attachListener($mount); |
|
| 165 | 165 | |
| 166 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 167 | - $this->triggerPropagator($storage, $path); |
|
| 168 | - }); |
|
| 169 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 170 | - $this->triggerPropagator($storage, $path); |
|
| 171 | - }); |
|
| 172 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 173 | - $this->triggerPropagator($storage, $path); |
|
| 174 | - }); |
|
| 166 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 167 | + $this->triggerPropagator($storage, $path); |
|
| 168 | + }); |
|
| 169 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 170 | + $this->triggerPropagator($storage, $path); |
|
| 171 | + }); |
|
| 172 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 173 | + $this->triggerPropagator($storage, $path); |
|
| 174 | + }); |
|
| 175 | 175 | |
| 176 | - $propagator = $storage->getPropagator(); |
|
| 177 | - $propagator->beginBatch(); |
|
| 178 | - $scanner->backgroundScan(); |
|
| 179 | - $propagator->commitBatch(); |
|
| 180 | - } |
|
| 181 | - } |
|
| 176 | + $propagator = $storage->getPropagator(); |
|
| 177 | + $propagator->beginBatch(); |
|
| 178 | + $scanner->backgroundScan(); |
|
| 179 | + $propagator->commitBatch(); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * @param string $dir |
|
| 185 | - * @throws \OC\ForbiddenException |
|
| 186 | - * @throws \OCP\Files\NotFoundException |
|
| 187 | - */ |
|
| 188 | - public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE) { |
|
| 189 | - if (!Filesystem::isValidPath($dir)) { |
|
| 190 | - throw new \InvalidArgumentException('Invalid path to scan'); |
|
| 191 | - } |
|
| 192 | - $mounts = $this->getMounts($dir); |
|
| 193 | - foreach ($mounts as $mount) { |
|
| 194 | - $storage = $mount->getStorage(); |
|
| 195 | - if (is_null($storage)) { |
|
| 196 | - continue; |
|
| 197 | - } |
|
| 183 | + /** |
|
| 184 | + * @param string $dir |
|
| 185 | + * @throws \OC\ForbiddenException |
|
| 186 | + * @throws \OCP\Files\NotFoundException |
|
| 187 | + */ |
|
| 188 | + public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE) { |
|
| 189 | + if (!Filesystem::isValidPath($dir)) { |
|
| 190 | + throw new \InvalidArgumentException('Invalid path to scan'); |
|
| 191 | + } |
|
| 192 | + $mounts = $this->getMounts($dir); |
|
| 193 | + foreach ($mounts as $mount) { |
|
| 194 | + $storage = $mount->getStorage(); |
|
| 195 | + if (is_null($storage)) { |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - // don't bother scanning failed storages (shortcut for same result) |
|
| 200 | - if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
| 201 | - continue; |
|
| 202 | - } |
|
| 199 | + // don't bother scanning failed storages (shortcut for same result) |
|
| 200 | + if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
| 201 | + continue; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // if the home storage isn't writable then the scanner is run as the wrong user |
|
| 205 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
| 206 | - (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
| 207 | - ) { |
|
| 208 | - if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
| 209 | - throw new ForbiddenException(); |
|
| 210 | - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
| 211 | - break; |
|
| 212 | - } |
|
| 204 | + // if the home storage isn't writable then the scanner is run as the wrong user |
|
| 205 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
| 206 | + (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
| 207 | + ) { |
|
| 208 | + if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
| 209 | + throw new ForbiddenException(); |
|
| 210 | + } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
| 211 | + break; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
| 217 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
| 218 | - continue; |
|
| 219 | - } |
|
| 220 | - $relativePath = $mount->getInternalPath($dir); |
|
| 221 | - $scanner = $storage->getScanner(); |
|
| 222 | - $scanner->setUseTransactions(false); |
|
| 223 | - $this->attachListener($mount); |
|
| 216 | + // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
| 217 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 220 | + $relativePath = $mount->getInternalPath($dir); |
|
| 221 | + $scanner = $storage->getScanner(); |
|
| 222 | + $scanner->setUseTransactions(false); |
|
| 223 | + $this->attachListener($mount); |
|
| 224 | 224 | |
| 225 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 226 | - $this->postProcessEntry($storage, $path); |
|
| 227 | - }); |
|
| 228 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 229 | - $this->postProcessEntry($storage, $path); |
|
| 230 | - }); |
|
| 231 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 232 | - $this->postProcessEntry($storage, $path); |
|
| 233 | - }); |
|
| 225 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
| 226 | + $this->postProcessEntry($storage, $path); |
|
| 227 | + }); |
|
| 228 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
| 229 | + $this->postProcessEntry($storage, $path); |
|
| 230 | + }); |
|
| 231 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
| 232 | + $this->postProcessEntry($storage, $path); |
|
| 233 | + }); |
|
| 234 | 234 | |
| 235 | - if (!$storage->file_exists($relativePath)) { |
|
| 236 | - throw new NotFoundException($dir); |
|
| 237 | - } |
|
| 235 | + if (!$storage->file_exists($relativePath)) { |
|
| 236 | + throw new NotFoundException($dir); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - if ($this->useTransaction) { |
|
| 240 | - $this->db->beginTransaction(); |
|
| 241 | - } |
|
| 242 | - try { |
|
| 243 | - $propagator = $storage->getPropagator(); |
|
| 244 | - $propagator->beginBatch(); |
|
| 245 | - $scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
| 246 | - $cache = $storage->getCache(); |
|
| 247 | - if ($cache instanceof Cache) { |
|
| 248 | - // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
| 249 | - $cache->correctFolderSize($relativePath); |
|
| 250 | - } |
|
| 251 | - $propagator->commitBatch(); |
|
| 252 | - } catch (StorageNotAvailableException $e) { |
|
| 253 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
| 254 | - $this->logger->logException($e); |
|
| 255 | - $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
| 256 | - } |
|
| 257 | - if ($this->useTransaction) { |
|
| 258 | - $this->db->commit(); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } |
|
| 239 | + if ($this->useTransaction) { |
|
| 240 | + $this->db->beginTransaction(); |
|
| 241 | + } |
|
| 242 | + try { |
|
| 243 | + $propagator = $storage->getPropagator(); |
|
| 244 | + $propagator->beginBatch(); |
|
| 245 | + $scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
| 246 | + $cache = $storage->getCache(); |
|
| 247 | + if ($cache instanceof Cache) { |
|
| 248 | + // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
| 249 | + $cache->correctFolderSize($relativePath); |
|
| 250 | + } |
|
| 251 | + $propagator->commitBatch(); |
|
| 252 | + } catch (StorageNotAvailableException $e) { |
|
| 253 | + $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
| 254 | + $this->logger->logException($e); |
|
| 255 | + $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
| 256 | + } |
|
| 257 | + if ($this->useTransaction) { |
|
| 258 | + $this->db->commit(); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - private function triggerPropagator(IStorage $storage, $internalPath) { |
|
| 264 | - $storage->getPropagator()->propagateChange($internalPath, time()); |
|
| 265 | - } |
|
| 263 | + private function triggerPropagator(IStorage $storage, $internalPath) { |
|
| 264 | + $storage->getPropagator()->propagateChange($internalPath, time()); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - private function postProcessEntry(IStorage $storage, $internalPath) { |
|
| 268 | - $this->triggerPropagator($storage, $internalPath); |
|
| 269 | - if ($this->useTransaction) { |
|
| 270 | - $this->entriesToCommit++; |
|
| 271 | - if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { |
|
| 272 | - $propagator = $storage->getPropagator(); |
|
| 273 | - $this->entriesToCommit = 0; |
|
| 274 | - $this->db->commit(); |
|
| 275 | - $propagator->commitBatch(); |
|
| 276 | - $this->db->beginTransaction(); |
|
| 277 | - $propagator->beginBatch(); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 267 | + private function postProcessEntry(IStorage $storage, $internalPath) { |
|
| 268 | + $this->triggerPropagator($storage, $internalPath); |
|
| 269 | + if ($this->useTransaction) { |
|
| 270 | + $this->entriesToCommit++; |
|
| 271 | + if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { |
|
| 272 | + $propagator = $storage->getPropagator(); |
|
| 273 | + $this->entriesToCommit = 0; |
|
| 274 | + $this->db->commit(); |
|
| 275 | + $propagator->commitBatch(); |
|
| 276 | + $this->db->beginTransaction(); |
|
| 277 | + $propagator->beginBatch(); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
@@ -44,315 +44,315 @@ |
||
| 44 | 44 | |
| 45 | 45 | class Scan extends Base { |
| 46 | 46 | |
| 47 | - /** @var IUserManager $userManager */ |
|
| 48 | - private $userManager; |
|
| 49 | - /** @var float */ |
|
| 50 | - protected $execTime = 0; |
|
| 51 | - /** @var int */ |
|
| 52 | - protected $foldersCounter = 0; |
|
| 53 | - /** @var int */ |
|
| 54 | - protected $filesCounter = 0; |
|
| 47 | + /** @var IUserManager $userManager */ |
|
| 48 | + private $userManager; |
|
| 49 | + /** @var float */ |
|
| 50 | + protected $execTime = 0; |
|
| 51 | + /** @var int */ |
|
| 52 | + protected $foldersCounter = 0; |
|
| 53 | + /** @var int */ |
|
| 54 | + protected $filesCounter = 0; |
|
| 55 | 55 | |
| 56 | - public function __construct(IUserManager $userManager) { |
|
| 57 | - $this->userManager = $userManager; |
|
| 58 | - parent::__construct(); |
|
| 59 | - } |
|
| 56 | + public function __construct(IUserManager $userManager) { |
|
| 57 | + $this->userManager = $userManager; |
|
| 58 | + parent::__construct(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - protected function configure() { |
|
| 62 | - parent::configure(); |
|
| 61 | + protected function configure() { |
|
| 62 | + parent::configure(); |
|
| 63 | 63 | |
| 64 | - $this |
|
| 65 | - ->setName('files:scan') |
|
| 66 | - ->setDescription('rescan filesystem') |
|
| 67 | - ->addArgument( |
|
| 68 | - 'user_id', |
|
| 69 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 70 | - 'will rescan all files of the given user(s)' |
|
| 71 | - ) |
|
| 72 | - ->addOption( |
|
| 73 | - 'path', |
|
| 74 | - 'p', |
|
| 75 | - InputArgument::OPTIONAL, |
|
| 76 | - 'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' |
|
| 77 | - ) |
|
| 78 | - ->addOption( |
|
| 79 | - 'quiet', |
|
| 80 | - 'q', |
|
| 81 | - InputOption::VALUE_NONE, |
|
| 82 | - 'suppress any output' |
|
| 83 | - ) |
|
| 84 | - ->addOption( |
|
| 85 | - 'verbose', |
|
| 86 | - '-v|vv|vvv', |
|
| 87 | - InputOption::VALUE_NONE, |
|
| 88 | - 'verbose the output' |
|
| 89 | - ) |
|
| 90 | - ->addOption( |
|
| 91 | - 'all', |
|
| 92 | - null, |
|
| 93 | - InputOption::VALUE_NONE, |
|
| 94 | - 'will rescan all files of all known users' |
|
| 95 | - )->addOption( |
|
| 96 | - 'unscanned', |
|
| 97 | - null, |
|
| 98 | - InputOption::VALUE_NONE, |
|
| 99 | - 'only scan files which are marked as not fully scanned' |
|
| 100 | - )->addOption( |
|
| 101 | - 'shallow', |
|
| 102 | - null, |
|
| 103 | - InputOption::VALUE_NONE, |
|
| 104 | - 'do not scan folders recursively' |
|
| 105 | - ); |
|
| 106 | - } |
|
| 64 | + $this |
|
| 65 | + ->setName('files:scan') |
|
| 66 | + ->setDescription('rescan filesystem') |
|
| 67 | + ->addArgument( |
|
| 68 | + 'user_id', |
|
| 69 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 70 | + 'will rescan all files of the given user(s)' |
|
| 71 | + ) |
|
| 72 | + ->addOption( |
|
| 73 | + 'path', |
|
| 74 | + 'p', |
|
| 75 | + InputArgument::OPTIONAL, |
|
| 76 | + 'limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored' |
|
| 77 | + ) |
|
| 78 | + ->addOption( |
|
| 79 | + 'quiet', |
|
| 80 | + 'q', |
|
| 81 | + InputOption::VALUE_NONE, |
|
| 82 | + 'suppress any output' |
|
| 83 | + ) |
|
| 84 | + ->addOption( |
|
| 85 | + 'verbose', |
|
| 86 | + '-v|vv|vvv', |
|
| 87 | + InputOption::VALUE_NONE, |
|
| 88 | + 'verbose the output' |
|
| 89 | + ) |
|
| 90 | + ->addOption( |
|
| 91 | + 'all', |
|
| 92 | + null, |
|
| 93 | + InputOption::VALUE_NONE, |
|
| 94 | + 'will rescan all files of all known users' |
|
| 95 | + )->addOption( |
|
| 96 | + 'unscanned', |
|
| 97 | + null, |
|
| 98 | + InputOption::VALUE_NONE, |
|
| 99 | + 'only scan files which are marked as not fully scanned' |
|
| 100 | + )->addOption( |
|
| 101 | + 'shallow', |
|
| 102 | + null, |
|
| 103 | + InputOption::VALUE_NONE, |
|
| 104 | + 'do not scan folders recursively' |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - public function checkScanWarning($fullPath, OutputInterface $output) { |
|
| 109 | - $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
| 110 | - $path = basename($fullPath); |
|
| 108 | + public function checkScanWarning($fullPath, OutputInterface $output) { |
|
| 109 | + $normalizedPath = basename(\OC\Files\Filesystem::normalizePath($fullPath)); |
|
| 110 | + $path = basename($fullPath); |
|
| 111 | 111 | |
| 112 | - if ($normalizedPath !== $path) { |
|
| 113 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 114 | - } |
|
| 115 | - } |
|
| 112 | + if ($normalizedPath !== $path) { |
|
| 113 | + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true) { |
|
| 118 | - $connection = $this->reconnectToDatabase($output); |
|
| 119 | - $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger()); |
|
| 120 | - # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 121 | - # printout and count |
|
| 122 | - if ($verbose) { |
|
| 123 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 124 | - $output->writeln("\tFile <info>$path</info>"); |
|
| 125 | - $this->filesCounter += 1; |
|
| 126 | - if ($this->hasBeenInterrupted()) { |
|
| 127 | - throw new InterruptedException(); |
|
| 128 | - } |
|
| 129 | - }); |
|
| 130 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 131 | - $output->writeln("\tFolder <info>$path</info>"); |
|
| 132 | - $this->foldersCounter += 1; |
|
| 133 | - if ($this->hasBeenInterrupted()) { |
|
| 134 | - throw new InterruptedException(); |
|
| 135 | - } |
|
| 136 | - }); |
|
| 137 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 138 | - $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")"); |
|
| 139 | - }); |
|
| 140 | - # count only |
|
| 141 | - } else { |
|
| 142 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 143 | - $this->filesCounter += 1; |
|
| 144 | - if ($this->hasBeenInterrupted()) { |
|
| 145 | - throw new InterruptedException(); |
|
| 146 | - } |
|
| 147 | - }); |
|
| 148 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 149 | - $this->foldersCounter += 1; |
|
| 150 | - if ($this->hasBeenInterrupted()) { |
|
| 151 | - throw new InterruptedException(); |
|
| 152 | - } |
|
| 153 | - }); |
|
| 154 | - } |
|
| 155 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 156 | - $this->checkScanWarning($path, $output); |
|
| 157 | - }); |
|
| 158 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 159 | - $this->checkScanWarning($path, $output); |
|
| 160 | - }); |
|
| 117 | + protected function scanFiles($user, $path, $verbose, OutputInterface $output, $backgroundScan = false, $recursive = true) { |
|
| 118 | + $connection = $this->reconnectToDatabase($output); |
|
| 119 | + $scanner = new \OC\Files\Utils\Scanner($user, $connection, \OC::$server->getLogger()); |
|
| 120 | + # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 121 | + # printout and count |
|
| 122 | + if ($verbose) { |
|
| 123 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 124 | + $output->writeln("\tFile <info>$path</info>"); |
|
| 125 | + $this->filesCounter += 1; |
|
| 126 | + if ($this->hasBeenInterrupted()) { |
|
| 127 | + throw new InterruptedException(); |
|
| 128 | + } |
|
| 129 | + }); |
|
| 130 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 131 | + $output->writeln("\tFolder <info>$path</info>"); |
|
| 132 | + $this->foldersCounter += 1; |
|
| 133 | + if ($this->hasBeenInterrupted()) { |
|
| 134 | + throw new InterruptedException(); |
|
| 135 | + } |
|
| 136 | + }); |
|
| 137 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 138 | + $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")"); |
|
| 139 | + }); |
|
| 140 | + # count only |
|
| 141 | + } else { |
|
| 142 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 143 | + $this->filesCounter += 1; |
|
| 144 | + if ($this->hasBeenInterrupted()) { |
|
| 145 | + throw new InterruptedException(); |
|
| 146 | + } |
|
| 147 | + }); |
|
| 148 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 149 | + $this->foldersCounter += 1; |
|
| 150 | + if ($this->hasBeenInterrupted()) { |
|
| 151 | + throw new InterruptedException(); |
|
| 152 | + } |
|
| 153 | + }); |
|
| 154 | + } |
|
| 155 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 156 | + $this->checkScanWarning($path, $output); |
|
| 157 | + }); |
|
| 158 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 159 | + $this->checkScanWarning($path, $output); |
|
| 160 | + }); |
|
| 161 | 161 | |
| 162 | - try { |
|
| 163 | - if ($backgroundScan) { |
|
| 164 | - $scanner->backgroundScan($path); |
|
| 165 | - } else { |
|
| 166 | - $scanner->scan($path, $recursive); |
|
| 167 | - } |
|
| 168 | - } catch (ForbiddenException $e) { |
|
| 169 | - $output->writeln("<error>Home storage for user $user not writable</error>"); |
|
| 170 | - $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); |
|
| 171 | - } catch (InterruptedException $e) { |
|
| 172 | - # exit the function if ctrl-c has been pressed |
|
| 173 | - $output->writeln('Interrupted by user'); |
|
| 174 | - } catch (NotFoundException $e) { |
|
| 175 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 176 | - } catch (\Exception $e) { |
|
| 177 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 178 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 179 | - } |
|
| 180 | - } |
|
| 162 | + try { |
|
| 163 | + if ($backgroundScan) { |
|
| 164 | + $scanner->backgroundScan($path); |
|
| 165 | + } else { |
|
| 166 | + $scanner->scan($path, $recursive); |
|
| 167 | + } |
|
| 168 | + } catch (ForbiddenException $e) { |
|
| 169 | + $output->writeln("<error>Home storage for user $user not writable</error>"); |
|
| 170 | + $output->writeln("Make sure you're running the scan command only as the user the web server runs as"); |
|
| 171 | + } catch (InterruptedException $e) { |
|
| 172 | + # exit the function if ctrl-c has been pressed |
|
| 173 | + $output->writeln('Interrupted by user'); |
|
| 174 | + } catch (NotFoundException $e) { |
|
| 175 | + $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 176 | + } catch (\Exception $e) { |
|
| 177 | + $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 178 | + $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 184 | - $inputPath = $input->getOption('path'); |
|
| 185 | - if ($inputPath) { |
|
| 186 | - $inputPath = '/' . trim($inputPath, '/'); |
|
| 187 | - list (, $user,) = explode('/', $inputPath, 3); |
|
| 188 | - $users = array($user); |
|
| 189 | - } else if ($input->getOption('all')) { |
|
| 190 | - $users = $this->userManager->search(''); |
|
| 191 | - } else { |
|
| 192 | - $users = $input->getArgument('user_id'); |
|
| 193 | - } |
|
| 183 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 184 | + $inputPath = $input->getOption('path'); |
|
| 185 | + if ($inputPath) { |
|
| 186 | + $inputPath = '/' . trim($inputPath, '/'); |
|
| 187 | + list (, $user,) = explode('/', $inputPath, 3); |
|
| 188 | + $users = array($user); |
|
| 189 | + } else if ($input->getOption('all')) { |
|
| 190 | + $users = $this->userManager->search(''); |
|
| 191 | + } else { |
|
| 192 | + $users = $input->getArgument('user_id'); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - # no messaging level option means: no full printout but statistics |
|
| 196 | - # $quiet means no print at all |
|
| 197 | - # $verbose means full printout including statistics |
|
| 198 | - # -q -v full stat |
|
| 199 | - # 0 0 no yes |
|
| 200 | - # 0 1 yes yes |
|
| 201 | - # 1 -- no no (quiet overrules verbose) |
|
| 202 | - $verbose = $input->getOption('verbose'); |
|
| 203 | - $quiet = $input->getOption('quiet'); |
|
| 204 | - # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 205 | - if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 206 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 207 | - } |
|
| 208 | - if ($quiet) { |
|
| 209 | - $verbose = false; |
|
| 210 | - } |
|
| 195 | + # no messaging level option means: no full printout but statistics |
|
| 196 | + # $quiet means no print at all |
|
| 197 | + # $verbose means full printout including statistics |
|
| 198 | + # -q -v full stat |
|
| 199 | + # 0 0 no yes |
|
| 200 | + # 0 1 yes yes |
|
| 201 | + # 1 -- no no (quiet overrules verbose) |
|
| 202 | + $verbose = $input->getOption('verbose'); |
|
| 203 | + $quiet = $input->getOption('quiet'); |
|
| 204 | + # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 205 | + if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 206 | + $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 207 | + } |
|
| 208 | + if ($quiet) { |
|
| 209 | + $verbose = false; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - # check quantity of users to be process and show it on the command line |
|
| 213 | - $users_total = count($users); |
|
| 214 | - if ($users_total === 0) { |
|
| 215 | - $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); |
|
| 216 | - return; |
|
| 217 | - } else { |
|
| 218 | - if ($users_total > 1) { |
|
| 219 | - $output->writeln("\nScanning files for $users_total users"); |
|
| 220 | - } |
|
| 221 | - } |
|
| 212 | + # check quantity of users to be process and show it on the command line |
|
| 213 | + $users_total = count($users); |
|
| 214 | + if ($users_total === 0) { |
|
| 215 | + $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); |
|
| 216 | + return; |
|
| 217 | + } else { |
|
| 218 | + if ($users_total > 1) { |
|
| 219 | + $output->writeln("\nScanning files for $users_total users"); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - $this->initTools(); |
|
| 223 | + $this->initTools(); |
|
| 224 | 224 | |
| 225 | - $user_count = 0; |
|
| 226 | - foreach ($users as $user) { |
|
| 227 | - if (is_object($user)) { |
|
| 228 | - $user = $user->getUID(); |
|
| 229 | - } |
|
| 230 | - $path = $inputPath ? $inputPath : '/' . $user; |
|
| 231 | - $user_count += 1; |
|
| 232 | - if ($this->userManager->userExists($user)) { |
|
| 233 | - # add an extra line when verbose is set to optical separate users |
|
| 234 | - if ($verbose) { |
|
| 235 | - $output->writeln(""); |
|
| 236 | - } |
|
| 237 | - $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
|
| 238 | - # full: printout data if $verbose was set |
|
| 239 | - $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow')); |
|
| 240 | - } else { |
|
| 241 | - $output->writeln("<error>Unknown user $user_count $user</error>"); |
|
| 242 | - } |
|
| 243 | - # check on each user if there was a user interrupt (ctrl-c) and exit foreach |
|
| 244 | - if ($this->hasBeenInterrupted()) { |
|
| 245 | - break; |
|
| 246 | - } |
|
| 247 | - } |
|
| 225 | + $user_count = 0; |
|
| 226 | + foreach ($users as $user) { |
|
| 227 | + if (is_object($user)) { |
|
| 228 | + $user = $user->getUID(); |
|
| 229 | + } |
|
| 230 | + $path = $inputPath ? $inputPath : '/' . $user; |
|
| 231 | + $user_count += 1; |
|
| 232 | + if ($this->userManager->userExists($user)) { |
|
| 233 | + # add an extra line when verbose is set to optical separate users |
|
| 234 | + if ($verbose) { |
|
| 235 | + $output->writeln(""); |
|
| 236 | + } |
|
| 237 | + $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
|
| 238 | + # full: printout data if $verbose was set |
|
| 239 | + $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow')); |
|
| 240 | + } else { |
|
| 241 | + $output->writeln("<error>Unknown user $user_count $user</error>"); |
|
| 242 | + } |
|
| 243 | + # check on each user if there was a user interrupt (ctrl-c) and exit foreach |
|
| 244 | + if ($this->hasBeenInterrupted()) { |
|
| 245 | + break; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - # stat: printout statistics if $quiet was not set |
|
| 250 | - if (!$quiet) { |
|
| 251 | - $this->presentStats($output); |
|
| 252 | - } |
|
| 253 | - } |
|
| 249 | + # stat: printout statistics if $quiet was not set |
|
| 250 | + if (!$quiet) { |
|
| 251 | + $this->presentStats($output); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Initialises some useful tools for the Command |
|
| 257 | - */ |
|
| 258 | - protected function initTools() { |
|
| 259 | - // Start the timer |
|
| 260 | - $this->execTime = -microtime(true); |
|
| 261 | - // Convert PHP errors to exceptions |
|
| 262 | - set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 263 | - } |
|
| 255 | + /** |
|
| 256 | + * Initialises some useful tools for the Command |
|
| 257 | + */ |
|
| 258 | + protected function initTools() { |
|
| 259 | + // Start the timer |
|
| 260 | + $this->execTime = -microtime(true); |
|
| 261 | + // Convert PHP errors to exceptions |
|
| 262 | + set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 267 | - * |
|
| 268 | - * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
| 269 | - * |
|
| 270 | - * @param int $severity the level of the error raised |
|
| 271 | - * @param string $message |
|
| 272 | - * @param string $file the filename that the error was raised in |
|
| 273 | - * @param int $line the line number the error was raised |
|
| 274 | - * |
|
| 275 | - * @throws \ErrorException |
|
| 276 | - */ |
|
| 277 | - public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
| 278 | - if (!(error_reporting() & $severity)) { |
|
| 279 | - // This error code is not included in error_reporting |
|
| 280 | - return; |
|
| 281 | - } |
|
| 282 | - throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 283 | - } |
|
| 265 | + /** |
|
| 266 | + * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 267 | + * |
|
| 268 | + * @see https://secure.php.net/manual/en/function.set-error-handler.php |
|
| 269 | + * |
|
| 270 | + * @param int $severity the level of the error raised |
|
| 271 | + * @param string $message |
|
| 272 | + * @param string $file the filename that the error was raised in |
|
| 273 | + * @param int $line the line number the error was raised |
|
| 274 | + * |
|
| 275 | + * @throws \ErrorException |
|
| 276 | + */ |
|
| 277 | + public function exceptionErrorHandler($severity, $message, $file, $line) { |
|
| 278 | + if (!(error_reporting() & $severity)) { |
|
| 279 | + // This error code is not included in error_reporting |
|
| 280 | + return; |
|
| 281 | + } |
|
| 282 | + throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * @param OutputInterface $output |
|
| 287 | - */ |
|
| 288 | - protected function presentStats(OutputInterface $output) { |
|
| 289 | - // Stop the timer |
|
| 290 | - $this->execTime += microtime(true); |
|
| 291 | - $output->writeln(""); |
|
| 285 | + /** |
|
| 286 | + * @param OutputInterface $output |
|
| 287 | + */ |
|
| 288 | + protected function presentStats(OutputInterface $output) { |
|
| 289 | + // Stop the timer |
|
| 290 | + $this->execTime += microtime(true); |
|
| 291 | + $output->writeln(""); |
|
| 292 | 292 | |
| 293 | - $headers = [ |
|
| 294 | - 'Folders', 'Files', 'Elapsed time' |
|
| 295 | - ]; |
|
| 293 | + $headers = [ |
|
| 294 | + 'Folders', 'Files', 'Elapsed time' |
|
| 295 | + ]; |
|
| 296 | 296 | |
| 297 | - $this->showSummary($headers, null, $output); |
|
| 298 | - } |
|
| 297 | + $this->showSummary($headers, null, $output); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Shows a summary of operations |
|
| 302 | - * |
|
| 303 | - * @param string[] $headers |
|
| 304 | - * @param string[] $rows |
|
| 305 | - * @param OutputInterface $output |
|
| 306 | - */ |
|
| 307 | - protected function showSummary($headers, $rows, OutputInterface $output) { |
|
| 308 | - $niceDate = $this->formatExecTime(); |
|
| 309 | - if (!$rows) { |
|
| 310 | - $rows = [ |
|
| 311 | - $this->foldersCounter, |
|
| 312 | - $this->filesCounter, |
|
| 313 | - $niceDate, |
|
| 314 | - ]; |
|
| 315 | - } |
|
| 316 | - $table = new Table($output); |
|
| 317 | - $table |
|
| 318 | - ->setHeaders($headers) |
|
| 319 | - ->setRows([$rows]); |
|
| 320 | - $table->render(); |
|
| 321 | - } |
|
| 300 | + /** |
|
| 301 | + * Shows a summary of operations |
|
| 302 | + * |
|
| 303 | + * @param string[] $headers |
|
| 304 | + * @param string[] $rows |
|
| 305 | + * @param OutputInterface $output |
|
| 306 | + */ |
|
| 307 | + protected function showSummary($headers, $rows, OutputInterface $output) { |
|
| 308 | + $niceDate = $this->formatExecTime(); |
|
| 309 | + if (!$rows) { |
|
| 310 | + $rows = [ |
|
| 311 | + $this->foldersCounter, |
|
| 312 | + $this->filesCounter, |
|
| 313 | + $niceDate, |
|
| 314 | + ]; |
|
| 315 | + } |
|
| 316 | + $table = new Table($output); |
|
| 317 | + $table |
|
| 318 | + ->setHeaders($headers) |
|
| 319 | + ->setRows([$rows]); |
|
| 320 | + $table->render(); |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Formats microtime into a human readable format |
|
| 326 | - * |
|
| 327 | - * @return string |
|
| 328 | - */ |
|
| 329 | - protected function formatExecTime() { |
|
| 330 | - list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 324 | + /** |
|
| 325 | + * Formats microtime into a human readable format |
|
| 326 | + * |
|
| 327 | + * @return string |
|
| 328 | + */ |
|
| 329 | + protected function formatExecTime() { |
|
| 330 | + list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 331 | 331 | |
| 332 | - # if you want to have microseconds add this: . '.' . $tens; |
|
| 333 | - return date('H:i:s', $secs); |
|
| 334 | - } |
|
| 332 | + # if you want to have microseconds add this: . '.' . $tens; |
|
| 333 | + return date('H:i:s', $secs); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * @return \OCP\IDBConnection |
|
| 338 | - */ |
|
| 339 | - protected function reconnectToDatabase(OutputInterface $output) { |
|
| 340 | - /** @var Connection | IDBConnection $connection */ |
|
| 341 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 342 | - try { |
|
| 343 | - $connection->close(); |
|
| 344 | - } catch (\Exception $ex) { |
|
| 345 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 346 | - } |
|
| 347 | - while (!$connection->isConnected()) { |
|
| 348 | - try { |
|
| 349 | - $connection->connect(); |
|
| 350 | - } catch (\Exception $ex) { |
|
| 351 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 352 | - sleep(60); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - return $connection; |
|
| 356 | - } |
|
| 336 | + /** |
|
| 337 | + * @return \OCP\IDBConnection |
|
| 338 | + */ |
|
| 339 | + protected function reconnectToDatabase(OutputInterface $output) { |
|
| 340 | + /** @var Connection | IDBConnection $connection */ |
|
| 341 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 342 | + try { |
|
| 343 | + $connection->close(); |
|
| 344 | + } catch (\Exception $ex) { |
|
| 345 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 346 | + } |
|
| 347 | + while (!$connection->isConnected()) { |
|
| 348 | + try { |
|
| 349 | + $connection->connect(); |
|
| 350 | + } catch (\Exception $ex) { |
|
| 351 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 352 | + sleep(60); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + return $connection; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $path = basename($fullPath); |
| 111 | 111 | |
| 112 | 112 | if ($normalizedPath !== $path) { |
| 113 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 113 | + $output->writeln("\t<error>Entry \"".$fullPath.'" will not be accessible due to incompatible encoding</error>'); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
@@ -120,42 +120,42 @@ discard block |
||
| 120 | 120 | # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
| 121 | 121 | # printout and count |
| 122 | 122 | if ($verbose) { |
| 123 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 123 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 124 | 124 | $output->writeln("\tFile <info>$path</info>"); |
| 125 | 125 | $this->filesCounter += 1; |
| 126 | 126 | if ($this->hasBeenInterrupted()) { |
| 127 | 127 | throw new InterruptedException(); |
| 128 | 128 | } |
| 129 | 129 | }); |
| 130 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 130 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 131 | 131 | $output->writeln("\tFolder <info>$path</info>"); |
| 132 | 132 | $this->foldersCounter += 1; |
| 133 | 133 | if ($this->hasBeenInterrupted()) { |
| 134 | 134 | throw new InterruptedException(); |
| 135 | 135 | } |
| 136 | 136 | }); |
| 137 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output) { |
|
| 138 | - $output->writeln("Error while scanning, storage not available (" . $e->getMessage() . ")"); |
|
| 137 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function(StorageNotAvailableException $e) use ($output) { |
|
| 138 | + $output->writeln("Error while scanning, storage not available (".$e->getMessage().")"); |
|
| 139 | 139 | }); |
| 140 | 140 | # count only |
| 141 | 141 | } else { |
| 142 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function () use ($output) { |
|
| 142 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function() use ($output) { |
|
| 143 | 143 | $this->filesCounter += 1; |
| 144 | 144 | if ($this->hasBeenInterrupted()) { |
| 145 | 145 | throw new InterruptedException(); |
| 146 | 146 | } |
| 147 | 147 | }); |
| 148 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function () use ($output) { |
|
| 148 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function() use ($output) { |
|
| 149 | 149 | $this->foldersCounter += 1; |
| 150 | 150 | if ($this->hasBeenInterrupted()) { |
| 151 | 151 | throw new InterruptedException(); |
| 152 | 152 | } |
| 153 | 153 | }); |
| 154 | 154 | } |
| 155 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output) { |
|
| 155 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function($path) use ($output) { |
|
| 156 | 156 | $this->checkScanWarning($path, $output); |
| 157 | 157 | }); |
| 158 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output) { |
|
| 158 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function($path) use ($output) { |
|
| 159 | 159 | $this->checkScanWarning($path, $output); |
| 160 | 160 | }); |
| 161 | 161 | |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | # exit the function if ctrl-c has been pressed |
| 173 | 173 | $output->writeln('Interrupted by user'); |
| 174 | 174 | } catch (NotFoundException $e) { |
| 175 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 175 | + $output->writeln('<error>Path not found: '.$e->getMessage().'</error>'); |
|
| 176 | 176 | } catch (\Exception $e) { |
| 177 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 178 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 177 | + $output->writeln('<error>Exception during scan: '.$e->getMessage().'</error>'); |
|
| 178 | + $output->writeln('<error>'.$e->getTraceAsString().'</error>'); |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 184 | 184 | $inputPath = $input->getOption('path'); |
| 185 | 185 | if ($inputPath) { |
| 186 | - $inputPath = '/' . trim($inputPath, '/'); |
|
| 186 | + $inputPath = '/'.trim($inputPath, '/'); |
|
| 187 | 187 | list (, $user,) = explode('/', $inputPath, 3); |
| 188 | 188 | $users = array($user); |
| 189 | 189 | } else if ($input->getOption('all')) { |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | if (is_object($user)) { |
| 228 | 228 | $user = $user->getUID(); |
| 229 | 229 | } |
| 230 | - $path = $inputPath ? $inputPath : '/' . $user; |
|
| 230 | + $path = $inputPath ? $inputPath : '/'.$user; |
|
| 231 | 231 | $user_count += 1; |
| 232 | 232 | if ($this->userManager->userExists($user)) { |
| 233 | 233 | # add an extra line when verbose is set to optical separate users |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | $output->writeln("Starting scan for user $user_count out of $users_total ($user)"); |
| 238 | 238 | # full: printout data if $verbose was set |
| 239 | - $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), ! $input->getOption('shallow')); |
|
| 239 | + $this->scanFiles($user, $path, $verbose, $output, $input->getOption('unscanned'), !$input->getOption('shallow')); |
|
| 240 | 240 | } else { |
| 241 | 241 | $output->writeln("<error>Unknown user $user_count $user</error>"); |
| 242 | 242 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @return string |
| 328 | 328 | */ |
| 329 | 329 | protected function formatExecTime() { |
| 330 | - list($secs, ) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 330 | + list($secs,) = explode('.', sprintf("%.1f", $this->execTime)); |
|
| 331 | 331 | |
| 332 | 332 | # if you want to have microseconds add this: . '.' . $tens; |
| 333 | 333 | return date('H:i:s', $secs); |