diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-06-21 14:05:38 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-06-21 14:29:44 +0200 |
commit | 944675a4a2cf95d9b2c71f448cffd75c75829e8c (patch) | |
tree | 8bdae1f98629c4b75419c84aeb19e8f9d386dc91 /apps/dav/lib/BackgroundJob | |
parent | de82d4f67ca8d12a0209598f9cdd55302d546524 (diff) | |
download | nextcloud-server-944675a4a2cf95d9b2c71f448cffd75c75829e8c.tar.gz nextcloud-server-944675a4a2cf95d9b2c71f448cffd75c75829e8c.zip |
Handle file contained inside the uploads folder
Fix #32450
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps/dav/lib/BackgroundJob')
-rw-r--r-- | apps/dav/lib/BackgroundJob/UploadCleanup.php | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/apps/dav/lib/BackgroundJob/UploadCleanup.php b/apps/dav/lib/BackgroundJob/UploadCleanup.php index f612f58cd7c..3a6f296deaf 100644 --- a/apps/dav/lib/BackgroundJob/UploadCleanup.php +++ b/apps/dav/lib/BackgroundJob/UploadCleanup.php @@ -37,15 +37,18 @@ use OCP\Files\File; 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); @@ -61,19 +64,27 @@ class UploadCleanup extends TimedJob { $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; |