From 6261ffd35a3ab9b209aabbac21686b484ed702ec Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 31 Jan 2023 19:14:52 -0800 Subject: [PATCH] fix: clear temp fies during index (fix #355) --- lib/Command/Index.php | 7 ++++++- lib/Controller/DownloadController.php | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Command/Index.php b/lib/Command/Index.php index 244b14ed..b2722d31 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -33,6 +33,7 @@ use OCP\Files\IRootFolder; use OCP\IConfig; use OCP\IDBConnection; use OCP\IPreview; +use OCP\ITempManager; use OCP\IUser; use OCP\IUserManager; use Symfony\Component\Console\Command\Command; @@ -68,6 +69,7 @@ class Index extends Command protected IDBConnection $connection; protected Connection $connectionForSchema; protected TimelineWrite $timelineWrite; + protected ITempManager $tempManager; // Stats private int $nUser = 0; @@ -85,7 +87,8 @@ class Index extends Command IPreview $preview, IConfig $config, IDBConnection $connection, - Connection $connectionForSchema + Connection $connectionForSchema, + ITempManager $tempManager ) { parent::__construct(); @@ -95,6 +98,7 @@ class Index extends Command $this->config = $config; $this->connection = $connection; $this->connectionForSchema = $connectionForSchema; + $this->tempManager = $tempManager; $this->timelineWrite = new TimelineWrite($connection); } @@ -306,6 +310,7 @@ class Index extends Command $progress = (float) (($progress_i / $progress_n) * 100); $this->outputSection->overwrite(sprintf('%.2f%%', $progress).' scanning '.$node->getPath()); $this->parseFile($node, $opts); + $this->tempManager->clean(); } } } catch (\Exception $e) { diff --git a/lib/Controller/DownloadController.php b/lib/Controller/DownloadController.php index 5ddb5924..4d82bf6e 100644 --- a/lib/Controller/DownloadController.php +++ b/lib/Controller/DownloadController.php @@ -27,6 +27,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\ISession; +use OCP\ITempManager; use OCP\Security\ISecureRandom; class DownloadController extends ApiBase @@ -193,6 +194,9 @@ class DownloadController extends ApiBase // So we need to add a number to the end of the name $nameCounts = []; + /** @var ITempManager for clearing temp files */ + $tempManager = \OC::$server->get(ITempManager::class); + // Send each file foreach ($fileIds as $fileId) { if (connection_aborted()) { @@ -265,6 +269,9 @@ class DownloadController extends ApiBase if (false !== $handle) { fclose($handle); } + + // Clear any temp files + $tempManager->clean(); } }