Skip to content

Commit

Permalink
Merge pull request #5 from ElementaryFramework/hotfix/lastmodtime-bug
Browse files Browse the repository at this point in the history
Check if file exists before to get `lastmodtime`
  • Loading branch information
na2axl authored Aug 11, 2021
2 parents c06190b + 9afd3ce commit 747a0e0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/FireFS/Watcher/FileSystemWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public function build(): self
$this->_watchingDirectory = false;

$this->_lastModTimeCache = array();
$this->_filesCache = array();

if ($this->_fs->isDir($this->_path)) {
$this->_filesCache = $this->_fs->readDir($this->_path, $this->_recursive);
Expand Down Expand Up @@ -433,7 +434,11 @@ private function _watchFile(string $_path)
private function _cacheLastModTimes()
{
foreach ($this->_filesCache as $name => $path) {
$this->_lastModTimeCache[$path] = $this->_lmt($path);
// If the file got deleted during from the listener,
// or during the process but after scanning for changes.
if ($this->_fs->exists($path)) {
$this->_lastModTimeCache[$path] = $this->_lmt($path);
}
}
}

Expand All @@ -445,7 +450,7 @@ private function _lmt(string $path): int
private function _addForWatch(string $path)
{
$p = $this->_fs->cleanPath($path);
$this->_filesCache = array($path => $p);
$this->_filesCache[$path] = $p;
$this->_lastModTimeCache[$p] = $this->_lmt($p);
}

Expand Down

0 comments on commit 747a0e0

Please sign in to comment.