Skip to content

Commit 0f322d3

Browse files
committed
Handle file contained inside the uploads folder
Fix #32450 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent de82d4f commit 0f322d3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

apps/dav/lib/BackgroundJob/UploadCleanup.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@
3737
use OCP\Files\Folder;
3838
use OCP\Files\IRootFolder;
3939
use OCP\Files\NotFoundException;
40+
use Psr\Log\LoggerInterface;
4041

4142
class UploadCleanup extends TimedJob {
4243
private IRootFolder $rootFolder;
4344
private IJobList $jobList;
45+
private ILoggerInterface $logger;
4446

45-
public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList) {
47+
public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList, ILoggerInterface $logger) {
4648
parent::__construct($time);
4749
$this->rootFolder = $rootFolder;
4850
$this->jobList = $jobList;
51+
$this->logger = $logger;
4952

5053
// Run once a day
5154
$this->setInterval(60 * 60 * 24);
@@ -61,19 +64,27 @@ protected function run($argument) {
6164
$userRoot = $userFolder->getParent();
6265
/** @var Folder $uploads */
6366
$uploads = $userRoot->get('uploads');
64-
/** @var Folder $uploadFolder */
6567
$uploadFolder = $uploads->get($folder);
6668
} catch (NotFoundException | NoUserException $e) {
6769
$this->jobList->remove(self::class, $argument);
6870
return;
6971
}
7072

71-
/** @var File[] $files */
72-
$files = $uploadFolder->getDirectoryListing();
73-
7473
// Remove if all files have an mtime of more than a day
7574
$time = $this->time->getTime() - 60 * 60 * 24;
7675

76+
if (!($uploadFolder instanceof Folder)) {
77+
$this->logger->error("Foud a file inside the uploads folder. Uid: " . $uid . ' folder: ' . $folder, )
78+
if ($uploadFolder->getMTime() < $time) {
79+
$uploadFolder->delete();
80+
}
81+
$this->jobList->remove(self::class, $argument);
82+
return;
83+
}
84+
85+
/** @var File[] $files */
86+
$files = $uploadFolder->getDirectoryListing();
87+
7788
// The folder has to be more than a day old
7889
$initial = $uploadFolder->getMTime() < $time;
7990

0 commit comments

Comments
 (0)