diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-06-01 10:14:15 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-06-01 10:14:15 +0300 |
commit | 89033528634fc77d74983cf717e7ec93bfd6ac4c (patch) | |
tree | 1d95cc1628acd2f0a55599362c3592bdf5f4463c | |
parent | b2ad99bd755d872c863482d66744f1f6cbbcd00b (diff) | |
download | direvent-89033528634fc77d74983cf717e7ec93bfd6ac4c.tar.gz direvent-89033528634fc77d74983cf717e7ec93bfd6ac4c.tar.bz2 |
Fix CREATE detection with kqueue.
* src/ev_kqueue.c (check_created): Fall back to hash lookup
to see if the file is recently created.
* tests/create.at: Remove the sleep. Wait for the pidfile to
appear before proceding with the test.
* tests/delete.at: Wait for the pidfile to appear before
proceding with the test.
* tests/remove.at: Likewise.
* tests/write.at: Likewise.
-rw-r--r-- | src/ev_kqueue.c | 10 | ||||
-rw-r--r-- | tests/create.at | 4 | ||||
-rw-r--r-- | tests/delete.at | 1 | ||||
-rw-r--r-- | tests/remove.at | 1 | ||||
-rw-r--r-- | tests/write.at | 6 |
5 files changed, 16 insertions, 6 deletions
diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c index 99ec822..101ed9f 100644 --- a/src/ev_kqueue.c +++ b/src/ev_kqueue.c @@ -159,7 +159,15 @@ check_created(struct dirwatcher *dp) if (stat(pathname, &st)) { diag(LOG_ERR, "cannot stat %s: %s", pathname, strerror(errno)); - } else if (st.st_ctime > dp->file_ctime) { + /* If ok, first see if the file is newer than the last + directory scan. If not, there is still a chance + the file is new (the timestamp precision leaves a + time window long enough for a file to be created) + so try the more expensive hash lookup to see if we + know about that file. If the file is new, register + a watcher for it. */ + } else if (st.st_ctime > dp->file_ctime || + !dirwatcher_lookup(pathname)) { event_mask m = { SIE_CREATE, 0 }; watch_pathname(dp, pathname, S_ISDIR(st.st_mode)); diff --git a/tests/create.at b/tests/create.at index 388a581..ace1af1 100644 --- a/tests/create.at +++ b/tests/create.at @@ -38,9 +38,7 @@ watcher { EOT dircond -lnotice test.conf || exit 1 -# Need to wait a second because on BSD the create event is detected with -# a 1-second resolution. This needs to be fixed in ev_kqueue.c -sleep 1 +waitfile $pidfile 2 > dir/file waitfile $outfile 6 kill `cat $pidfile` diff --git a/tests/delete.at b/tests/delete.at index 704b4e3..971708d 100644 --- a/tests/delete.at +++ b/tests/delete.at @@ -39,6 +39,7 @@ EOT > dir/file dircond -lnotice test.conf || exit 1 +waitfile $pidfile 2 rm dir/file waitfile $outfile 6 || exit 2 kill `cat $pidfile` diff --git a/tests/remove.at b/tests/remove.at index ba6d6ca..aaf6cb0 100644 --- a/tests/remove.at +++ b/tests/remove.at @@ -38,6 +38,7 @@ watcher { EOT dircond -lnotice test.conf || exit 1 +waitfile $pidfile 2 > dir/file waitfile $outfile 6 || exit 2 kill `cat $pidfile` diff --git a/tests/write.at b/tests/write.at index f2722e9..bce98da 100644 --- a/tests/write.at +++ b/tests/write.at @@ -44,11 +44,13 @@ men EOT dircond -lnotice test.conf || exit 1 -sleep 1 +waitfile $pidfile 2 echo "to come to" >> dir/file -waitfile $outfile 6 || exit 2 +waitfile $outfile 6 +res=$? kill `cat $pidfile` +test $? -ne 0 && exit 1 sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile ], [0], |