Skip to content

ResourceWatcher misses some inotify events #3

@ju1ius

Description

@ju1ius

Steps to reproduce:

Setup test directory

cd /some/dir
composer.phar init
composer.phar require henrikbjorn/lurker dev-master
mkdir -p test/foo
touch test/foo/{bar,baz}.txt
vim test.php

Setup test script

// test.php
require_once __DIR__.'/vendor/autoload.php';
use Lurker\Event\FilesystemEvent;
use Lurker\ResourceWatcher;

$watcher = new ResourceWatcher();
$watcher->track('test.foo', __DIR__.'/test/foo');
$watcher->addListener('test.foo', function(FilesystemEvent $event) {
    echo $event->getTypeString() . ' >>> ' . $event->getResource() .PHP_EOL;
});
$watcher->start();

Open two terminals, t1 & t2

t1 $ php test.php
t2 $ echo "something" > test/foo/bar.txt
t1 > modify >>> [..]/test/foo/bar.txt
t2 $ mv test/foo/bar.txt test/
t1 > delete >> [..]/test/foo/bar.txt
t2 $ mv test/bar.txt test/foo/
t1 > ... # nothing !
t2 $ rm test/foo/bar.txt
t1 > ... # nothing !
t2 $ touch test/foo/bar.txt
t1 > create >> [..]/test/foo/bar.txt

Same session with inotifywait

t1 $ inotifywait -rm test/foo
t2 $ echo "something" > test/foo/bar.txt
t1 > test/foo/ MODIFY bar.txt
   > test/foo/ OPEN bar.txt
   > test/foo/ MODIFY bar.txt
   > test/foo/ CLOSE_WRITE,CLOSE bar.txt
t2 $ mv test/foo/bar.txt test/
t1 > test/foo/ MOVED_FROM bar.txt
t2 $ mv test/bar.txt test/foo/
t1 > test/foo/ MOVED_TO bar.txt
t2 $ rm test/foo/bar.txt
t1 > test/foo/ DELETE bar.txt
t2 $ touch test/foo/bar.txt
t1 > test/foo/ CREATE bar.txt
   > test/foo/ OPEN bar.txt
   > test/foo/ ATTRIB bar.txt
   > test/foo/ CLOSE_WRITE,CLOSE bar.txt

Conclusion

It seems Lurker is missing two events here. IN_MOVED_FROM (FilesystemEvent::DELETE) and IN_MOVED_TO (FilesystemEvent::CREATE).
Tested with pecl-inotify 0.1.6

$ php -i | grep inotify -A 2
> inotify
>
> Version => 0.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions