# HG changeset patch # User Matti Hamalainen # Date 1442213641 -10800 # Node ID 805f93962cf96790dfb8f8834f9149b1767a0bc9 # Parent c9fad00199f98809e13fdda5e85c893e0a597aeb Factorize gallery cache file writing to a separate function. diff -r c9fad00199f9 -r 805f93962cf9 mgtool.php --- a/mgtool.php Fri Aug 28 13:13:27 2015 +0300 +++ b/mgtool.php Mon Sep 14 09:54:01 2015 +0300 @@ -327,6 +327,39 @@ } +function mgWriteGalleryCache($cacheFilename, &$gallery, &$entries) +{ + // Store gallery cache for this directory + $images = array(); + $albums = array(); + foreach ($entries as $ename => &$edata) + { + if ($edata["hide"]) + continue; + + unset($edata["hide"]); + if ($edata["type"] == 0) + $images[$ename] = &$edata; + else + $albums[$ename] = &$edata; + } + ksort($images); + ksort($albums); + + $str = + ""; + + if (@file_put_contents($cacheFilename, $str, LOCK_EX) === FALSE) + return mgError("Error writing '".$cacheFilename."'\n"); + + return TRUE; +} + function mgHandleDirectory($mode, $basepath, $path, $parentData, $parentEntry, $writeMode, $startAt) { global $galExifConversions, $galTNPath, $galCleanFlags; @@ -509,34 +542,11 @@ mgCheckQuit(TRUE); // Store gallery cache for this directory - if ($writeMode) + if ($writeMode && !mgWriteGalleryCache($cacheFilename, $gallery, $entries)) + return FALSE; { - $images = array(); - $albums = array(); - foreach ($entries as $ename => &$edata) { - if ($edata["hide"]) - continue; - - unset($edata["hide"]); - if ($edata["type"] == 0) - $images[$ename] = &$edata; - else - $albums[$ename] = &$edata; } - ksort($images); - ksort($albums); - - $str = - ""; - - if (@file_put_contents($cacheFilename, $str, LOCK_EX) === FALSE) - return mgError("Error writing '".$cacheFilename."'\n"); } } else