diff options
-rw-r--r-- | src/direvent.h | 4 | ||||
-rw-r--r-- | src/fnpat.c | 8 | ||||
-rw-r--r-- | src/watcher.c | 17 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/conv.at | 63 | ||||
-rw-r--r-- | tests/sent.at | 65 | ||||
-rw-r--r-- | tests/testsuite.at | 25 |
7 files changed, 168 insertions, 16 deletions
diff --git a/src/direvent.h b/src/direvent.h index d69fa34..416d833 100644 --- a/src/direvent.h +++ b/src/direvent.h @@ -307,8 +307,10 @@ int sigv_set_tab(int sigc, struct sigtab *sigtab, struct sigaction *retsa); int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa); struct grecs_locus; -int filpatlist_add(filpatlist_t *fptr, char const *arg, struct grecs_locus *loc); +int filpatlist_add(filpatlist_t *fptr, char const *arg, + struct grecs_locus *loc); void filpatlist_add_exact(filpatlist_t *fptr, char const *arg); void filpatlist_destroy(filpatlist_t *fptr); int filpatlist_match(filpatlist_t fp, const char *name); +int filpatlist_is_empty(filpatlist_t fp); diff --git a/src/fnpat.c b/src/fnpat.c index 5a98053..3e282b3 100644 --- a/src/fnpat.c +++ b/src/fnpat.c @@ -137,6 +137,14 @@ filpatlist_destroy(filpatlist_t *fptr) } int +filpatlist_is_empty(filpatlist_t fp) +{ + if (!fp) + return 1; + return grecs_list_size(fp->list) == 0; +} + +int filpatlist_match(filpatlist_t fp, const char *name) { struct grecs_list_entry *ep; diff --git a/src/watcher.c b/src/watcher.c index 7ac3d86..9b6c633 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -203,21 +203,27 @@ convert_watcher(struct watchpoint *wpt) char *new_dirname; struct handler *hp; handler_iterator_t itr; - + + filename = split_pathname(wpt, &dirname); + for_each_handler(wpt, itr, hp) { - if (hp->fnames) { - /* FIXME: Error message */ + if (!filpatlist_is_empty(hp->fnames) + && filpatlist_match(hp->fnames, filename) == 0) { + unsplit_pathname(wpt); + diag(LOG_ERR, + _("can't convert file watcher %s to directory watcher"), + wpt->dirname); return 1; } } - filename = split_pathname(wpt, &dirname); for_each_handler(wpt, itr, hp) filpatlist_add_exact(&hp->fnames, filename); new_dirname = estrdup(dirname); unsplit_pathname(wpt); - diag(LOG_NOTICE, _("watcher %s converted to %s"), + diag(LOG_NOTICE, + _("file watcher %s converted to directory watcher %s"), wpt->dirname, new_dirname); free(wpt->dirname); @@ -302,7 +308,6 @@ watchpoint_init(struct watchpoint *wpt) return 1; } } else if (!S_ISDIR(st.st_mode)) { - diag(LOG_NOTICE, _("%s is a regular file"), wpt->dirname); convert_watcher(wpt); } diff --git a/tests/Makefile.am b/tests/Makefile.am index f797790..4b70e75 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,6 +41,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac TESTSUITE_AT = \ attrib.at\ cmdexp.at\ + conv.at\ create.at\ createrec.at\ delete.at\ @@ -57,6 +58,7 @@ TESTSUITE_AT = \ re05.at\ samepath.at\ shell.at\ + sent.at\ testsuite.at\ write.at diff --git a/tests/conv.at b/tests/conv.at new file mode 100644 index 0000000..d46f7f6 --- /dev/null +++ b/tests/conv.at @@ -0,0 +1,63 @@ +# This file is part of Direvent testsuite. -*- Autotest -*- +# Copyright (C) 2013-2016 Sergey Poznyakoff +# +# Direvent is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# Direvent is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Direvent. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([File watcher]) +AT_KEYWORDS([special conv convert file]) + +AT_DIREVENT_TEST_UNQUOTED([ +debug 10; +syslog { + facility ${TESTSUITE_FACILITY:-local0}; + tag direvent-test:create; +} +watcher { + path $cwd/file; + event (create,write,delete); + option (stdout,stderr); + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; +} +], +[echo "foo" > file +], +[outfile=$cwd/dump +echo "file" > file +], +[sed '/^argv\[[[0-9]]\]=-k/d' $outfile +], +[0], +[# Dump of execution environment +cwd is $cwd +# Arguments +argv[[0]]=$TESTDIR/envdump +argv[[1]]=-s +argv[[2]]=-i +argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_ +argv[[4]]=-f +argv[[5]]=$cwd/dump +# Environment +DIREVENT_FILE=file +DIREVENT_GENEV_CODE=2 +DIREVENT_GENEV_NAME=write +# End +], +[direvent: [[NOTICE]] file watcher $cwd/file converted to directory watcher $cwd +]) + +AT_CLEANUP + + + + diff --git a/tests/sent.at b/tests/sent.at new file mode 100644 index 0000000..1d8e152 --- /dev/null +++ b/tests/sent.at @@ -0,0 +1,65 @@ +# This file is part of Direvent testsuite. -*- Autotest -*- +# Copyright (C) 2013-2016 Sergey Poznyakoff +# +# Direvent is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# Direvent is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Direvent. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([Sentinel]) +AT_KEYWORDS([special sent sentinel]) + +AT_DIREVENT_TEST_UNQUOTED([ +debug 10; +syslog { + facility ${TESTSUITE_FACILITY:-local0}; + tag direvent-test:create; +} +watcher { + path $cwd/dir/sub; + file "foo"; + event (create); + option (stdout,stderr); + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -a -f $outfile -k\$self_test_pid"; +} +], +[mkdir $cwd/dir +mkdir $cwd/dir/sub +echo "bar" > $cwd/dir/sub/bar +echo "foo" > $cwd/dir/sub/foo +], +[outfile=$cwd/dump +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile +], +[0], +[# Dump of execution environment +cwd is (CWD)/dir/sub +# Arguments +argv[[0]]=(TESTDIR)/envdump +argv[[1]]=-s +argv[[2]]=-i +argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_ +argv[[4]]=-a +argv[[5]]=-f +argv[[6]]=(CWD)/dump +# Environment +DIREVENT_FILE=foo +DIREVENT_GENEV_CODE=1 +DIREVENT_GENEV_NAME=create +# End +], +[direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir/sub +direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir +]) + +AT_CLEANUP + diff --git a/tests/testsuite.at b/tests/testsuite.at index cbe9906..09538b5 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -18,28 +18,32 @@ m4_version_prereq([2.52g]) m4_define([AT_SKIP_TEST],[exit 77]) -dnl AT_DIREVENT_TEST([CONFIG],[SELFTEST],[PROLOGUE],[EPILOGUE],[CODE],[STDOUT], +dnl m4_direvent_test([MOD], +dnl [CONFIG],[SELFTEST],[PROLOGUE],[EPILOGUE],[CODE],[STDOUT], dnl [STDERR]) -m4_define([AT_DIREVENT_TEST],[ -AT_CHECK([ +m4_define([m4_direvent_test],[ cwd=`pwd -P` -$3 +AT_CHECK$1([ +$4 cat > test.conf <<EOT -[$1] +[$2] EOT cat > selftest.sh <<EOT #!/bin/sh -[$2] +[$3] sleep 10 exit 21 EOT chmod +x selftest.sh direvent -lnotice -f --self-test $cwd/selftest.sh test.conf || exit $? -$4 +$5 ], -[$5], [$6], -[$7])]) +[$7], +[$8])]) + +m4_define([AT_DIREVENT_TEST],[m4_direvent_test([],$@)]) +m4_define([AT_DIREVENT_TEST_UNQUOTED],[m4_direvent_test([_UNQUOTED], $@)]) AT_INIT AT_TESTED([direvent]) @@ -68,3 +72,6 @@ m4_include([re03.at]) m4_include([re04.at]) m4_include([re05.at]) +AT_BANNER([Special watchpoints]) +m4_include([conv.at]) +m4_include([sent.at]) |