Skip to content

Commit 1b6381a

Browse files
committed
validate that folder size sums to children
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent bbb2474 commit 1b6381a

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

core/Command/Info/File.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,24 @@ public function execute(InputInterface $input, OutputInterface $output): int {
6161
$output->writeln(" fileid: " . $node->getId());
6262
$output->writeln(" mimetype: " . $node->getMimetype());
6363
$output->writeln(" modified: " . (string)$this->l10n->l("datetime", $node->getMTime()));
64-
$output->writeln(" size: " . Util::humanFileSize($node->getSize()));
6564
$output->writeln(" " . ($node->isEncrypted() ? "encrypted" : "not encrypted"));
65+
$output->writeln(" size: " . Util::humanFileSize($node->getSize()));
6666
if ($node instanceof Folder) {
6767
$children = $node->getDirectoryListing();
68+
$childSize = array_sum(array_map(function (Node $node) {
69+
return $node->getSize();
70+
}, $children));
71+
if ($childSize != $node->getSize()) {
72+
$output->writeln(" <error>warning: folder has a size of " . Util::humanFileSize($node->getSize()) ." but it's children sum up to " . Util::humanFileSize($childSize) . "</error>.");
73+
$output->writeln(" Run <info>occ files:scan --path " . $node->getPath() . "</info> to attempt to resolve this.");
74+
}
6875
if ($showChildren) {
6976
$output->writeln(" children: " . count($children) . ":");
7077
foreach ($children as $child) {
7178
$output->writeln(" - " . $child->getName());
7279
}
7380
} else {
74-
$output->writeln(" children: " . count($children) . " (--children to list)");
81+
$output->writeln(" children: " . count($children) . " (use <info>--children</info> option to list)");
7582
}
7683
}
7784
$this->outputStorageDetails($node->getMountPoint(), $node, $output);
@@ -176,7 +183,10 @@ private function formatMountType(IMountPoint $mountPoint): string {
176183
$description .= " owned by " . $share->getShareOwner();
177184
}
178185
return $description;
179-
} elseif ($mountPoint instanceof GroupMountPoint) { /** @psalm-suppress UndefinedClass */
186+
/**
187+
* @psalm-suppress UndefinedClass
188+
*/
189+
} elseif ($mountPoint instanceof GroupMountPoint) {
180190
return "groupfolder " . $mountPoint->getFolderId();
181191
} elseif ($mountPoint instanceof ExternalMountPoint) {
182192
return "external storage " . $mountPoint->getStorageConfig()->getId();
@@ -242,7 +252,11 @@ private function outputStorageDetails(IMountPoint $mountPoint, Node $node, Outpu
242252
$storageConfig = $mountPoint->getStorageConfig();
243253
$output->writeln(" external storage id: " . $storageConfig->getId());
244254
$output->writeln(" external type: " . $storageConfig->getBackend()->getText());
245-
} elseif ($mountPoint instanceof GroupMountPoint) { /** @psalm-suppress UndefinedClass */
255+
256+
/**
257+
* @psalm-suppress UndefinedClass
258+
*/
259+
} elseif ($mountPoint instanceof GroupMountPoint) {
246260
$output->writeln(" groupfolder id: " . $mountPoint->getFolderId());
247261
}
248262
}

0 commit comments

Comments
 (0)