From 7b45c629a3a7c5ada3e368e894297a45ccd4148d Mon Sep 17 00:00:00 2001 From: Conrad Vermeulen Date: Tue, 12 Aug 2008 10:42:36 +0000 Subject: [PATCH] KTS-3598 "KnowledgeTree's temp folder has too many smarty files in it. over time, the directory gets very large." Implemented. We clean up files and directories created more than a day ago. Ideally, we'd use smarty better so this would not happen. --- search2/bin/cronCleanup.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/search2/bin/cronCleanup.php b/search2/bin/cronCleanup.php index 198be1e..e21ea2a 100644 --- a/search2/bin/cronCleanup.php +++ b/search2/bin/cronCleanup.php @@ -43,25 +43,37 @@ require_once(realpath('../../config/dmsDefaults.php')); $config = KTConfig::getSingleton(); $temp_dir =$config->get("urls/tmpDirectory"); - cleanupTempDirectory($temp_dir); -function cleanupTempDirectory($dir) +function cleanupTempDirectory($dir, $force = false) { - if (!is_dir($dir)) - { - return; - } $dir = str_replace('\\','/', $dir); $dh = opendir($dir); while (($name = readdir($dh)) !== false) { - if (substr($name, 0, 9) != 'ktindexer') + if (substr($name, 0, 1) == '.') continue; + + $kti = (substr($name, 0, 3) == 'kti'); // remove files starting with kti (indexer temp files created by open office) + + $fullname = $dir . '/' . $name; + + if (!$kti && !$force) { - continue; + $info = stat($fullname); + if ($info['ctime'] >= time() - 24 * 60 * 60) continue; // remove files that have been accessed in the last 24 hours } - unlink($dir . '/' . $name); + + if (is_dir($fullname)) + { + cleanupTempDirectory($fullname, true); + rmdir($fullname); + } + else + { + unlink($fullname); + } + } closedir($dh); } -- libgit2 0.21.4