@@ -22,121 +22,121 @@ |
||
| 22 | 22 | use Symfony\Component\Console\Output\OutputInterface; |
| 23 | 23 | |
| 24 | 24 | class File extends Command { |
| 25 | - private IL10N $l10n; |
|
| 26 | - private FileUtils $fileUtils; |
|
| 25 | + private IL10N $l10n; |
|
| 26 | + private FileUtils $fileUtils; |
|
| 27 | 27 | |
| 28 | - public function __construct(IFactory $l10nFactory, FileUtils $fileUtils) { |
|
| 29 | - $this->l10n = $l10nFactory->get("core"); |
|
| 30 | - $this->fileUtils = $fileUtils; |
|
| 31 | - parent::__construct(); |
|
| 32 | - } |
|
| 28 | + public function __construct(IFactory $l10nFactory, FileUtils $fileUtils) { |
|
| 29 | + $this->l10n = $l10nFactory->get("core"); |
|
| 30 | + $this->fileUtils = $fileUtils; |
|
| 31 | + parent::__construct(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - protected function configure(): void { |
|
| 35 | - $this |
|
| 36 | - ->setName('info:file') |
|
| 37 | - ->setDescription('get information for a file') |
|
| 38 | - ->addArgument('file', InputArgument::REQUIRED, "File id or path") |
|
| 39 | - ->addOption('children', 'c', InputOption::VALUE_NONE, "List children of folders"); |
|
| 40 | - } |
|
| 34 | + protected function configure(): void { |
|
| 35 | + $this |
|
| 36 | + ->setName('info:file') |
|
| 37 | + ->setDescription('get information for a file') |
|
| 38 | + ->addArgument('file', InputArgument::REQUIRED, "File id or path") |
|
| 39 | + ->addOption('children', 'c', InputOption::VALUE_NONE, "List children of folders"); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function execute(InputInterface $input, OutputInterface $output): int { |
|
| 43 | - $fileInput = $input->getArgument('file'); |
|
| 44 | - $showChildren = $input->getOption('children'); |
|
| 45 | - $node = $this->fileUtils->getNode($fileInput); |
|
| 46 | - if (!$node) { |
|
| 47 | - $output->writeln("<error>file $fileInput not found</error>"); |
|
| 48 | - return 1; |
|
| 49 | - } |
|
| 42 | + public function execute(InputInterface $input, OutputInterface $output): int { |
|
| 43 | + $fileInput = $input->getArgument('file'); |
|
| 44 | + $showChildren = $input->getOption('children'); |
|
| 45 | + $node = $this->fileUtils->getNode($fileInput); |
|
| 46 | + if (!$node) { |
|
| 47 | + $output->writeln("<error>file $fileInput not found</error>"); |
|
| 48 | + return 1; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $output->writeln($node->getName()); |
|
| 52 | - $output->writeln(" fileid: " . $node->getId()); |
|
| 53 | - $output->writeln(" mimetype: " . $node->getMimetype()); |
|
| 54 | - $output->writeln(" modified: " . (string)$this->l10n->l("datetime", $node->getMTime())); |
|
| 55 | - $output->writeln(" " . ($node->isEncrypted() ? "encrypted" : "not encrypted")); |
|
| 56 | - $output->writeln(" size: " . Util::humanFileSize($node->getSize())); |
|
| 57 | - $output->writeln(" etag: " . $node->getEtag()); |
|
| 58 | - if ($node instanceof Folder) { |
|
| 59 | - $children = $node->getDirectoryListing(); |
|
| 60 | - $childSize = array_sum(array_map(function (Node $node) { |
|
| 61 | - return $node->getSize(); |
|
| 62 | - }, $children)); |
|
| 63 | - if ($childSize != $node->getSize()) { |
|
| 64 | - $output->writeln(" <error>warning: folder has a size of " . Util::humanFileSize($node->getSize()) ." but it's children sum up to " . Util::humanFileSize($childSize) . "</error>."); |
|
| 65 | - $output->writeln(" Run <info>occ files:scan --path " . $node->getPath() . "</info> to attempt to resolve this."); |
|
| 66 | - } |
|
| 67 | - if ($showChildren) { |
|
| 68 | - $output->writeln(" children: " . count($children) . ":"); |
|
| 69 | - foreach ($children as $child) { |
|
| 70 | - $output->writeln(" - " . $child->getName()); |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - $output->writeln(" children: " . count($children) . " (use <info>--children</info> option to list)"); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $this->outputStorageDetails($node->getMountPoint(), $node, $output); |
|
| 51 | + $output->writeln($node->getName()); |
|
| 52 | + $output->writeln(" fileid: " . $node->getId()); |
|
| 53 | + $output->writeln(" mimetype: " . $node->getMimetype()); |
|
| 54 | + $output->writeln(" modified: " . (string)$this->l10n->l("datetime", $node->getMTime())); |
|
| 55 | + $output->writeln(" " . ($node->isEncrypted() ? "encrypted" : "not encrypted")); |
|
| 56 | + $output->writeln(" size: " . Util::humanFileSize($node->getSize())); |
|
| 57 | + $output->writeln(" etag: " . $node->getEtag()); |
|
| 58 | + if ($node instanceof Folder) { |
|
| 59 | + $children = $node->getDirectoryListing(); |
|
| 60 | + $childSize = array_sum(array_map(function (Node $node) { |
|
| 61 | + return $node->getSize(); |
|
| 62 | + }, $children)); |
|
| 63 | + if ($childSize != $node->getSize()) { |
|
| 64 | + $output->writeln(" <error>warning: folder has a size of " . Util::humanFileSize($node->getSize()) ." but it's children sum up to " . Util::humanFileSize($childSize) . "</error>."); |
|
| 65 | + $output->writeln(" Run <info>occ files:scan --path " . $node->getPath() . "</info> to attempt to resolve this."); |
|
| 66 | + } |
|
| 67 | + if ($showChildren) { |
|
| 68 | + $output->writeln(" children: " . count($children) . ":"); |
|
| 69 | + foreach ($children as $child) { |
|
| 70 | + $output->writeln(" - " . $child->getName()); |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + $output->writeln(" children: " . count($children) . " (use <info>--children</info> option to list)"); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $this->outputStorageDetails($node->getMountPoint(), $node, $output); |
|
| 77 | 77 | |
| 78 | - $filesPerUser = $this->fileUtils->getFilesByUser($node); |
|
| 79 | - $output->writeln(""); |
|
| 80 | - $output->writeln("The following users have access to the file"); |
|
| 81 | - $output->writeln(""); |
|
| 82 | - foreach ($filesPerUser as $user => $files) { |
|
| 83 | - $output->writeln("$user:"); |
|
| 84 | - foreach ($files as $userFile) { |
|
| 85 | - $output->writeln(" " . $userFile->getPath() . ": " . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions())); |
|
| 86 | - $mount = $userFile->getMountPoint(); |
|
| 87 | - $output->writeln(" " . $this->fileUtils->formatMountType($mount)); |
|
| 88 | - } |
|
| 89 | - } |
|
| 78 | + $filesPerUser = $this->fileUtils->getFilesByUser($node); |
|
| 79 | + $output->writeln(""); |
|
| 80 | + $output->writeln("The following users have access to the file"); |
|
| 81 | + $output->writeln(""); |
|
| 82 | + foreach ($filesPerUser as $user => $files) { |
|
| 83 | + $output->writeln("$user:"); |
|
| 84 | + foreach ($files as $userFile) { |
|
| 85 | + $output->writeln(" " . $userFile->getPath() . ": " . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions())); |
|
| 86 | + $mount = $userFile->getMountPoint(); |
|
| 87 | + $output->writeln(" " . $this->fileUtils->formatMountType($mount)); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return 0; |
|
| 92 | - } |
|
| 91 | + return 0; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @psalm-suppress UndefinedClass |
|
| 96 | - * @psalm-suppress UndefinedInterfaceMethod |
|
| 97 | - */ |
|
| 98 | - private function outputStorageDetails(IMountPoint $mountPoint, Node $node, OutputInterface $output): void { |
|
| 99 | - $storage = $mountPoint->getStorage(); |
|
| 100 | - if (!$storage) { |
|
| 101 | - return; |
|
| 102 | - } |
|
| 103 | - if (!$storage->instanceOfStorage(IHomeStorage::class)) { |
|
| 104 | - $output->writeln(" mounted at: " . $mountPoint->getMountPoint()); |
|
| 105 | - } |
|
| 106 | - if ($storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 107 | - /** @var ObjectStoreStorage $storage */ |
|
| 108 | - $objectStoreId = $storage->getObjectStore()->getStorageId(); |
|
| 109 | - $parts = explode(':', $objectStoreId); |
|
| 110 | - /** @var string $bucket */ |
|
| 111 | - $bucket = array_pop($parts); |
|
| 112 | - $output->writeln(" bucket: " . $bucket); |
|
| 113 | - if ($node instanceof \OC\Files\Node\File) { |
|
| 114 | - $output->writeln(" object id: " . $storage->getURN($node->getId())); |
|
| 115 | - try { |
|
| 116 | - $fh = $node->fopen('r'); |
|
| 117 | - if (!$fh) { |
|
| 118 | - throw new NotFoundException(); |
|
| 119 | - } |
|
| 120 | - $stat = fstat($fh); |
|
| 121 | - fclose($fh); |
|
| 122 | - if ($stat['size'] !== $node->getSize()) { |
|
| 123 | - $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"); |
|
| 124 | - } |
|
| 125 | - } catch (\Exception $e) { |
|
| 126 | - $output->writeln(" <error>warning: object not found in bucket</error>"); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } else { |
|
| 130 | - if (!$storage->file_exists($node->getInternalPath())) { |
|
| 131 | - $output->writeln(" <error>warning: file not found in storage</error>"); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - if ($mountPoint instanceof ExternalMountPoint) { |
|
| 135 | - $storageConfig = $mountPoint->getStorageConfig(); |
|
| 136 | - $output->writeln(" external storage id: " . $storageConfig->getId()); |
|
| 137 | - $output->writeln(" external type: " . $storageConfig->getBackend()->getText()); |
|
| 138 | - } elseif ($mountPoint instanceof GroupMountPoint) { |
|
| 139 | - $output->writeln(" groupfolder id: " . $mountPoint->getFolderId()); |
|
| 140 | - } |
|
| 141 | - } |
|
| 94 | + /** |
|
| 95 | + * @psalm-suppress UndefinedClass |
|
| 96 | + * @psalm-suppress UndefinedInterfaceMethod |
|
| 97 | + */ |
|
| 98 | + private function outputStorageDetails(IMountPoint $mountPoint, Node $node, OutputInterface $output): void { |
|
| 99 | + $storage = $mountPoint->getStorage(); |
|
| 100 | + if (!$storage) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | + if (!$storage->instanceOfStorage(IHomeStorage::class)) { |
|
| 104 | + $output->writeln(" mounted at: " . $mountPoint->getMountPoint()); |
|
| 105 | + } |
|
| 106 | + if ($storage->instanceOfStorage(ObjectStoreStorage::class)) { |
|
| 107 | + /** @var ObjectStoreStorage $storage */ |
|
| 108 | + $objectStoreId = $storage->getObjectStore()->getStorageId(); |
|
| 109 | + $parts = explode(':', $objectStoreId); |
|
| 110 | + /** @var string $bucket */ |
|
| 111 | + $bucket = array_pop($parts); |
|
| 112 | + $output->writeln(" bucket: " . $bucket); |
|
| 113 | + if ($node instanceof \OC\Files\Node\File) { |
|
| 114 | + $output->writeln(" object id: " . $storage->getURN($node->getId())); |
|
| 115 | + try { |
|
| 116 | + $fh = $node->fopen('r'); |
|
| 117 | + if (!$fh) { |
|
| 118 | + throw new NotFoundException(); |
|
| 119 | + } |
|
| 120 | + $stat = fstat($fh); |
|
| 121 | + fclose($fh); |
|
| 122 | + if ($stat['size'] !== $node->getSize()) { |
|
| 123 | + $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"); |
|
| 124 | + } |
|
| 125 | + } catch (\Exception $e) { |
|
| 126 | + $output->writeln(" <error>warning: object not found in bucket</error>"); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } else { |
|
| 130 | + if (!$storage->file_exists($node->getInternalPath())) { |
|
| 131 | + $output->writeln(" <error>warning: file not found in storage</error>"); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + if ($mountPoint instanceof ExternalMountPoint) { |
|
| 135 | + $storageConfig = $mountPoint->getStorageConfig(); |
|
| 136 | + $output->writeln(" external storage id: " . $storageConfig->getId()); |
|
| 137 | + $output->writeln(" external type: " . $storageConfig->getBackend()->getText()); |
|
| 138 | + } elseif ($mountPoint instanceof GroupMountPoint) { |
|
| 139 | + $output->writeln(" groupfolder id: " . $mountPoint->getFolderId()); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -49,28 +49,28 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $output->writeln($node->getName()); |
| 52 | - $output->writeln(" fileid: " . $node->getId()); |
|
| 53 | - $output->writeln(" mimetype: " . $node->getMimetype()); |
|
| 54 | - $output->writeln(" modified: " . (string)$this->l10n->l("datetime", $node->getMTime())); |
|
| 55 | - $output->writeln(" " . ($node->isEncrypted() ? "encrypted" : "not encrypted")); |
|
| 56 | - $output->writeln(" size: " . Util::humanFileSize($node->getSize())); |
|
| 57 | - $output->writeln(" etag: " . $node->getEtag()); |
|
| 52 | + $output->writeln(" fileid: ".$node->getId()); |
|
| 53 | + $output->writeln(" mimetype: ".$node->getMimetype()); |
|
| 54 | + $output->writeln(" modified: ".(string) $this->l10n->l("datetime", $node->getMTime())); |
|
| 55 | + $output->writeln(" ".($node->isEncrypted() ? "encrypted" : "not encrypted")); |
|
| 56 | + $output->writeln(" size: ".Util::humanFileSize($node->getSize())); |
|
| 57 | + $output->writeln(" etag: ".$node->getEtag()); |
|
| 58 | 58 | if ($node instanceof Folder) { |
| 59 | 59 | $children = $node->getDirectoryListing(); |
| 60 | - $childSize = array_sum(array_map(function (Node $node) { |
|
| 60 | + $childSize = array_sum(array_map(function(Node $node) { |
|
| 61 | 61 | return $node->getSize(); |
| 62 | 62 | }, $children)); |
| 63 | 63 | if ($childSize != $node->getSize()) { |
| 64 | - $output->writeln(" <error>warning: folder has a size of " . Util::humanFileSize($node->getSize()) ." but it's children sum up to " . Util::humanFileSize($childSize) . "</error>."); |
|
| 65 | - $output->writeln(" Run <info>occ files:scan --path " . $node->getPath() . "</info> to attempt to resolve this."); |
|
| 64 | + $output->writeln(" <error>warning: folder has a size of ".Util::humanFileSize($node->getSize())." but it's children sum up to ".Util::humanFileSize($childSize)."</error>."); |
|
| 65 | + $output->writeln(" Run <info>occ files:scan --path ".$node->getPath()."</info> to attempt to resolve this."); |
|
| 66 | 66 | } |
| 67 | 67 | if ($showChildren) { |
| 68 | - $output->writeln(" children: " . count($children) . ":"); |
|
| 68 | + $output->writeln(" children: ".count($children).":"); |
|
| 69 | 69 | foreach ($children as $child) { |
| 70 | - $output->writeln(" - " . $child->getName()); |
|
| 70 | + $output->writeln(" - ".$child->getName()); |
|
| 71 | 71 | } |
| 72 | 72 | } else { |
| 73 | - $output->writeln(" children: " . count($children) . " (use <info>--children</info> option to list)"); |
|
| 73 | + $output->writeln(" children: ".count($children)." (use <info>--children</info> option to list)"); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | $this->outputStorageDetails($node->getMountPoint(), $node, $output); |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | foreach ($filesPerUser as $user => $files) { |
| 83 | 83 | $output->writeln("$user:"); |
| 84 | 84 | foreach ($files as $userFile) { |
| 85 | - $output->writeln(" " . $userFile->getPath() . ": " . $this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions())); |
|
| 85 | + $output->writeln(" ".$userFile->getPath().": ".$this->fileUtils->formatPermissions($userFile->getType(), $userFile->getPermissions())); |
|
| 86 | 86 | $mount = $userFile->getMountPoint(); |
| 87 | - $output->writeln(" " . $this->fileUtils->formatMountType($mount)); |
|
| 87 | + $output->writeln(" ".$this->fileUtils->formatMountType($mount)); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | 103 | if (!$storage->instanceOfStorage(IHomeStorage::class)) { |
| 104 | - $output->writeln(" mounted at: " . $mountPoint->getMountPoint()); |
|
| 104 | + $output->writeln(" mounted at: ".$mountPoint->getMountPoint()); |
|
| 105 | 105 | } |
| 106 | 106 | if ($storage->instanceOfStorage(ObjectStoreStorage::class)) { |
| 107 | 107 | /** @var ObjectStoreStorage $storage */ |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | $parts = explode(':', $objectStoreId); |
| 110 | 110 | /** @var string $bucket */ |
| 111 | 111 | $bucket = array_pop($parts); |
| 112 | - $output->writeln(" bucket: " . $bucket); |
|
| 112 | + $output->writeln(" bucket: ".$bucket); |
|
| 113 | 113 | if ($node instanceof \OC\Files\Node\File) { |
| 114 | - $output->writeln(" object id: " . $storage->getURN($node->getId())); |
|
| 114 | + $output->writeln(" object id: ".$storage->getURN($node->getId())); |
|
| 115 | 115 | try { |
| 116 | 116 | $fh = $node->fopen('r'); |
| 117 | 117 | if (!$fh) { |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $stat = fstat($fh); |
| 121 | 121 | fclose($fh); |
| 122 | 122 | if ($stat['size'] !== $node->getSize()) { |
| 123 | - $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"); |
|
| 123 | + $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"); |
|
| 124 | 124 | } |
| 125 | 125 | } catch (\Exception $e) { |
| 126 | 126 | $output->writeln(" <error>warning: object not found in bucket</error>"); |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | if ($mountPoint instanceof ExternalMountPoint) { |
| 135 | 135 | $storageConfig = $mountPoint->getStorageConfig(); |
| 136 | - $output->writeln(" external storage id: " . $storageConfig->getId()); |
|
| 137 | - $output->writeln(" external type: " . $storageConfig->getBackend()->getText()); |
|
| 136 | + $output->writeln(" external storage id: ".$storageConfig->getId()); |
|
| 137 | + $output->writeln(" external type: ".$storageConfig->getBackend()->getText()); |
|
| 138 | 138 | } elseif ($mountPoint instanceof GroupMountPoint) { |
| 139 | - $output->writeln(" groupfolder id: " . $mountPoint->getFolderId()); |
|
| 139 | + $output->writeln(" groupfolder id: ".$mountPoint->getFolderId()); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | } |