[icinga-checkins] icinga.org: icinga-web/master: * Removed FilesystemIterater (fixes #2005)

git at icinga.org git at icinga.org
Mon Nov 21 12:02:33 CET 2011


Module: icinga-web
Branch: master
Commit: 4f1623ebf9a54c6a9ceeaf88fbca3b36581544c6
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=4f1623ebf9a54c6a9ceeaf88fbca3b36581544c6

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Nov 21 12:01:36 2011 +0100

* Removed FilesystemIterater (fixes #2005)

---

 .../Reporting/models/ReportUserFileModel.class.php |   23 +++++++++++--------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/app/modules/Reporting/models/ReportUserFileModel.class.php b/app/modules/Reporting/models/ReportUserFileModel.class.php
index 796c23e..4c410ee 100644
--- a/app/modules/Reporting/models/ReportUserFileModel.class.php
+++ b/app/modules/Reporting/models/ReportUserFileModel.class.php
@@ -27,20 +27,23 @@ class Reporting_ReportUserFileModel extends ReportingBaseModel implements AgaviI
     private $__user = null;
 
     private function fileGarbageCollector() {
-        $it = new FilesystemIterator($this->__dir, FilesystemIterator::CURRENT_AS_FILEINFO);
+        
+        $this->getContext()->getLoggerManager()->log('REPORTING: Running garbage collector for user files.', AgaviLogger::DEBUG);
+        
         $count = 0;
-        foreach($it as $fileInfo) {
-            $diff = time() - $fileInfo->getCTime();
-
-            if ($diff > self::MAX_TIME) {
-                if (unlink($fileInfo->getRealPath())) {
-                    $count++;
-                } else {
-                    throw new AppKitModelException('Could not delete report user file: '. $fileInfo->getBaseName());
+        foreach (scandir($this->__dir) as $f) {
+            if ($f !== '.' && $f !== '..' && is_file(($file = $this->__dir . '/'. $f))) {
+                $diff = time() - filectime($file);
+                if ($diff > self::MAX_TIME) {
+                    if (unlink($file)) {
+                        $count++;
+                    } else {
+                        throw new AppKitModelException('Could not delete report user file: '. $file);
+                    }
                 }
             }
         }
-
+        
         if ($count>0) {
             $this->getContext()->getLoggerManager()->log('Deleted '. $count. ' reporting user files', AgaviLogger::INFO);
             return true;





More information about the icinga-checkins mailing list