diff --git a/core/Command/Info/FileUtils.php b/core/Command/Info/FileUtils.php index 1264dee5de21b..34ef29c538004 100644 --- a/core/Command/Info/FileUtils.php +++ b/core/Command/Info/FileUtils.php @@ -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; @@ -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 * diff --git a/core/Command/Info/UserFiles.php b/core/Command/Info/UserFiles.php new file mode 100644 index 0000000000000..f0983d10d1176 --- /dev/null +++ b/core/Command/Info/UserFiles.php @@ -0,0 +1,112 @@ +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("usefr $userId not found"); + 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 occ info:file:space to get more details about used space"); + + return 0; + } + +} diff --git a/core/register_command.php b/core/register_command.php index 8f600d7b89488..70db8957fa4d6 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -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))); diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index ea60de137d25e..fd4b7f6d46b53 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -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']; @@ -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(); } @@ -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; + } }