Merge pull request #55742 from nextcloud/fix-trashbin-expiration

fix(trashbin): make sure the trashed files are deleted if we don't have any available space left
pull/55676/head
Côme Chilliet 2025-10-20 10:47:17 +07:00 committed by GitHub
commit a36ebef1c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 6 deletions

@ -11,7 +11,6 @@ use OC\Files\SetupManager;
use OC\Files\View;
use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Expiration;
use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
@ -66,8 +65,7 @@ class ExpireTrash extends TimedJob {
try {
if ($this->setupFS($user)) {
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
Trashbin::deleteExpiredFiles($dirContent, $uid);
Trashbin::expire($uid);
}
} catch (\Throwable $e) {
$this->logger->error('Error while expiring trashbin for user ' . $uid, ['exception' => $e]);

@ -844,7 +844,7 @@ class Trashbin implements IEventListener {
$dirContent = Helper::getTrashFiles('/', $user, 'mtime');
// delete all files older then $retention_obligation
[$delSize, $count] = self::deleteExpiredFiles($dirContent, $user);
[$delSize, $count] = self::deleteExpiredFiles($dirContent, $user, $availableSpace <= 0);
$availableSpace += $delSize;
@ -906,9 +906,10 @@ class Trashbin implements IEventListener {
*
* @param array $files list of files sorted by mtime
* @param string $user
* @param bool $quotaExceeded
* @return array{int|float, int} size of deleted files and number of deleted files
*/
public static function deleteExpiredFiles($files, $user) {
public static function deleteExpiredFiles($files, $user, bool $quotaExceeded = false) {
/** @var Expiration $expiration */
$expiration = Server::get(Expiration::class);
$size = 0;
@ -916,7 +917,7 @@ class Trashbin implements IEventListener {
foreach ($files as $file) {
$timestamp = $file['mtime'];
$filename = $file['name'];
if ($expiration->isExpired($timestamp)) {
if ($expiration->isExpired($timestamp, $quotaExceeded)) {
try {
$size += self::delete($filename, $user, $timestamp);
$count++;