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); | |||
307 | int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa); | 307 | int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa); |
308 | 308 | ||
309 | struct grecs_locus; | 309 | struct grecs_locus; |
310 | int filpatlist_add(filpatlist_t *fptr, char const *arg, struct grecs_locus *loc); | 310 | int filpatlist_add(filpatlist_t *fptr, char const *arg, |
311 | struct grecs_locus *loc); | ||
311 | void filpatlist_add_exact(filpatlist_t *fptr, char const *arg); | 312 | void filpatlist_add_exact(filpatlist_t *fptr, char const *arg); |
312 | void filpatlist_destroy(filpatlist_t *fptr); | 313 | void filpatlist_destroy(filpatlist_t *fptr); |
313 | int filpatlist_match(filpatlist_t fp, const char *name); | 314 | int filpatlist_match(filpatlist_t fp, const char *name); |
315 | int filpatlist_is_empty(filpatlist_t fp); | ||
314 | 316 | ||
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) | |||
137 | } | 137 | } |
138 | 138 | ||
139 | int | 139 | int |
140 | filpatlist_is_empty(filpatlist_t fp) | ||
141 | { | ||
142 | if (!fp) | ||
143 | return 1; | ||
144 | return grecs_list_size(fp->list) == 0; | ||
145 | } | ||
146 | |||
147 | int | ||
140 | filpatlist_match(filpatlist_t fp, const char *name) | 148 | filpatlist_match(filpatlist_t fp, const char *name) |
141 | { | 149 | { |
142 | struct grecs_list_entry *ep; | 150 | 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) | |||
203 | char *new_dirname; | 203 | char *new_dirname; |
204 | struct handler *hp; | 204 | struct handler *hp; |
205 | handler_iterator_t itr; | 205 | handler_iterator_t itr; |
206 | 206 | ||
207 | filename = split_pathname(wpt, &dirname); | ||
208 | |||
207 | for_each_handler(wpt, itr, hp) { | 209 | for_each_handler(wpt, itr, hp) { |
208 | if (hp->fnames) { | 210 | if (!filpatlist_is_empty(hp->fnames) |
209 | /* FIXME: Error message */ | 211 | && filpatlist_match(hp->fnames, filename) == 0) { |
212 | unsplit_pathname(wpt); | ||
213 | diag(LOG_ERR, | ||
214 | _("can't convert file watcher %s to directory watcher"), | ||
215 | wpt->dirname); | ||
210 | return 1; | 216 | return 1; |
211 | } | 217 | } |
212 | } | 218 | } |
213 | 219 | ||
214 | filename = split_pathname(wpt, &dirname); | ||
215 | for_each_handler(wpt, itr, hp) | 220 | for_each_handler(wpt, itr, hp) |
216 | filpatlist_add_exact(&hp->fnames, filename); | 221 | filpatlist_add_exact(&hp->fnames, filename); |
217 | 222 | ||
218 | new_dirname = estrdup(dirname); | 223 | new_dirname = estrdup(dirname); |
219 | unsplit_pathname(wpt); | 224 | unsplit_pathname(wpt); |
220 | diag(LOG_NOTICE, _("watcher %s converted to %s"), | 225 | diag(LOG_NOTICE, |
226 | _("file watcher %s converted to directory watcher %s"), | ||
221 | wpt->dirname, new_dirname); | 227 | wpt->dirname, new_dirname); |
222 | 228 | ||
223 | free(wpt->dirname); | 229 | free(wpt->dirname); |
@@ -302,7 +308,6 @@ watchpoint_init(struct watchpoint *wpt) | |||
302 | return 1; | 308 | return 1; |
303 | } | 309 | } |
304 | } else if (!S_ISDIR(st.st_mode)) { | 310 | } else if (!S_ISDIR(st.st_mode)) { |
305 | diag(LOG_NOTICE, _("%s is a regular file"), wpt->dirname); | ||
306 | convert_watcher(wpt); | 311 | convert_watcher(wpt); |
307 | } | 312 | } |
308 | 313 | ||
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 | |||
41 | TESTSUITE_AT = \ | 41 | TESTSUITE_AT = \ |
42 | attrib.at\ | 42 | attrib.at\ |
43 | cmdexp.at\ | 43 | cmdexp.at\ |
44 | conv.at\ | ||
44 | create.at\ | 45 | create.at\ |
45 | createrec.at\ | 46 | createrec.at\ |
46 | delete.at\ | 47 | delete.at\ |
@@ -57,6 +58,7 @@ TESTSUITE_AT = \ | |||
57 | re05.at\ | 58 | re05.at\ |
58 | samepath.at\ | 59 | samepath.at\ |
59 | shell.at\ | 60 | shell.at\ |
61 | sent.at\ | ||
60 | testsuite.at\ | 62 | testsuite.at\ |
61 | write.at | 63 | write.at |
62 | 64 | ||
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 @@ | |||
1 | # This file is part of Direvent testsuite. -*- Autotest -*- | ||
2 | # Copyright (C) 2013-2016 Sergey Poznyakoff | ||
3 | # | ||
4 | # Direvent is free software; you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation; either version 3, or (at your option) | ||
7 | # any later version. | ||
8 | # | ||
9 | # Direvent is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with Direvent. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | AT_SETUP([File watcher]) | ||
18 | AT_KEYWORDS([special conv convert file]) | ||
19 | |||
20 | AT_DIREVENT_TEST_UNQUOTED([ | ||
21 | debug 10; | ||
22 | syslog { | ||
23 | facility ${TESTSUITE_FACILITY:-local0}; | ||
24 | tag direvent-test:create; | ||
25 | } | ||
26 | watcher { | ||
27 | path $cwd/file; | ||
28 | event (create,write,delete); | ||
29 | option (stdout,stderr); | ||
30 | command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; | ||
31 | } | ||
32 | ], | ||
33 | [echo "foo" > file | ||
34 | ], | ||
35 | [outfile=$cwd/dump | ||
36 | echo "file" > file | ||
37 | ], | ||
38 | [sed '/^argv\[[[0-9]]\]=-k/d' $outfile | ||
39 | ], | ||
40 | [0], | ||
41 | [# Dump of execution environment | ||
42 | cwd is $cwd | ||
43 | # Arguments | ||
44 | argv[[0]]=$TESTDIR/envdump | ||
45 | argv[[1]]=-s | ||
46 | argv[[2]]=-i | ||
47 | argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_ | ||
48 | argv[[4]]=-f | ||
49 | argv[[5]]=$cwd/dump | ||
50 | # Environment | ||
51 | DIREVENT_FILE=file | ||
52 | DIREVENT_GENEV_CODE=2 | ||
53 | DIREVENT_GENEV_NAME=write | ||
54 | # End | ||
55 | ], | ||
56 | [direvent: [[NOTICE]] file watcher $cwd/file converted to directory watcher $cwd | ||
57 | ]) | ||
58 | |||
59 | AT_CLEANUP | ||
60 | |||
61 | |||
62 | |||
63 | |||
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 @@ | |||
1 | # This file is part of Direvent testsuite. -*- Autotest -*- | ||
2 | # Copyright (C) 2013-2016 Sergey Poznyakoff | ||
3 | # | ||
4 | # Direvent is free software; you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation; either version 3, or (at your option) | ||
7 | # any later version. | ||
8 | # | ||
9 | # Direvent is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with Direvent. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | AT_SETUP([Sentinel]) | ||
18 | AT_KEYWORDS([special sent sentinel]) | ||
19 | |||
20 | AT_DIREVENT_TEST_UNQUOTED([ | ||
21 | debug 10; | ||
22 | syslog { | ||
23 | facility ${TESTSUITE_FACILITY:-local0}; | ||
24 | tag direvent-test:create; | ||
25 | } | ||
26 | watcher { | ||
27 | path $cwd/dir/sub; | ||
28 | file "foo"; | ||
29 | event (create); | ||
30 | option (stdout,stderr); | ||
31 | command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -a -f $outfile -k\$self_test_pid"; | ||
32 | } | ||
33 | ], | ||
34 | [mkdir $cwd/dir | ||
35 | mkdir $cwd/dir/sub | ||
36 | echo "bar" > $cwd/dir/sub/bar | ||
37 | echo "foo" > $cwd/dir/sub/foo | ||
38 | ], | ||
39 | [outfile=$cwd/dump | ||
40 | ], | ||
41 | [sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile | ||
42 | ], | ||
43 | [0], | ||
44 | [# Dump of execution environment | ||
45 | cwd is (CWD)/dir/sub | ||
46 | # Arguments | ||
47 | argv[[0]]=(TESTDIR)/envdump | ||
48 | argv[[1]]=-s | ||
49 | argv[[2]]=-i | ||
50 | argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_ | ||
51 | argv[[4]]=-a | ||
52 | argv[[5]]=-f | ||
53 | argv[[6]]=(CWD)/dump | ||
54 | # Environment | ||
55 | DIREVENT_FILE=foo | ||
56 | DIREVENT_GENEV_CODE=1 | ||
57 | DIREVENT_GENEV_NAME=create | ||
58 | # End | ||
59 | ], | ||
60 | [direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir/sub | ||
61 | direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir | ||
62 | ]) | ||