From fd0051dab7258c817ff01877bd4324530ce79398 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Sun, 17 Feb 2013 23:19:35 +0100 Subject: #2006 - Add system::mark_file_for_delete API to delete files at shutdown. - added system::mark_file_for_delete to be called to mark a file - added system::delete_marked_files to be called at shutdown to delete the list - amended system::temp_filename to, by default, add the temp name to the list - updated a few other places in code where this should be used --- modules/gallery/helpers/system.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'modules/gallery/helpers/system.php') diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php index e1398103..7d56466e 100644 --- a/modules/gallery/helpers/system.php +++ b/modules/gallery/helpers/system.php @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class system_Core { + private static $files_marked_for_deletion = array(); + /** * Return the path to an executable version of the named binary, or null. * The paths are traversed in the following order: @@ -66,8 +68,10 @@ class system_Core { * 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. + * Unless specified with the $delete_later argument, it will be marked + * for deletion at shutdown using system::delete_later. */ - static function temp_filename($prefix="", $extension="") { + static function temp_filename($prefix="", $extension="", $delete_later=true) { do { $basename = tempnam(TMPPATH, $prefix); if (!$basename) { @@ -79,6 +83,30 @@ class system_Core { @unlink($basename); } } while (!$success); + + if ($delete_later) { + system::delete_later($filename); + } + return $filename; } -} \ No newline at end of file + + /** + * Mark a file for deletion at shutdown time. This is useful for temp files, where we can delay + * the deletion time until shutdown to keep page load time quick. + */ + static function delete_later($filename) { + self::$files_marked_for_deletion[] = $filename; + } + + /** + * Delete all files marked using system::delete_later. This is called at gallery shutdown. + */ + static function delete_marked_files() { + foreach (self::$files_marked_for_deletion as $filename) { + // We want to suppress all errors, as it's possible that some of these + // files may have been deleted/moved before we got here. + @unlink($filename); + } + } +} -- cgit v1.2.3 From de3f9edb88aaf0486485838de1b115f2d9ac87c9 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Sat, 9 Mar 2013 15:59:23 +0100 Subject: Follow-on to #1935 - Ensure ffmpeg is executable, remove possible doubled "/". - movie::find_ffmpeg - made it use is_executable instead of just file_exists. - system::find_binary - removed possible doubled "/" in paths. --- modules/gallery/helpers/movie.php | 3 ++- modules/gallery/helpers/system.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers/system.php') diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index aff2acc1..2f190881 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -138,7 +138,8 @@ class movie_Core { * Return the path to the ffmpeg binary if one exists and is executable, or null. */ static function find_ffmpeg() { - if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || !file_exists($ffmpeg_path)) { + if (!($ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) || + !@is_executable($ffmpeg_path)) { $ffmpeg_path = system::find_binary( "ffmpeg", module::get_var("gallery", "graphics_toolkit_path")); module::set_var("gallery", "ffmpeg_path", $ffmpeg_path); diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php index 7d56466e..f0879d6a 100644 --- a/modules/gallery/helpers/system.php +++ b/modules/gallery/helpers/system.php @@ -47,6 +47,7 @@ class system_Core { explode(":", module::get_var("gallery", "extra_binary_paths"))); foreach ($paths as $path) { + $path = rtrim($path, "/"); $candidate = "$path/$binary"; // @suppress errors below to avoid open_basedir issues if (@file_exists($candidate)) { -- cgit v1.2.3