@@ -30,180 +30,180 @@ |
||
| 30 | 30 | use Symfony\Component\Console\Output\OutputInterface; |
| 31 | 31 | |
| 32 | 32 | class File extends Command { |
| 33 | - private IL10N $l10n; |
|
| 34 | - private View $rootView; |
|
| 33 | + private IL10N $l10n; |
|
| 34 | + private View $rootView; |
|
| 35 | 35 | |
| 36 | - public function __construct( |
|
| 37 | - IFactory $l10nFactory, |
|
| 38 | - private FileUtils $fileUtils, |
|
| 39 | - private \OC\Encryption\Util $encryptionUtil, |
|
| 40 | - private PrimaryObjectStoreConfig $objectStoreConfig, |
|
| 41 | - ) { |
|
| 42 | - $this->l10n = $l10nFactory->get('core'); |
|
| 43 | - parent::__construct(); |
|
| 44 | - $this->rootView = new View(); |
|
| 45 | - } |
|
| 36 | + public function __construct( |
|
| 37 | + IFactory $l10nFactory, |
|
| 38 | + private FileUtils $fileUtils, |
|
| 39 | + private \OC\Encryption\Util $encryptionUtil, |
|
| 40 | + private PrimaryObjectStoreConfig $objectStoreConfig, |
|
| 41 | + ) { |
|
| 42 | + $this->l10n = $l10nFactory->get('core'); |
|
| 43 | + parent::__construct(); |
|
| 44 | + $this->rootView = new View(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - protected function configure(): void { |
|
| 48 | - $this |
|
| 49 | - ->setName('info:file') |
|
| 50 | - ->setDescription('get information for a file') |
|
| 51 | - ->addArgument('file', InputArgument::REQUIRED, 'File id or path') |
|
| 52 | - ->addOption('children', 'c', InputOption::VALUE_NONE, 'List children of folders') |
|
| 53 | - ->addOption('storage-tree', null, InputOption::VALUE_NONE, 'Show storage and cache wrapping tree'); |
|
| 54 | - } |
|
| 47 | + protected function configure(): void { |
|
| 48 | + $this |
|
| 49 | + ->setName('info:file') |
|
| 50 | + ->setDescription('get information for a file') |
|
| 51 | + ->addArgument('file', InputArgument::REQUIRED, 'File id or path') |
|
| 52 | + ->addOption('children', 'c', InputOption::VALUE_NONE, 'List children of folders') |
|
| 53 | + ->addOption('storage-tree', null, InputOption::VALUE_NONE, 'Show storage and cache wrapping tree'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function execute(InputInterface $input, OutputInterface $output): int { |
|
| 57 | - $fileInput = $input->getArgument('file'); |
|
| 58 | - $showChildren = $input->getOption('children'); |
|
| 59 | - $node = $this->fileUtils->getNode($fileInput); |
|
| 60 | - if (!$node) { |
|
| 61 | - $output->writeln("<error>file $fileInput not found</error>"); |
|
| 62 | - return 1; |
|
| 63 | - } |
|
| 56 | + public function execute(InputInterface $input, OutputInterface $output): int { |
|
| 57 | + $fileInput = $input->getArgument('file'); |
|
| 58 | + $showChildren = $input->getOption('children'); |
|
| 59 | + $node = $this->fileUtils->getNode($fileInput); |
|
| 60 | + if (!$node) { |
|
| 61 | + $output->writeln("<error>file $fileInput not found</error>"); |
|
| 62 | + return 1; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $output->writeln($node->getName()); |
|
| 66 | - $output->writeln(' fileid: ' . $node->getId()); |
|
| 67 | - $output->writeln(' mimetype: ' . $node->getMimetype()); |
|
| 68 | - $output->writeln(' modified: ' . (string)$this->l10n->l('datetime', $node->getMTime())); |
|
| 65 | + $output->writeln($node->getName()); |
|
| 66 | + $output->writeln(' fileid: ' . $node->getId()); |
|
| 67 | + $output->writeln(' mimetype: ' . $node->getMimetype()); |
|
| 68 | + $output->writeln(' modified: ' . (string)$this->l10n->l('datetime', $node->getMTime())); |
|
| 69 | 69 | |
| 70 | - if ($node instanceof OCPFile && $node->isEncrypted()) { |
|
| 71 | - $output->writeln(' ' . 'server-side encrypted: yes'); |
|
| 72 | - $keyPath = $this->encryptionUtil->getFileKeyDir('', $node->getPath()); |
|
| 73 | - if ($this->rootView->file_exists($keyPath)) { |
|
| 74 | - $output->writeln(' encryption key at: ' . $keyPath); |
|
| 75 | - } else { |
|
| 76 | - $output->writeln(' <error>encryption key not found</error> should be located at: ' . $keyPath); |
|
| 77 | - } |
|
| 78 | - $storage = $node->getStorage(); |
|
| 79 | - if ($storage->instanceOfStorage(Encryption::class)) { |
|
| 80 | - /** @var Encryption $storage */ |
|
| 81 | - if (!$storage->hasValidHeader($node->getInternalPath())) { |
|
| 82 | - $output->writeln(' <error>file doesn\'t have a valid encryption header</error>'); |
|
| 83 | - } |
|
| 84 | - } else { |
|
| 85 | - $output->writeln(' <error>file is marked as encrypted, but encryption doesn\'t seem to be setup</error>'); |
|
| 86 | - } |
|
| 87 | - } |
|
| 70 | + if ($node instanceof OCPFile && $node->isEncrypted()) { |
|
| 71 | + $output->writeln(' ' . 'server-side encrypted: yes'); |
|
| 72 | + $keyPath = $this->encryptionUtil->getFileKeyDir('', $node->getPath()); |
|
| 73 | + if ($this->rootView->file_exists($keyPath)) { |
|
| 74 | + $output->writeln(' encryption key at: ' . $keyPath); |
|
| 75 | + } else { |
|
| 76 | + $output->writeln(' <error>encryption key not found</error> should be located at: ' . $keyPath); |
|
| 77 | + } |
|
| 78 | + $storage = $node->getStorage(); |
|
| 79 | + if ($storage->instanceOfStorage(Encryption::class)) { |
|
| 80 | + /** @var Encryption $storage */ |
|
| 81 | + if (!$storage->hasValidHeader($node->getInternalPath())) { |
|
| 82 | + $output->writeln(' <error>file doesn\'t have a valid encryption header</error>'); |
|
| 83 | + } |
|
| 84 | + } else { |
|
| 85 | + $output->writeln(' <error>file is marked as encrypted, but encryption doesn\'t seem to be setup</error>'); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - if ($node instanceof Folder && $node->isEncrypted() || $node instanceof OCPFile && $node->getParent()->isEncrypted()) { |
|
| 90 | - $output->writeln(' ' . 'end-to-end encrypted: yes'); |
|
| 91 | - } |
|
| 89 | + if ($node instanceof Folder && $node->isEncrypted() || $node instanceof OCPFile && $node->getParent()->isEncrypted()) { |
|
| 90 | + $output->writeln(' ' . 'end-to-end encrypted: yes'); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $output->writeln(' size: ' . Util::humanFileSize($node->getSize())); |
|
| 94 | - $output->writeln(' etag: ' . $node->getEtag()); |
|
| 95 | - $output->writeln(' permissions: ' . $this->fileUtils->formatPermissions($node->getType(), $node->getPermissions())); |
|
| 96 | - if ($node instanceof Folder) { |
|
| 97 | - $children = $node->getDirectoryListing(); |
|
| 98 | - $childSize = array_sum(array_map(function (Node $node) { |
|
| 99 | - return $node->getSize(); |
|
| 100 | - }, $children)); |
|
| 101 | - if ($childSize != $node->getSize()) { |
|
| 102 | - $output->writeln(' <error>warning: folder has a size of ' . Util::humanFileSize($node->getSize()) . " but it's children sum up to " . Util::humanFileSize($childSize) . '</error>.'); |
|
| 103 | - $output->writeln(' Run <info>occ files:scan --path ' . $node->getPath() . '</info> to attempt to resolve this.'); |
|
| 104 | - } |
|
| 105 | - if ($showChildren) { |
|
| 106 | - $output->writeln(' children: ' . count($children) . ':'); |
|
| 107 | - foreach ($children as $child) { |
|
| 108 | - $output->writeln(' - ' . $child->getName()); |
|
| 109 | - } |
|
| 110 | - } else { |
|
| 111 | - $output->writeln(' children: ' . count($children) . ' (use <info>--children</info> option to list)'); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - $this->outputStorageDetails($node->getMountPoint(), $node, $input, $output); |
|
| 93 | + $output->writeln(' size: ' . Util::humanFileSize($node->getSize())); |
|
| 94 | + $output->writeln(' etag: ' . $node->getEtag()); |
|
| 95 | + $output->writeln(' permissions: ' . $this->fileUtils->formatPermissions($node->getType(), $node->getPermissions())); |
|
| 96 | + if ($node instanceof Folder) { |
|
| 97 | + $children = $node->getDirectoryListing(); |
|
| 98 | + $childSize = array_sum(array_map(function (Node $node) { |
|
| 99 | + return $node->getSize(); |
|
| 100 | + }, $children)); |
|
| 101 | + if ($childSize != $node->getSize()) { |
|
| 102 | + $output->writeln(' <error>warning: folder has a size of ' . Util::humanFileSize($node->getSize()) . " but it's children sum up to " . Util::humanFileSize($childSize) . '</error>.'); |
|
| 103 | + $output->writeln(' Run <info>occ files:scan --path ' . $node->getPath() . '</info> to attempt to resolve this.'); |
|
| 104 | + } |
|
| 105 | + if ($showChildren) { |
|
| 106 | + $output->writeln(' children: ' . count($children) . ':'); |
|
| 107 | + foreach ($children as $child) { |
|
| 108 | + $output->writeln(' - ' . $child->getName()); |
|
| 109 | + } |
|
| 110 | + } else { |
|
| 111 | + $output->writeln(' children: ' . count($children) . ' (use <info>--children</info> option to list)'); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + $this->outputStorageDetails($node->getMountPoint(), $node, $input, $output); |
|
| 115 | 115 | |
| 116 | - $filesPerUser = $this->fileUtils->getFilesByUser($node); |
|
| 117 | - $output->writeln(''); |
|
| 118 | - $output->writeln('The following users have access to the file'); |
|
| 119 | - $output->writeln(''); |
|
| 120 | - foreach ($filesPerUser as $user => $files) { |
|
| 121 | - $output->writeln("$user:"); |
|
| 122 | - foreach ($files as $userFile) { |
|
| 123 | - $output->writeln(' ' . $userFile->getPath() . ': ' . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions())); |
|
| 124 | - $mount = $userFile->getMountPoint(); |
|
| 125 | - $output->writeln(' ' . $this->fileUtils->formatMountType($mount)); |
|
| 126 | - } |
|
| 127 | - } |
|
| 116 | + $filesPerUser = $this->fileUtils->getFilesByUser($node); |
|
| 117 | + $output->writeln(''); |
|
| 118 | + $output->writeln('The following users have access to the file'); |
|
| 119 | + $output->writeln(''); |
|
| 120 | + foreach ($filesPerUser as $user => $files) { |
|
| 121 | + $output->writeln("$user:"); |
|
| 122 | + foreach ($files as $userFile) { |
|
| 123 | + $output->writeln(' ' . $userFile->getPath() . ': ' . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions())); |
|
| 124 | + $mount = $userFile->getMountPoint(); |
|
| 125 | + $output->writeln(' ' . $this->fileUtils->formatMountType($mount)); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return 0; |
|
| 130 | - } |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @psalm-suppress UndefinedClass |
|
| 134 | - * @psalm-suppress UndefinedInterfaceMethod |
|
| 135 | - */ |
|
| 136 | - private function outputStorageDetails(IMountPoint $mountPoint, Node $node, InputInterface $input, OutputInterface $output): void { |
|
| 137 | - $storage = $mountPoint->getStorage(); |
|
| 138 | - if (!$storage) { |
|
| 139 | - return; |
|
| 140 | - } |
|
| 141 | - if (!$storage->instanceOfStorage(IHomeStorage::class)) { |
|
| 142 | - $output->writeln(' mounted at: ' . $mountPoint->getMountPoint()); |
|
| 143 | - } |
|
| 144 | - if ($storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 145 | - /** @var ObjectStoreStorage $storage */ |
|
| 146 | - $objectStoreId = $storage->getObjectStore()->getStorageId(); |
|
| 147 | - $parts = explode(':', $objectStoreId); |
|
| 148 | - /** @var string $bucket */ |
|
| 149 | - $bucket = array_pop($parts); |
|
| 150 | - if ($this->objectStoreConfig->hasMultipleObjectStorages()) { |
|
| 151 | - $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 152 | - foreach ($configs as $instance => $config) { |
|
| 153 | - if (is_array($config)) { |
|
| 154 | - if ($config['arguments']['multibucket']) { |
|
| 155 | - if (str_starts_with($bucket, $config['arguments']['bucket'])) { |
|
| 156 | - $postfix = substr($bucket, strlen($config['arguments']['bucket'])); |
|
| 157 | - if (is_numeric($postfix)) { |
|
| 158 | - $output->writeln(' object store instance: ' . $instance); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - if ($config['arguments']['bucket'] === $bucket) { |
|
| 163 | - $output->writeln(' object store instance: ' . $instance); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - $output->writeln(' bucket: ' . $bucket); |
|
| 170 | - if ($node instanceof \OC\Files\Node\File) { |
|
| 171 | - $output->writeln(' object id: ' . $storage->getURN($node->getId())); |
|
| 172 | - try { |
|
| 173 | - $fh = $node->fopen('r'); |
|
| 174 | - if (!$fh) { |
|
| 175 | - throw new NotFoundException(); |
|
| 176 | - } |
|
| 177 | - $stat = fstat($fh); |
|
| 178 | - fclose($fh); |
|
| 179 | - if ($stat['size'] !== $node->getSize()) { |
|
| 180 | - $output->writeln(' <error>warning: object had a size of ' . $stat['size'] . ' but cache entry has a size of ' . $node->getSize() . '</error>. This should have been automatically repaired'); |
|
| 181 | - } |
|
| 182 | - } catch (\Exception $e) { |
|
| 183 | - $output->writeln(' <error>warning: object not found in bucket</error>'); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - if (!$storage->file_exists($node->getInternalPath())) { |
|
| 188 | - $output->writeln(' <error>warning: file not found in storage</error>'); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - if ($mountPoint instanceof ExternalMountPoint) { |
|
| 192 | - $storageConfig = $mountPoint->getStorageConfig(); |
|
| 193 | - $output->writeln(' external storage id: ' . $storageConfig->getId()); |
|
| 194 | - $output->writeln(' external type: ' . $storageConfig->getBackend()->getText()); |
|
| 195 | - } elseif ($mountPoint instanceof GroupMountPoint) { |
|
| 196 | - $output->writeln(' groupfolder id: ' . $mountPoint->getFolderId()); |
|
| 197 | - } |
|
| 198 | - if ($input->getOption('storage-tree')) { |
|
| 199 | - $storageTmp = $storage; |
|
| 200 | - $storageClass = get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')'; |
|
| 201 | - while ($storageTmp instanceof Wrapper) { |
|
| 202 | - $storageTmp = $storageTmp->getWrapperStorage(); |
|
| 203 | - $storageClass .= "\n\t" . '> ' . get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')'; |
|
| 204 | - } |
|
| 205 | - $output->writeln(' storage wrapping: ' . $storageClass); |
|
| 206 | - } |
|
| 132 | + /** |
|
| 133 | + * @psalm-suppress UndefinedClass |
|
| 134 | + * @psalm-suppress UndefinedInterfaceMethod |
|
| 135 | + */ |
|
| 136 | + private function outputStorageDetails(IMountPoint $mountPoint, Node $node, InputInterface $input, OutputInterface $output): void { |
|
| 137 | + $storage = $mountPoint->getStorage(); |
|
| 138 | + if (!$storage) { |
|
| 139 | + return; |
|
| 140 | + } |
|
| 141 | + if (!$storage->instanceOfStorage(IHomeStorage::class)) { |
|
| 142 | + $output->writeln(' mounted at: ' . $mountPoint->getMountPoint()); |
|
| 143 | + } |
|
| 144 | + if ($storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 145 | + /** @var ObjectStoreStorage $storage */ |
|
| 146 | + $objectStoreId = $storage->getObjectStore()->getStorageId(); |
|
| 147 | + $parts = explode(':', $objectStoreId); |
|
| 148 | + /** @var string $bucket */ |
|
| 149 | + $bucket = array_pop($parts); |
|
| 150 | + if ($this->objectStoreConfig->hasMultipleObjectStorages()) { |
|
| 151 | + $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 152 | + foreach ($configs as $instance => $config) { |
|
| 153 | + if (is_array($config)) { |
|
| 154 | + if ($config['arguments']['multibucket']) { |
|
| 155 | + if (str_starts_with($bucket, $config['arguments']['bucket'])) { |
|
| 156 | + $postfix = substr($bucket, strlen($config['arguments']['bucket'])); |
|
| 157 | + if (is_numeric($postfix)) { |
|
| 158 | + $output->writeln(' object store instance: ' . $instance); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + if ($config['arguments']['bucket'] === $bucket) { |
|
| 163 | + $output->writeln(' object store instance: ' . $instance); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + $output->writeln(' bucket: ' . $bucket); |
|
| 170 | + if ($node instanceof \OC\Files\Node\File) { |
|
| 171 | + $output->writeln(' object id: ' . $storage->getURN($node->getId())); |
|
| 172 | + try { |
|
| 173 | + $fh = $node->fopen('r'); |
|
| 174 | + if (!$fh) { |
|
| 175 | + throw new NotFoundException(); |
|
| 176 | + } |
|
| 177 | + $stat = fstat($fh); |
|
| 178 | + fclose($fh); |
|
| 179 | + if ($stat['size'] !== $node->getSize()) { |
|
| 180 | + $output->writeln(' <error>warning: object had a size of ' . $stat['size'] . ' but cache entry has a size of ' . $node->getSize() . '</error>. This should have been automatically repaired'); |
|
| 181 | + } |
|
| 182 | + } catch (\Exception $e) { |
|
| 183 | + $output->writeln(' <error>warning: object not found in bucket</error>'); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + if (!$storage->file_exists($node->getInternalPath())) { |
|
| 188 | + $output->writeln(' <error>warning: file not found in storage</error>'); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + if ($mountPoint instanceof ExternalMountPoint) { |
|
| 192 | + $storageConfig = $mountPoint->getStorageConfig(); |
|
| 193 | + $output->writeln(' external storage id: ' . $storageConfig->getId()); |
|
| 194 | + $output->writeln(' external type: ' . $storageConfig->getBackend()->getText()); |
|
| 195 | + } elseif ($mountPoint instanceof GroupMountPoint) { |
|
| 196 | + $output->writeln(' groupfolder id: ' . $mountPoint->getFolderId()); |
|
| 197 | + } |
|
| 198 | + if ($input->getOption('storage-tree')) { |
|
| 199 | + $storageTmp = $storage; |
|
| 200 | + $storageClass = get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')'; |
|
| 201 | + while ($storageTmp instanceof Wrapper) { |
|
| 202 | + $storageTmp = $storageTmp->getWrapperStorage(); |
|
| 203 | + $storageClass .= "\n\t" . '> ' . get_class($storageTmp) . ' (cache:' . get_class($storageTmp->getCache()) . ')'; |
|
| 204 | + } |
|
| 205 | + $output->writeln(' storage wrapping: ' . $storageClass); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - } |
|
| 208 | + } |
|
| 209 | 209 | } |