fix: clear temp fies during index (fix #355)

pull/391/head
Varun Patil 2023-01-31 19:14:52 -08:00
parent 3a7037d3cd
commit 6261ffd35a
2 changed files with 13 additions and 1 deletions

View File

@ -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) {

View File

@ -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();
}
}