Skip to content
Closed
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions core/Command/Info/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IUser;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -181,6 +182,18 @@ public function formatShareType(IShare $share): ?string {
}
}

/**
* @param IUser $user
* @return IMountPoint[]
*/
public function getMountsForUser(IUser $user): array {
$this->setupManager->setupForUser($user);
$prefix = "/" . $user->getUID();
return array_filter($this->mountManager->getAll(), function (IMountPoint $mount) use ($prefix) {
return str_starts_with($mount->getMountPoint(), $prefix);
});
}

/**
* Print out the largest count($sizeLimits) files in the directory tree
*
Expand Down
112 changes: 112 additions & 0 deletions core/Command/Info/UserFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

declare(strict_types=1);

namespace OC\Core\Command\Info;

use OC\Files\ObjectStore\HomeObjectStoreStorage;
use OC\Files\ObjectStore\ObjectStoreStorage;
use OC\Files\Storage\Local;
use OCA\Circles\MountManager\CircleMount;
use OCA\Files_External\Config\ExternalMountPoint;
use OCA\Files_Sharing\SharedMount;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCP\Constants;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IHomeStorage;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UserFiles extends Command {
private IRootFolder $rootFolder;
private IUserManager $userManager;
private IL10N $l10n;
private FileUtils $fileUtils;

public function __construct(
IRootFolder $rootFolder,
IUserManager $userManager,
IFactory $l10nFactory,
FileUtils $fileUtils
) {
$this->rootFolder = $rootFolder;
$this->userManager = $userManager;
$this->l10n = $l10nFactory->get("core");
$this->fileUtils = $fileUtils;
parent::__construct();
}

protected function configure(): void {
$this
->setName('info:file:user')
->setDescription('get file information for a user')
->addArgument('user_id', InputArgument::REQUIRED, "User id")
->addOption('large-files', 'l', InputOption::VALUE_REQUIRED, "Number of large files and folders to show", 25);
}

public function execute(InputInterface $input, OutputInterface $output): int {
$userId = $input->getArgument('user_id');
$user = $this->userManager->get($userId);
if (!$user) {
$output->writeln("<error>usefr $userId not found</error>");
return 1;
}

$output->writeln($user->getUID());
$output->writeln("");

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$userStorage = $userFolder->getStorage();
if ($userStorage->instanceOfStorage(Local::class)) {
$output->writeln(" data directory: " . $user->getHome());
} else if ($userStorage->instanceOfStorage(HomeObjectStoreStorage::class)) {
/** @var HomeObjectStoreStorage $userStorage */
$output->writeln(" bucket: " . $userStorage->getBucket());
}

$mounts = $this->fileUtils->getMountsForUser($user);
$output->writeln("");
$output->writeln(" available storages:");
foreach ($mounts as $mount) {
$storage = $mount->getStorage();
if (!$storage) {
continue;
}
$cache = $storage->getCache();
$free = Util::humanFileSize($storage->free_space(""));
$output->write(" - " . $mount->getMountPoint() . ": " . $this->fileUtils->formatMountType($mount));
if ($storage->instanceOfStorage(IHomeStorage::class)) {
$filesInfo = $cache->get("files");
$trashInfo = $cache->get("files_trashbin");
$versionsInfo = $cache->get("files_versions");
$used = Util::humanFileSize($filesInfo ? $filesInfo->getSize() : 0);
$trashUsed = Util::humanFileSize($trashInfo ? $trashInfo->getSize() : 0);
$versionUsed = Util::humanFileSize($versionsInfo ? $versionsInfo->getSize() : 0);
$output->writeln(" ($used in files, $trashUsed in trash, $versionUsed in versions, $free free)");
} else {
$rootInfo = $cache->get("");
$used = Util::humanFileSize($rootInfo ? $rootInfo->getSize(): -1);
$output->writeln(" ($used used, $free free)");
}
}
$output->writeln("");
$output->writeln(" use <info>occ info:file:space <path></info> to get more details about used space");

return 0;
}

}
1 change: 1 addition & 0 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

$application->add(\OC::$server->get(OC\Core\Command\Info\File::class));
$application->add(\OC::$server->get(OC\Core\Command\Info\Space::class));
$application->add(\OC::$server->get(OC\Core\Command\Info\UserFiles::class));

$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class)));
Expand Down
12 changes: 12 additions & 0 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
/** @var bool */
protected $validateWrites = true;

private string $bucket;

public function __construct($params) {
if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
$this->objectStore = $params['objectstore'];
Expand All @@ -92,6 +94,12 @@ public function __construct($params) {
$this->mkdir('/');
}

if (isset($params['container'])) { // azure
$this->bucket = $params['container'];
} else { // s3, swift
$this->bucket = $params['bucket'];
}

$this->logger = \OC::$server->getLogger();
}

Expand Down Expand Up @@ -716,4 +724,8 @@ public function cancelChunkedWrite(string $targetPath, string $writeToken): void
$urn = $this->getURN($cacheEntry->getId());
$this->objectStore->abortMultipartUpload($urn, $writeToken);
}

public function getBucket(): string {
return $this->bucket;
}
}