Skip to content
Open
Changes from all commits
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
34 changes: 25 additions & 9 deletions core/Command/User/Info.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -31,6 +32,11 @@ protected function configure() {
'user',
InputArgument::REQUIRED,
'user to show'
)->addOption(
'human',
null,
InputOption::VALUE_NONE,
'Print storage values in human-readable format'
)->addOption(
'output',
null,
Expand All @@ -55,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'enabled' => $user->isEnabled(),
'groups' => $groups,
'quota' => $user->getQuota(),
'storage' => $this->getStorageInfo($user),
'storage' => $this->getStorageInfo($user, $input),
'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601
'user_directory' => $user->getHome(),
'backend' => $user->getBackendClassName()
Expand All @@ -68,21 +74,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
* @param IUser $user
* @return array
*/
protected function getStorageInfo(IUser $user): array {
protected function getStorageInfo(IUser $user, InputInterface $input): array {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user->getUID());
try {
$storage = \OC_Helper::getStorageInfo('/');
} catch (\OCP\Files\NotFoundException $e) {
return [];
}
return [
'free' => $storage['free'],
'used' => $storage['used'],
'total' => $storage['total'],
'relative' => $storage['relative'],
'quota' => $storage['quota'],
];
if ($input->getOption('human')) {
return [
'free' => \OC_Helper::humanFileSize($storage['free']),
'used' => \OC_Helper::humanFileSize($storage['used']),
'total' => \OC_Helper::humanFileSize($storage['total']),
'relative' => $storage['relative'] . '%',
'quota' => ($storage['quota'] >= 0) ? \OC_Helper::humanFileSize($storage['quota']) : $storage['quota'],
Comment on lines +87 to +91
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'free' => \OC_Helper::humanFileSize($storage['free']),
'used' => \OC_Helper::humanFileSize($storage['used']),
'total' => \OC_Helper::humanFileSize($storage['total']),
'relative' => $storage['relative'] . '%',
'quota' => ($storage['quota'] >= 0) ? \OC_Helper::humanFileSize($storage['quota']) : $storage['quota'],
'free' => Util::humanFileSize($storage['free']),
'used' => Util::humanFileSize($storage['used']),
'total' => Util::humanFileSize($storage['total']),
'relative' => $storage['relative'] . '%',
'quota' => ($storage['quota'] >= 0) ? Util::humanFileSize($storage['quota']) : $storage['quota'],

And add a use \OCP\Util; to the top. OC_* classes are deprecated.

];
} else {
return [
'free' => $storage['free'],
'used' => $storage['used'],
'total' => $storage['total'],
'relative' => $storage['relative'],
'quota' => $storage['quota'],
];
}
}

/**
Expand Down