return false early from directory resource

This commit is contained in:
Rob Frawley 2nd 2017-01-29 16:51:59 -05:00
parent f7ba71db7c
commit 96107e21f1
No known key found for this signature in database
GPG Key ID: 0EC41426CA2BA4E4

View File

@ -68,7 +68,10 @@ class DirectoryResource implements ResourceInterface, \Serializable
return false;
}
$newestMTime = filemtime($this->resource);
if ($timestamp <= filemtime($this->resource)) {
return false;
}
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
// if regex filtering is enabled only check matching files
if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
@ -81,10 +84,13 @@ class DirectoryResource implements ResourceInterface, \Serializable
continue;
}
$newestMTime = max($file->getMTime(), $newestMTime);
// early return if a file's mtime exceeds the passed timestamp
if ($timestamp <= $file->getMTime()) {
return false;
}
}
return $newestMTime < $timestamp;
return true;
}
public function serialize()