Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
validate that folder size sums to children
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Apr 17, 2023
commit c5dfa1cb797ea7fdb09f31963974edebb30742fe
26 changes: 21 additions & 5 deletions core/Command/Info/File.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In-place of the manual stdout formatting we could use the built-in Symfony methods https://symfony.com/doc/current/console/style.html#helper-methods ?

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(IRootFolder $rootFolder, IUserMountCache $userMountC
parent::__construct();
}

protected function configure() {
protected function configure(): void {
$this
->setName('info:file')
->setDescription('get information for a file')
Expand All @@ -61,17 +61,24 @@ public function execute(InputInterface $input, OutputInterface $output): int {
$output->writeln(" fileid: " . $node->getId());
$output->writeln(" mimetype: " . $node->getMimetype());
$output->writeln(" modified: " . (string)$this->l10n->l("datetime", $node->getMTime()));
$output->writeln(" size: " . Util::humanFileSize($node->getSize()));
$output->writeln(" " . ($node->isEncrypted() ? "encrypted" : "not encrypted"));
$output->writeln(" size: " . Util::humanFileSize($node->getSize()));
if ($node instanceof Folder) {
$children = $node->getDirectoryListing();
$childSize = array_sum(array_map(function (Node $node) {
return $node->getSize();
}, $children));
if ($childSize != $node->getSize()) {
$output->writeln(" <error>warning: folder has a size of " . Util::humanFileSize($node->getSize()) ." but it's children sum up to " . Util::humanFileSize($childSize) . "</error>.");
$output->writeln(" Run <info>occ files:scan --path " . $node->getPath() . "</info> to attempt to resolve this.");
}
if ($showChildren) {
$output->writeln(" children: " . count($children) . ":");
foreach ($children as $child) {
$output->writeln(" - " . $child->getName());
}
} else {
$output->writeln(" children: " . count($children) . " (--children to list)");
$output->writeln(" children: " . count($children) . " (use <info>--children</info> option to list)");
}
}
$this->outputStorageDetails($node->getMountPoint(), $node, $output);
Expand Down Expand Up @@ -156,6 +163,10 @@ private function formatPermissions(string $type, int $permissions): string {
return implode(", ", $perms);
}

/**
* @psalm-suppress UndefinedClass
* @psalm-suppress UndefinedInterfaceMethod
*/
private function formatMountType(IMountPoint $mountPoint): string {
$storage = $mountPoint->getStorage();
if ($storage && $storage->instanceOfStorage(IHomeStorage::class)) {
Expand All @@ -176,7 +187,7 @@ private function formatMountType(IMountPoint $mountPoint): string {
$description .= " owned by " . $share->getShareOwner();
}
return $description;
} elseif ($mountPoint instanceof GroupMountPoint) { /** @psalm-suppress UndefinedClass */
} elseif ($mountPoint instanceof GroupMountPoint) {
return "groupfolder " . $mountPoint->getFolderId();
} elseif ($mountPoint instanceof ExternalMountPoint) {
return "external storage " . $mountPoint->getStorageConfig()->getId();
Expand All @@ -203,6 +214,10 @@ private function formatShareType(IShare $share): ?string {
}
}

/**
* @psalm-suppress UndefinedClass
* @psalm-suppress UndefinedInterfaceMethod
*/
private function outputStorageDetails(IMountPoint $mountPoint, Node $node, OutputInterface $output): void {
$storage = $mountPoint->getStorage();
if (!$storage) {
Expand All @@ -215,6 +230,7 @@ private function outputStorageDetails(IMountPoint $mountPoint, Node $node, Outpu
/** @var ObjectStoreStorage $storage */
$objectStoreId = $storage->getObjectStore()->getStorageId();
$parts = explode(':', $objectStoreId);
/** @var string $bucket */
$bucket = array_pop($parts);
$output->writeln(" bucket: " . $bucket);
if ($node instanceof \OC\Files\Node\File) {
Expand Down Expand Up @@ -242,7 +258,7 @@ private function outputStorageDetails(IMountPoint $mountPoint, Node $node, Outpu
$storageConfig = $mountPoint->getStorageConfig();
$output->writeln(" external storage id: " . $storageConfig->getId());
$output->writeln(" external type: " . $storageConfig->getBackend()->getText());
} elseif ($mountPoint instanceof GroupMountPoint) { /** @psalm-suppress UndefinedClass */
} elseif ($mountPoint instanceof GroupMountPoint) {
$output->writeln(" groupfolder id: " . $mountPoint->getFolderId());
}
}
Expand Down