From 8df64d85859653e5fb26a78f0cdd23d47e6cbd3f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 14 Apr 2012 22:38:45 +0200 Subject: cron: Remove expired, unowned files Unowned files expire whenever a session expires because the user won't be able to reclaim them anymore. Signed-off-by: Florian Pritz --- application/controllers/file.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'application') diff --git a/application/controllers/file.php b/application/controllers/file.php index 152e6a011..7d165c02e 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -334,10 +334,16 @@ class File extends CI_Controller { if ($this->config->item('upload_max_age') == 0) return; - $oldest_time = (time()-$this->config->item('upload_max_age')); + $oldest_time = (time() - $this->config->item('upload_max_age')); + $oldest_session_time = (time() - $this->config->item("sess_expiration")); + $small_upload_size = $this->config->item('small_upload_size'); - $query = $this->db->query('SELECT hash, id FROM files WHERE date < ?', - array($oldest_time)); + + $query = $this->db->query(' + SELECT hash, id, user + FROM files + WHERE date < ? OR (user = 0 AND date < ?)', + array($oldest_time, $oldest_session_time)); foreach($query->result_array() as $row) { $file = $this->file_mod->file($row['hash']); @@ -346,7 +352,7 @@ class File extends CI_Controller { continue; } - if (filesize($file) > $small_upload_size) { + if ($row["user"] == 0 || filesize($file) > $small_upload_size) { if (filemtime($file) < $oldest_time) { unlink($file); $this->db->query('DELETE FROM files WHERE hash = ?', array($row['hash'])); -- cgit v1.2.3-24-g4f1b