From 95d7bc53193e3592024d142526435349ebb8d9b8 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 28 Oct 2016 14:03:17 +0000 Subject: [PATCH] Continuation of [r4423] Optimizing the scan of icons on disk. Added a LOCK_EX flag to prevent concurrent access related issues. Safe handing of collision on the cache key (used as a filename). SVN:trunk[4471] --- application/forms.class.inc.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/application/forms.class.inc.php b/application/forms.class.inc.php index 8021d5e93..e8cbe785d 100644 --- a/application/forms.class.inc.php +++ b/application/forms.class.inc.php @@ -1368,23 +1368,30 @@ class RunTimeIconSelectionField extends DesignerIconSelectionField static protected function FindIconsOnDisk($sBaseDir, $sDir = '') { - $sKey = md5($sBaseDir.'/'.$sDir); - $sCacheFile = utils::GetCachePath().'available-icons-'.$sKey.'.php'; + $aFiles = null; + $sKey = $sBaseDir.'/'.$sDir; + $sShortKey = crc32($sKey); + $sCacheFile = utils::GetCachePath().'available-icons-'.$sShortKey.'.php'; + $sCacheClass = 'AvailableIcons_'.$sShortKey; if (file_exists($sCacheFile)) { require_once($sCacheFile); - $aFiles = AvailableIcons::$aIconFiles; + if ($sCacheClass::$sKey === $sKey) // crc32 collision detection + { + $aFiles = $sCacheClass::$aIconFiles; + } } - else + if ($aFiles === null) { $aFiles = self::_FindIconsOnDisk($sBaseDir, $sDir); $sAvailableIcons = '