From: Tim Otten Date: Sat, 30 Aug 2014 03:08:29 +0000 (-0700) Subject: CRM_Core_CodeGen_Util_File - Better tempdir creation X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0eed9eccea7dcedff96953e7745c3f76f2b247e0;p=civicrm-core.git CRM_Core_CodeGen_Util_File - Better tempdir creation --- diff --git a/CRM/Core/CodeGen/Util/File.php b/CRM/Core/CodeGen/Util/File.php index 47f99ea623..5784c7ccdf 100644 --- a/CRM/Core/CodeGen/Util/File.php +++ b/CRM/Core/CodeGen/Util/File.php @@ -17,11 +17,16 @@ class CRM_Core_CodeGen_Util_File { /** * @param $dir */ - static function removeDir($dir) { + static function cleanTempDir($dir) { foreach (glob("$dir/*") as $tempFile) { unlink($tempFile); } rmdir($dir); + if (preg_match(':^(.*)\.d$:', $dir, $matches)) { + if (file_exists($matches[1])) { + unlink($matches[1]); + } + } } /** @@ -30,18 +35,7 @@ class CRM_Core_CodeGen_Util_File { * @return string */ static function createTempDir($prefix) { - if (isset($_SERVER['TMPDIR'])) { - $tempDir = $_SERVER['TMPDIR']; - } - else { - $tempDir = '/tmp'; - } - - $newTempDir = $tempDir . '/' . $prefix . rand(1, 10000); - if (function_exists('posix_geteuid')) { - $newTempDir .= '_' . posix_geteuid(); - } - + $newTempDir = tempnam(sys_get_temp_dir(), $prefix) . '.d'; if (file_exists($newTempDir)) { self::removeDir($newTempDir); } diff --git a/CRM/Core/CodeGen/Util/Template.php b/CRM/Core/CodeGen/Util/Template.php index f9a509f584..3d14b8896f 100644 --- a/CRM/Core/CodeGen/Util/Template.php +++ b/CRM/Core/CodeGen/Util/Template.php @@ -50,7 +50,7 @@ class CRM_Core_CodeGen_Util_Template { } function __destruct() { - CRM_Core_CodeGen_Util_File::removeDir($this->compileDir); + CRM_Core_CodeGen_Util_File::cleanTempDir($this->compileDir); } /**