git ssb

0+

cel / foostudio



Commit 5786b0b025e423f956afb157f1478abd951ddb2a

Handle source file replaced instead of just modified

cel committed on 10/24/2016, 11:00:29 PM
Parent: fd156cd03b6fce3c933ce1edb725e8e6e74e7be4

Files changed

ccdl.cchanged
ccdl.cView
@@ -120,17 +120,19 @@
120120
121121 static int ccdl_watch_run(struct ccdl *ccdl)
122122 {
123123 int ifd = inotify_init();
124 + int wd = 0;
124125 if (ifd < 0) {
125126 warn("inotify_init");
126127 return -1;
127128 }
128129 if (!ccdl || !ccdl->lib || !ccdl->lib->src_fname) {
129130 warn("missing lib filename");
130131 return -1;
131132 }
132- if (inotify_add_watch(ifd, ccdl->lib->src_fname, IN_MODIFY) < 0) {
133 + wd = inotify_add_watch(ifd, ccdl->lib->src_fname, IN_MODIFY);
134 + if (wd < 0) {
133135 warn("watch");
134136 return -1;
135137 }
136138
@@ -149,13 +151,22 @@
149151 if (ev.len > 0) {
150152 warn("unexpected name");
151153 return -1;
152154 }
153- if (!(ev.mask & IN_MODIFY)) {
155 + if (ev.mask & IN_MODIFY) {
156 + } else if (ev.mask & IN_DELETE_SELF) {
157 + printf("deleted\n");
158 + } else if (ev.mask & IN_IGNORED) {
159 + printf("ignored\n");
160 + // file is being replaced. replace the watch
161 + wd = inotify_add_watch(ifd, ccdl->lib->src_fname, IN_MODIFY);
162 + if (wd < 0) {
163 + warn("inotify_add_watch");
164 + return -1;
165 + }
166 + } else {
154167 printf("unknown mask: %u\n", ev.mask);
155- continue;
156168 }
157-
158169 (void)ccdl_rebuild(ccdl);
159170 }
160171
161172 return 0;

Built with git-ssb-web