summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Parry <github@chad.parry.org>2011-04-30 16:40:55 -0600
committerChad Parry <github@chad.parry.org>2011-04-30 17:45:44 -0600
commit0e844766baf3b3875cbb2d84579626e05e879420 (patch)
tree9be9474531aa5220243b07f2d33bb5dcd4ced5d6
parent5c9a3b3f39f6ff0d5c84c2cf283d27eaebe2e66e (diff)
Change the signature of system::tempnam to something more appropriate for Gallery.
-rw-r--r--modules/gallery/controllers/quick.php4
-rw-r--r--modules/gallery/helpers/system.php13
-rw-r--r--modules/gallery/tests/System_Helper_Test.php5
3 files changed, 13 insertions, 9 deletions
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index ce52cb8d..b6576ec0 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -36,8 +36,8 @@ class Quick_Controller extends Controller {
}
if ($degrees) {
- $tmpfile = system::tempnam(TMPPATH, "rotate",
- "." . pathinfo($item->file_path(), PATHINFO_EXTENSION));
+ $tmpfile = system::temp_filename("rotate",
+ pathinfo($item->file_path(), PATHINFO_EXTENSION));
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index 31ecafa7..9815d588 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -43,15 +43,18 @@ class system_Core {
/**
* Create a file with a unique file name.
- * This helper is similar to the built-in tempnam, except that it supports an optional postfix.
+ * This helper is similar to the built-in tempnam.
+ * It allows the caller to specify a prefix and an extension.
+ * It always places the file in TMPPATH.
*/
- static function tempnam($dir = TMPPATH, $prefix = "", $postfix = "") {
- return self::_tempnam($dir, $prefix, $postfix, "tempnam");
+ static function temp_filename($prefix = "", $extension = "") {
+ return self::_tempnam(TMPPATH, $prefix, ".$extension", "tempnam");
}
- // This helper provides a dependency-injected implementation of tempnam.
+ /**
+ * This helper provides a dependency-injected implementation of tempnam.
+ */
static function _tempnam($dir, $prefix, $postfix, $builtin) {
- $success = false;
do {
$basename = call_user_func($builtin, $dir, $prefix);
if (!$basename) {
diff --git a/modules/gallery/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
index 734f98ac..dfe5d9ab 100644
--- a/modules/gallery/tests/System_Helper_Test.php
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -18,10 +18,11 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class System_Helper_Test extends Gallery_Unit_Test_Case {
- public function tempnam_random_test() {
- $filename = system::tempnam(TMPPATH, "file", ".ext");
+ public function temp_filename_random_test() {
+ $filename = system::temp_filename("file", "ext");
$this->assert_true(file_exists($filename), "File not created");
unlink($filename);
+ $this->assert_pattern($filename, "|/file.*\\.ext$|");
}
public function tempnam_collision_test() {