]> git.wh0rd.org Git - tt-rss.git/commitdiff
add built-in expiring of obsolete lockfiles
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 12 Dec 2012 05:46:02 +0000 (09:46 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 12 Dec 2012 05:46:02 +0000 (09:46 +0400)
include/rssfuncs.php

index b5949d720dc82cb860d310df5fd8bc9074d1a650..1b39efec1010f79a5dabefc9f0b0c743fc8436cf 100644 (file)
                }
 
                expire_cached_files($debug);
+               expire_lock_files($debug);
 
                // For each feed, we call the feed update function.
                while ($line = array_pop($feeds_to_update)) {
                return $doc->saveXML($node, LIBXML_NOEMPTYTAG);
        }
 
+       function expire_lock_files($debug) {
+               if ($debug) _debug("Removing old lock files...");
+
+               $num_deleted = 0;
+
+               if (is_writable(LOCK_DIRECTORY)) {
+                       $files = glob(LOCK_DIRECTORY . "/*.lock");
+
+                       if ($files) {
+                               foreach ($files as $file) {
+                                       if (!file_is_locked($file) && time() - filemtime($file) > 86400*2) {
+                                               unlink($file);
+                                               ++$num_deleted;
+                                       }
+                               }
+                       }
+               }
+
+               if ($debug) _debug("Removed $num_deleted files.");
+       }
+
        function expire_cached_files($debug) {
                foreach (array("magpie", "simplepie", "images", "export") as $dir) {
                        $cache_dir = CACHE_DIR . "/$dir";
                        if (is_writable($cache_dir)) {
                                $files = glob("$cache_dir/*");
 
-                               if ($files)
+                               if ($files) {
                                        foreach ($files as $file) {
                                                if (time() - filemtime($file) > 86400*7) {
                                                        unlink($file);
                                                }
                                        }
                                }
+                       }
 
                        if ($debug) _debug("Removed $num_deleted files.");
                }