summaryrefslogtreecommitdiffstats
path: root/application/controllers/Main.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/controllers/Main.php')
-rw-r--r--application/controllers/Main.php98
1 files changed, 3 insertions, 95 deletions
diff --git a/application/controllers/Main.php b/application/controllers/Main.php
index 94d025678..c7bfb2f73 100644
--- a/application/controllers/Main.php
+++ b/application/controllers/Main.php
@@ -869,106 +869,14 @@ 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()
{
$this->_require_cli_request();
- $this->remove_files_missing_in_db();
- $this->remove_files_missing_on_disk();
- $this->clean_multipaste_tarballs();
- }
-
- private function remove_files_missing_in_db()
- {
- $upload_path = $this->config->item("upload_path");
- $outer_dh = opendir($upload_path);
-
- while (($dir = readdir($outer_dh)) !== false) {
- if (!is_dir($upload_path."/".$dir) || $dir == ".." || $dir == "." || $dir == "special") {
- continue;
- }
-
- $dh = opendir($upload_path."/".$dir);
-
- $empty = true;
-
- while (($file = readdir($dh)) !== false) {
- if ($file == ".." || $file == ".") {
- continue;
- }
-
- try {
- list($hash, $storage_id) = explode("-", $file);
- } catch (\ErrorException $e) {
- unlink($upload_path."/".$dir."/".$file);
- continue;
- }
-
- $query = $this->db->select('hash, id')
- ->from('file_storage')
- ->where('hash', $hash)
- ->where('id', $storage_id)
- ->limit(1)
- ->get()->row_array();
-
- if (empty($query)) {
- $this->mfile->delete_data_id($file);
- } else {
- $empty = false;
- }
- }
-
- closedir($dh);
-
- if ($empty && file_exists($upload_path."/".$dir)) {
- rmdir($upload_path."/".$dir);
- }
- }
- closedir($outer_dh);
- }
-
- private function remove_files_missing_on_disk()
- {
- $chunk = 500;
- $total = $this->db->count_all("file_storage");
-
- for ($limit = 0; $limit < $total; $limit += $chunk) {
- $query = $this->db->select('hash, id')
- ->from('file_storage')
- ->limit($chunk, $limit)
- ->get()->result_array();
-
- foreach ($query as $key => $item) {
- $data_id = $item["hash"].'-'.$item['id'];
- $file = $this->mfile->file($data_id);
-
- if (!$this->mfile->file_exists($file)) {
- $this->mfile->delete_data_id($data_id);
- }
- }
- }
+ \service\files::remove_files_missing_in_db();
+ \service\files::remove_files_missing_on_disk();
+ \service\files::clean_multipaste_tarballs();
}
function nuke_id()