From f162a5dd1af6ec7194dd246b2b36f100eb6a8448 Mon Sep 17 00:00:00 2001 From: kevin_fourie Date: Tue, 12 Aug 2008 11:05:55 +0000 Subject: [PATCH] Merged in from DEV trunk... --- search2/bin/cronCleanup.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/search2/bin/cronCleanup.php b/search2/bin/cronCleanup.php index 198be1e..d72c449 100644 --- a/search2/bin/cronCleanup.php +++ b/search2/bin/cronCleanup.php @@ -43,25 +43,39 @@ 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); + if (strpos($dir, '/tmp') === false) return; + $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