diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-05-03 20:03:35 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-05-03 20:03:35 +0200 |
commit | c12318a99e9ba44a6774f72f647c7a3c41ee24e4 (patch) | |
tree | 1239e81dc1517fd45d17bb293222a8f01d45104f | |
parent | 9635db3ec764a52ee49b1276ecb0f5cf4fcfbcf2 (diff) |
file/cron: Refactor multipaste tarball clean code into new method
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/Main.php | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/application/controllers/Main.php b/application/controllers/Main.php index f48596b56..6389b1039 100644 --- a/application/controllers/Main.php +++ b/application/controllers/Main.php @@ -832,23 +832,7 @@ class Main extends MY_Controller { { $this->_require_cli_request(); - $tarball_dir = $this->config->item("upload_path")."/special/multipaste-tarballs"; - if (is_dir($tarball_dir)) { - $tarball_cache_time = $this->config->item("tarball_cache_time"); - $it = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($tarball_dir), RecursiveIteratorIterator::SELF_FIRST); - - foreach ($it as $file) { - if ($file->isFile()) { - if ($file->getMTime() < time() - $tarball_cache_time) { - $lock = fopen($file, "r+"); - flock($lock, LOCK_EX); - unlink($file); - flock($lock, LOCK_UN); - } - } - } - } + $this->clean_multipaste_tarballs(); $oldest_time = (time() - $this->config->item('upload_max_age')); $oldest_session_time = (time() - $this->config->item("sess_expiration")); @@ -885,6 +869,27 @@ class Main extends MY_Controller { } } + private function clean_multipaste_tarballs() + { + $tarball_dir = $this->config->item("upload_path")."/special/multipaste-tarballs"; + if (is_dir($tarball_dir)) { + $tarball_cache_time = $this->config->item("tarball_cache_time"); + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($tarball_dir), RecursiveIteratorIterator::SELF_FIRST); + + foreach ($it as $file) { + if ($file->isFile()) { + if ($file->getMTime() < time() - $tarball_cache_time) { + $lock = fopen($file, "r+"); + flock($lock, LOCK_EX); + unlink($file); + flock($lock, LOCK_UN); + } + } + } + } + } + /* remove files without database entries */ function clean_stale_files() { |