Skip to content
Merged
Changes from 1 commit
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
53 changes: 24 additions & 29 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
use Psr\Log\LoggerInterface;

class Trashbin {

// unit: percentage; 50% of available disk space/quota
public const DEFAULTMAXSIZE = 50;

Expand Down Expand Up @@ -191,7 +190,7 @@ private static function setUpTrash($user) {
* @param string $owner
* @param string $targetPath
* @param $user
* @param integer $timestamp
* @param int $timestamp
*/
private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp) {
self::setUpTrash($owner);
Expand Down Expand Up @@ -306,8 +305,8 @@ public static function move2trash($file_path, $ownerOnly = false) {
}

$config = \OC::$server->getConfig();
$systemTrashbinSize = (int)$config->getAppValue('files_trashbin', 'trashbin_size', '-1');
$userTrashbinSize = (int)$config->getUserValue($owner, 'files_trashbin', 'trashbin_size', '-1');
$systemTrashbinSize = \OCP\Util::numericToNumber($config->getAppValue('files_trashbin', 'trashbin_size', '-1'));
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
$userTrashbinSize = \OCP\Util::numericToNumber($config->getUserValue($owner, 'files_trashbin', 'trashbin_size', '-1'));
Comment thread Fixed
$configuredTrashbinSize = ($userTrashbinSize < 0) ? $systemTrashbinSize : $userTrashbinSize;
if ($configuredTrashbinSize >= 0 && $sourceInfo->getSize() >= $configuredTrashbinSize) {
return false;
Expand Down Expand Up @@ -386,7 +385,7 @@ public static function move2trash($file_path, $ownerOnly = false) {
* @param string $filename of deleted file
* @param string $owner owner user id
* @param string $ownerPath path relative to the owner's home storage
* @param integer $timestamp when the file was deleted
* @param int $timestamp when the file was deleted
*/
private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions') && !empty($ownerPath)) {
Expand Down Expand Up @@ -647,7 +646,7 @@ protected static function emitTrashbinPostDelete($path) {
* @param string $user
* @param int $timestamp of deletion time
*
* @return int size of deleted files
* @return int|float size of deleted files
*/
public static function delete($filename, $user, $timestamp = null) {
$userRoot = \OC::$server->getUserFolder($user)->getParent();
Expand Down Expand Up @@ -689,14 +688,11 @@ public static function delete($filename, $user, $timestamp = null) {
}

/**
* @param View $view
* @param string $file
* @param string $filename
* @param integer|null $timestamp
* @param string $user
* @return int
* @param ?int $timestamp
*/
private static function deleteVersions(View $view, $file, $filename, $timestamp, $user) {
private static function deleteVersions(View $view, $file, $filename, $timestamp, string $user): int|float {
$size = 0;
if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
if ($view->is_dir('files_trashbin/versions/' . $file)) {
Expand Down Expand Up @@ -752,17 +748,17 @@ public static function deleteUser($uid) {
/**
* calculate remaining free space for trash bin
*
* @param integer $trashbinSize current size of the trash bin
* @param int|float $trashbinSize current size of the trash bin
* @param string $user
* @return int available free space for trash bin
* @return int|float available free space for trash bin
*/
private static function calculateFreeSpace($trashbinSize, $user) {
private static function calculateFreeSpace(int|float $trashbinSize, string $user): int|float {
$config = \OC::$server->getConfig();
$userTrashbinSize = (int)$config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
$userTrashbinSize = \OCP\Util::numericToNumber($config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'));
Comment thread Fixed
if ($userTrashbinSize > -1) {
return $userTrashbinSize - $trashbinSize;
}
$systemTrashbinSize = (int)$config->getAppValue('files_trashbin', 'trashbin_size', '-1');
$systemTrashbinSize = \OCP\Util::numericToNumber($config->getAppValue('files_trashbin', 'trashbin_size', '-1'));
Comment thread Fixed
if ($systemTrashbinSize > -1) {
return $systemTrashbinSize - $trashbinSize;
}
Expand Down Expand Up @@ -801,7 +797,7 @@ private static function calculateFreeSpace($trashbinSize, $user) {
$availableSpace = $quota;
}

return (int)$availableSpace;
return \OCP\Util::numericToNumber($availableSpace);
Comment thread Fixed
}

/**
Expand Down Expand Up @@ -858,10 +854,10 @@ private static function scheduleExpire($user) {
*
* @param array $files
* @param string $user
* @param int $availableSpace available disc space
* @return int size of deleted files
* @param int|float $availableSpace available disc space
* @return int|float size of deleted files
*/
protected static function deleteFiles($files, $user, $availableSpace) {
protected static function deleteFiles(array $files, string $user, int|float $availableSpace): int|float {
/** @var Application $application */
$application = \OC::$server->query(Application::class);
$expiration = $application->getContainer()->query('Expiration');
Expand All @@ -887,7 +883,7 @@ protected static function deleteFiles($files, $user, $availableSpace) {
*
* @param array $files list of files sorted by mtime
* @param string $user
* @return integer[] size of deleted files and number of deleted files
* @return array{int|float, int} size of deleted files and number of deleted files
*/
public static function deleteExpiredFiles($files, $user) {
/** @var Expiration $expiration */
Expand Down Expand Up @@ -927,10 +923,10 @@ public static function deleteExpiredFiles($files, $user) {
* @param string $source source path, relative to the users files directory
* @param string $destination destination path relative to the users root directory
* @param View $view file view for the users root directory
* @return int
* @return int|float
* @throws Exceptions\CopyRecursiveException
*/
private static function copy_recursive($source, $destination, View $view) {
private static function copy_recursive($source, $destination, View $view): int|float {
$size = 0;
if ($view->is_dir($source)) {
$view->mkdir($destination);
Expand Down Expand Up @@ -964,9 +960,8 @@ private static function copy_recursive($source, $destination, View $view) {
*
* @param string $filename name of the file which should be restored
* @param int $timestamp timestamp when the file was deleted
* @return array
*/
private static function getVersionsFromTrash($filename, $timestamp, $user) {
private static function getVersionsFromTrash($filename, $timestamp, string $user): array {
$view = new View('/' . $user . '/files_trashbin/versions');
$versions = [];

Expand Down Expand Up @@ -1061,9 +1056,9 @@ private static function getUniqueFilename($location, $filename, View $view) {
* get the size from a given root folder
*
* @param View $view file view on the root folder
* @return integer size of the folder
* @return int|float size of the folder
*/
private static function calculateSize($view) {
private static function calculateSize(View $view): int|float {
$root = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . $view->getAbsolutePath('');
if (!file_exists($root)) {
return 0;
Expand Down Expand Up @@ -1092,9 +1087,9 @@ private static function calculateSize($view) {
* get current size of trash bin from a given user
*
* @param string $user user who owns the trash bin
* @return integer trash bin size
* @return int|float trash bin size
*/
private static function getTrashbinSize($user) {
private static function getTrashbinSize(string $user): int|float {
$view = new View('/' . $user);
$fileInfo = $view->getFileInfo('/files_trashbin');
return isset($fileInfo['size']) ? $fileInfo['size'] : 0;
Expand Down