From 8b0088fd8d1774f4bdf5ae345ab5ad2da1eaedaf Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Feb 2013 13:23:05 -0500 Subject: Change gallery/bin -> gallery3/bin in the comment since I suspect most people don't change the name of the directory. Follow-on to 1d7f5e3ab117a6cce8f2a1d3de5e311b74dbee81 for #1935 --- modules/gallery/views/admin_movies.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/views/admin_movies.html.php b/modules/gallery/views/admin_movies.html.php index e7810711..242a4349 100644 --- a/modules/gallery/views/admin_movies.html.php +++ b/modules/gallery/views/admin_movies.html.php @@ -8,7 +8,7 @@

static build of FFmpeg from one of the links here.", array("url" => "http://ffmpeg.org/download.html")) ?> - +

-- cgit v1.2.3 From 7bdccade98e76df3a7830bc45bc42321a77c709a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Feb 2013 19:09:06 -0500 Subject: Every 500th request prune a single old file from var/tmp and var/logs. Might not be aggressive enough. Fixes #2005. --- modules/gallery/helpers/gallery_event.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 54c60296..eb54e521 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -36,6 +36,34 @@ class gallery_event_Core { locales::set_request_locale(); } + static function gallery_shutdown() { + // Every 500th request, do a pass over var/logs and var/tmp and delete old files. + // Limit ourselves to deleting a single file so that we don't spend too much CPU + // time on it. As long as servers call this at least twice a day they'll eventually + // wind up with a clean var/logs directory because we only create 1 file a day there. + // var/tmp might be stickier because theoretically we could wind up spamming that + // dir with a lot of files. But let's start with this and refine as we go. + if (!(rand() % 500)) { + // Note that this code is roughly duplicated in gallery_event::gallery_shutdown + $threshold = time() - 1209600; // older than 2 weeks + foreach(array("logs", "tmp") as $dir) { + $dir = VARPATH . $dir; + if ($dh = opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if ($file[0] == ".") { + continue; + } + + if (filemtime("$dir/$file") <= $threshold) { + unlink("$dir/$file"); + break; + } + } + } + } + } + } + static function user_deleted($user) { $admin = identity::admin_user(); if (!empty($admin)) { // could be empty if there is not identity provider -- cgit v1.2.3 From 0dd12caa6f4c0452167b0e621a01bee28e71b0af Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Feb 2013 19:12:08 -0500 Subject: Follow-on to 7bdccade98e76df3a7830bc45bc42321a77c709a - point out that there's duplicated code in gallery_event. --- modules/gallery/helpers/gallery_task.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 856d2639..37de2f93 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -281,6 +281,7 @@ class gallery_task_Core { switch ($task->get("mode", "init")) { case "init": $threshold = time() - 1209600; // older than 2 weeks + // Note that this code is roughly duplicated in gallery_event::gallery_shutdown foreach(array("logs", "tmp") as $dir) { $dir = VARPATH . $dir; if ($dh = opendir($dir)) { -- cgit v1.2.3 From 96ad7789c84b5b81320f9cb94b4c8cb4e10ad92f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Feb 2013 16:15:40 -0800 Subject: Follow-on to 7bdccade98e76df3a7830bc45bc42321a77c709a to exclude directories for now. --- modules/gallery/helpers/gallery_event.php | 5 +++++ modules/gallery/helpers/gallery_task.php | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index eb54e521..26432ef5 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -54,6 +54,11 @@ class gallery_event_Core { continue; } + // Ignore directories for now, but we should really address them in the long term. + if (is_dir("$dir/$file")) { + continue; + } + if (filemtime("$dir/$file") <= $threshold) { unlink("$dir/$file"); break; diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 37de2f93..a79cb2d5 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -290,6 +290,11 @@ class gallery_task_Core { continue; } + // Ignore directories for now, but we should really address them in the long term. + if (is_dir("$dir/$file")) { + continue; + } + if (filemtime("$dir/$file") <= $threshold) { $files[] = "$dir/$file"; } -- cgit v1.2.3