From 241aa92cc5db32b7d4125e47b04bb67466ef6150 Mon Sep 17 00:00:00 2001 From: everzet Date: Wed, 20 Jun 2012 10:19:09 +0200 Subject: [PATCH] [Config] added existence check to some resource methods * fixed DELETED event when starting to watch a file that does not exist yet * fixed files that are deleted and then re-created Conflicts: src/Symfony/Component/ResourceWatcher/StateChecker/ResourceStateChecker.php tests/Symfony/Tests/Component/ResourceWatcher/StateChecker/DirectoryStateCheckerTest.php tests/Symfony/Tests/Component/ResourceWatcher/StateChecker/FileStateCheckerTest.php --- .../Component/Config/Resource/DirectoryResource.php | 8 ++++++++ src/Symfony/Component/Config/Resource/FileResource.php | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Resource/DirectoryResource.php b/src/Symfony/Component/Config/Resource/DirectoryResource.php index 13ef5d10da..474fbb3078 100644 --- a/src/Symfony/Component/Config/Resource/DirectoryResource.php +++ b/src/Symfony/Component/Config/Resource/DirectoryResource.php @@ -75,6 +75,10 @@ class DirectoryResource implements ResourceInterface */ public function getFilteredResources() { + if (!$this->exists()) { + return array(); + } + $iterator = new \DirectoryIterator($this->resource); $resources = array(); @@ -166,6 +170,10 @@ class DirectoryResource implements ResourceInterface */ public function getModificationTime() { + if (!$this->exists()) { + return -1; + } + clearstatcache(true, $this->resource); $newestMTime = filemtime($this->resource); diff --git a/src/Symfony/Component/Config/Resource/FileResource.php b/src/Symfony/Component/Config/Resource/FileResource.php index 07564a3470..259db3c75d 100644 --- a/src/Symfony/Component/Config/Resource/FileResource.php +++ b/src/Symfony/Component/Config/Resource/FileResource.php @@ -29,7 +29,7 @@ class FileResource implements ResourceInterface */ public function __construct($resource) { - $this->resource = realpath($resource); + $this->resource = file_exists($resource) ? realpath($resource) : $resource; } /** @@ -59,6 +59,10 @@ class FileResource implements ResourceInterface */ public function getModificationTime() { + if (!$this->exists()) { + return -1; + } + clearstatcache(true, $this->resource); return filemtime($this->resource);