You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The logic behind change detection is flawed.
It becomes an issue if both file deletion and creation happens between two 'findChanges' call.
(Theoretically it can be prevented by polling for changes fast enough, but I can't rely on it, since many file operations can happen even in a few milliseconds, and polling can be expensive.)
if (count($finderFileHashes) > count($cacheFileHashes)) {
foreach ($finderFileHashesas$file => $hash) {
$this->processFileFromFilesystem($file, $hash);
}
} else {
foreach ($cacheFileHashesas$file => $hash) {
$this->processFileFromCache($file, $hash);
}
}
Based just on the file count, it is not possible to detect all 3 cases (addition, deletion, updates) at once. The code should compare differences from the perspective of both of them. - Cache compared to actual files - Actual files compared to cache
The library wrongly assumes that if:
"Current count of files" > "file count in cache", then only these two could have happened:
Any/some file was updated
New file has been added
AND IF
"Current count of files" <= "file count in cache", then only these two could have happened:
The text was updated successfully, but these errors were encountered:
Hiroko103
changed the title
[Bug] Faulty detection logics if both file creation and deletion happens at the same time
[Bug] Faulty detection logic if both file creation and deletion happens between detection calls
Sep 29, 2023
Hi!
The logic behind change detection is flawed.
It becomes an issue if both file deletion and creation happens between two 'findChanges' call.
(Theoretically it can be prevented by polling for changes fast enough, but I can't rely on it, since many file operations can happen even in a few milliseconds, and polling can be expensive.)
Problematic source part:
resource-watcher/src/ResourceWatcher.php
Lines 135 to 143 in fda1c53
Based just on the file count, it is not possible to detect all 3 cases (addition, deletion, updates) at once.
The code should compare differences from the perspective of both of them.
- Cache compared to actual files
- Actual files compared to cache
The library wrongly assumes that if:
"Current count of files" > "file count in cache", then only these two could have happened:
AND IF
"Current count of files" <= "file count in cache", then only these two could have happened:
Examples:
In this case, the library will report that 'c.txt' has been deleted, but won't report that 'd.txt' have been added.
Another similar example:
Now the library will report that 'd.txt' and 'e.txt' have been added, but won't report that 'c.txt' have been deleted.
I'm attaching a test script with the example scenario.
index.zip
The text was updated successfully, but these errors were encountered: