Skip to content

Commit 96f9c17

Browse files
committed
validate that folder size sums to children
Signed-off-by: Robin Appelman <[email protected]>
1 parent bbb2474 commit 96f9c17

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

core/Command/Info/File.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(IRootFolder $rootFolder, IUserMountCache $userMountC
4040
parent::__construct();
4141
}
4242

43-
protected function configure() {
43+
protected function configure(): void {
4444
$this
4545
->setName('info:file')
4646
->setDescription('get information for a file')
@@ -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);
@@ -156,6 +163,9 @@ private function formatPermissions(string $type, int $permissions): string {
156163
return implode(", ", $perms);
157164
}
158165

166+
/**
167+
* @psalm-suppress UndefinedClass
168+
*/
159169
private function formatMountType(IMountPoint $mountPoint): string {
160170
$storage = $mountPoint->getStorage();
161171
if ($storage && $storage->instanceOfStorage(IHomeStorage::class)) {
@@ -176,7 +186,7 @@ private function formatMountType(IMountPoint $mountPoint): string {
176186
$description .= " owned by " . $share->getShareOwner();
177187
}
178188
return $description;
179-
} elseif ($mountPoint instanceof GroupMountPoint) { /** @psalm-suppress UndefinedClass */
189+
} elseif ($mountPoint instanceof GroupMountPoint) {
180190
return "groupfolder " . $mountPoint->getFolderId();
181191
} elseif ($mountPoint instanceof ExternalMountPoint) {
182192
return "external storage " . $mountPoint->getStorageConfig()->getId();
@@ -203,6 +213,9 @@ private function formatShareType(IShare $share): ?string {
203213
}
204214
}
205215

216+
/**
217+
* @psalm-suppress UndefinedClass
218+
*/
206219
private function outputStorageDetails(IMountPoint $mountPoint, Node $node, OutputInterface $output): void {
207220
$storage = $mountPoint->getStorage();
208221
if (!$storage) {
@@ -215,7 +228,7 @@ private function outputStorageDetails(IMountPoint $mountPoint, Node $node, Outpu
215228
/** @var ObjectStoreStorage $storage */
216229
$objectStoreId = $storage->getObjectStore()->getStorageId();
217230
$parts = explode(':', $objectStoreId);
218-
$bucket = array_pop($parts);
231+
$bucket = (string)array_pop($parts);
219232
$output->writeln(" bucket: " . $bucket);
220233
if ($node instanceof \OC\Files\Node\File) {
221234
$output->writeln(" object id: " . $storage->getURN($node->getId()));
@@ -242,7 +255,7 @@ private function outputStorageDetails(IMountPoint $mountPoint, Node $node, Outpu
242255
$storageConfig = $mountPoint->getStorageConfig();
243256
$output->writeln(" external storage id: " . $storageConfig->getId());
244257
$output->writeln(" external type: " . $storageConfig->getBackend()->getText());
245-
} elseif ($mountPoint instanceof GroupMountPoint) { /** @psalm-suppress UndefinedClass */
258+
} elseif ($mountPoint instanceof GroupMountPoint) {
246259
$output->writeln(" groupfolder id: " . $mountPoint->getFolderId());
247260
}
248261
}

0 commit comments

Comments
 (0)