Index: infusionBuilder-secure/php/postProcessor.php =================================================================== --- infusionBuilder-secure/php/postProcessor.php (revision 9348) +++ infusionBuilder-secure/php/postProcessor.php (working copy) @@ -128,7 +128,7 @@ * @return object $cache_row A row of data from the cache table if successful, FALSE otherwise */ function checkCacheMysql($cacheKey, $intMin, $error_message) { - $cache_query = "SELECT * FROM cache WHERE id = '{$cacheKey}' AND minified = ".$intMin; + $cache_query = "SELECT * FROM cache WHERE id = '{$cacheKey}' AND minified = ".$intMin; $cache_result = mysql_query($cache_query); if (!$cache_result) { //mysql_query resulted in error returnError($error_message); @@ -144,6 +144,54 @@ return $is_cached; } +/** + * Deletes a directory, including containing files and subdirectories. + * **I am having some problems with this function on windows due to the + * limitation that directory and file names are limited to 260 characters + * including path information. Because the depth of some of the infusion + * directories are so deep, some of my temp files are not being deleted. + * This needs more testing in a unix environment. + * + * @param $dir String name of the directory to be deleted. + * @return Boolean true if the deletion was successful and false otherwise + */ +function deleteDirectory($dir) { + if (!file_exists($dir)) return true; + if (!is_dir($dir)) { + return unlink($dir); + } + foreach (scandir($dir) as $item) { + if ($item == '.' || $item == '..') { + continue; + } + if (!deleteDirectory($dir."/".$item, $fh)) { + return false; + } + } + return rmdir($dir); +} + +/** +* Gets a mysql UUID from an already established mysql connection +* +* @return string UUID +*/ +function getUUID() { + + //get UUID to use as temp directory name + $uuid_query = "SELECT uuid()"; + $uuid_result = mysql_query($uuid_query); + if (!$uuid_result) { + returnError("Cannot get UUID"); + exit (1); + } + if (mysql_num_rows($uuid_result) == 1) { + $uuid_row = mysql_fetch_assoc($uuid_result); + mysql_free_result($uuid_result); + } + return $uuid_row["uuid()"]; +} + //START OF EXECUTION //process posted values @@ -174,27 +222,10 @@ exit (1); } -//get UUID to use as temp directory name -$uuid_query = "SELECT uuid()"; -$uuid_result = mysql_query($uuid_query); -if (!$uuid_result) { - returnError("Cannot complete cache retrieval query"); - exit (1); -} -if (mysql_num_rows($uuid_result) == 1) { - $uuid_row = mysql_fetch_assoc($uuid_result); - mysql_free_result($uuid_result); -} -$uuid = $uuid_row["uuid()"]; - //initialize some variables -$tmppath = OUTPUT_FILE_PATH_PRODUCTS.$uuid; //path for temporary files $cachepath = CACHE_FILE_PATH.$cacheKey; //path to cached files - $minfilename = "infusion-".$ver.".zip"; //filename of minified zip $srcfilename = "infusion-".$ver."-src.zip"; //filename of source zip - -$tmpfilename = $tmppath."/".$minfilename; //path and filename of temporary zip file $filename = $min ? $minfilename : $srcfilename; //filename desired (either source or zip) $filepath = $cachepath."/".$filename; //path and filename of cached file @@ -206,6 +237,11 @@ //file is not cached - go through build process if (!$is_cached) { + $uuid = getUUID(); + $tmpbuildpath = OUTPUT_FILE_PATH_BUILD.$uuid; //path for temporary build files + $tmppath = OUTPUT_FILE_PATH_PRODUCTS.$uuid; //path for temporary files + $tmpfilename = $tmppath."/".$minfilename; //path and filename of temporary zip file + //create cache directory if (!file_exists($cachepath)) { if (!@mkdir($cachepath, 0755, true)) { @@ -227,8 +263,13 @@ returnError("Cannot copy temp file to cache"); exit(1); } - - //insert cache entry for this build + + //delete the tmp files and remove directories + //$tmpbuildpath and $tmppath + deleteDirectory($tmppath); + deleteDirectory($tmpbuildpath); + + //insert cache entry for this build $insert_query = "INSERT INTO cache (id, minified) VALUES('$cacheKey', ".$intMin.")"; $insert_result = mysql_query($insert_query); if (!$insert_result) {