Skip to content
Merged
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
Handle file contained inside the uploads folder
Fix #32450

Signed-off-by: Carl Schwan <[email protected]>
  • Loading branch information
CarlSchwan committed Jun 21, 2022
commit 944675a4a2cf95d9b2c71f448cffd75c75829e8c
21 changes: 16 additions & 5 deletions apps/dav/lib/BackgroundJob/UploadCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use Psr\Log\LoggerInterface;

class UploadCleanup extends TimedJob {
private IRootFolder $rootFolder;
private IJobList $jobList;
private LoggerInterface $logger;

public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList) {
public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList, LoggerInterface $logger) {
parent::__construct($time);
$this->rootFolder = $rootFolder;
$this->jobList = $jobList;
$this->logger = $logger;

// Run once a day
$this->setInterval(60 * 60 * 24);
Expand All @@ -61,19 +64,27 @@ protected function run($argument) {
$userRoot = $userFolder->getParent();
/** @var Folder $uploads */
$uploads = $userRoot->get('uploads');
/** @var Folder $uploadFolder */
$uploadFolder = $uploads->get($folder);
} catch (NotFoundException | NoUserException $e) {
$this->jobList->remove(self::class, $argument);
return;
}

/** @var File[] $files */
$files = $uploadFolder->getDirectoryListing();

// Remove if all files have an mtime of more than a day
$time = $this->time->getTime() - 60 * 60 * 24;

if (!($uploadFolder instanceof Folder)) {
$this->logger->error("Found a file inside the uploads folder. Uid: " . $uid . ' folder: ' . $folder);
if ($uploadFolder->getMTime() < $time) {
$uploadFolder->delete();
}
$this->jobList->remove(self::class, $argument);
return;
}

/** @var File[] $files */
$files = $uploadFolder->getDirectoryListing();

// The folder has to be more than a day old
$initial = $uploadFolder->getMTime() < $time;

Expand Down