Skip to content

Commit 747a0e0

Browse files
authored
Merge pull request #5 from ElementaryFramework/hotfix/lastmodtime-bug
Check if file exists before to get `lastmodtime`
2 parents c06190b + 9afd3ce commit 747a0e0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/FireFS/Watcher/FileSystemWatcher.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public function build(): self
273273
$this->_watchingDirectory = false;
274274

275275
$this->_lastModTimeCache = array();
276+
$this->_filesCache = array();
276277

277278
if ($this->_fs->isDir($this->_path)) {
278279
$this->_filesCache = $this->_fs->readDir($this->_path, $this->_recursive);
@@ -433,7 +434,11 @@ private function _watchFile(string $_path)
433434
private function _cacheLastModTimes()
434435
{
435436
foreach ($this->_filesCache as $name => $path) {
436-
$this->_lastModTimeCache[$path] = $this->_lmt($path);
437+
// If the file got deleted during from the listener,
438+
// or during the process but after scanning for changes.
439+
if ($this->_fs->exists($path)) {
440+
$this->_lastModTimeCache[$path] = $this->_lmt($path);
441+
}
437442
}
438443
}
439444

@@ -445,7 +450,7 @@ private function _lmt(string $path): int
445450
private function _addForWatch(string $path)
446451
{
447452
$p = $this->_fs->cleanPath($path);
448-
$this->_filesCache = array($path => $p);
453+
$this->_filesCache[$path] = $p;
449454
$this->_lastModTimeCache[$p] = $this->_lmt($p);
450455
}
451456

0 commit comments

Comments
 (0)