From 111c662decb8a53010546986412891d46177cd31 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 5 Feb 2015 13:20:29 +0000 Subject: [PATCH] fixed the cloc graph generator to purge temporary files properly --- codepot/src/codepot/controllers/code.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 13d76943..c845927d 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -677,21 +677,24 @@ class Code extends Controller return; } - $tfname = @tempnam(__FILE__, 'xxx'); + // pass __FILE__ as the first argument so that tempnam creates a name + // in the system directory. __FILE__ can never be a valid directory. + $tfname = @tempnam(__FILE__, 'codepot-cloc-'); if ($tfname === FALSE) { header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error'); return; } - $tfname = $tfname . '.' . pathinfo ($file['name'], PATHINFO_EXTENSION); - @file_put_contents ($tfname, $file['content']); + $actual_tfname = $tfname . '.' . pathinfo ($file['name'], PATHINFO_EXTENSION); + @file_put_contents ($actual_tfname, $file['content']); - $cloc_cmd = sprintf ('%s --quiet --csv --csv-delimiter=":" %s', CODEPOT_CLOC_COMMAND_PATH, $tfname); + $cloc_cmd = sprintf ('%s --quiet --csv --csv-delimiter=":" %s', CODEPOT_CLOC_COMMAND_PATH, $actual_tfname); $cloc = @popen ($cloc_cmd, 'r'); if ($cloc === FALSE) { @unlink ($tfname); + @unlink ($actual_tfname); header($_SERVER['SERVER_PROTOCOL'].' 500 Internal Server Error'); return; } @@ -710,6 +713,7 @@ class Code extends Controller @pclose ($cloc); @unlink ($tfname); + @unlink ($actual_tfname); if ($counter === FALSE) {