Skip to content

Commit 0663dfc

Browse files
committed
fix: avoid duplicate enrty of changes when it checks deleted file
1 parent 8bcedac commit 0663dfc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Watcher.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,19 @@ protected function addChange(string $filename, ChangeType $type): void
3636
$this->changes[] = ['name' => $filename, 'type' => $type, 'data' => filemtime($filename)];
3737
}
3838

39-
protected function checkFile(string $file): void
39+
protected function checkFile(string $file, bool $checkForDelete = false): void
4040
{
41-
if (!array_key_exists($file, $this->files) && file_exists($file)) {
42-
$this->addChange($file, ChangeType::NEW);
41+
if (array_key_exists($file, $this->files) && !file_exists($file)) {
42+
$this->addChange($file, ChangeType::DELETED);
4343
return;
4444
}
4545

46-
if (array_key_exists($file, $this->files) && !file_exists($file)) {
47-
$this->addChange($file, ChangeType::DELETED);
46+
if ($checkForDelete) {
47+
return;
48+
}
49+
50+
if (!array_key_exists($file, $this->files) && file_exists($file)) {
51+
$this->addChange($file, ChangeType::NEW);
4852
return;
4953
}
5054

@@ -118,7 +122,7 @@ public function checkChanges(): void
118122

119123
// Checks the deleted files
120124
foreach ($this->files as $key => $file) {
121-
$this->checkFile($key);
125+
$this->checkFile($key, true);
122126
}
123127

124128
$this->commit();

0 commit comments

Comments
 (0)