io-watch 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/io/watch/fsevent.c +2 -2
- data/ext/io/watch/inotify.c +47 -25
- data/ext/io/watch.c +2 -2
- data/lib/io/watch/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b3d57b500111de6639098f96580da6ddfc5029f77fc0daf97159e54415ea7c5
|
4
|
+
data.tar.gz: 0ee6cfbdb782214fc141b713f7396448e92ae438244939ed48b9681a6e620f7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e4873bbd69789206c2704fe3e20914c7955c79d2310513adcf8dd9371c6773bf9d0a729b19b1de4a18fe852631435184559d98600d7de5b2ecd81a5a633075a
|
7
|
+
data.tar.gz: cbc9fdaedb8f1383e36e845cd07341e2427e706c205a94da35b355eb87ae049f9d2a256d30beb3a4616f35fbcf10f66e5022e0653849a3762a01376a7937f003
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/ext/io/watch/fsevent.c
CHANGED
@@ -48,7 +48,7 @@ void IO_Watch_FSEvent_callback(
|
|
48
48
|
struct IO_Watch *watch = context;
|
49
49
|
|
50
50
|
for (size_t i = 0; i < numberOfEvents; i++) {
|
51
|
-
if (DEBUG) fprintf(stderr, "
|
51
|
+
if (DEBUG) fprintf(stderr, "io-watch:IO_Watch_FSEvent_callback: Event %s\n", eventPaths[i]);
|
52
52
|
|
53
53
|
// Find the index of the path in the paths array
|
54
54
|
ssize_t index = IO_Watch_find_path(watch, eventPaths[i]);
|
@@ -57,7 +57,7 @@ void IO_Watch_FSEvent_callback(
|
|
57
57
|
// Output event data as newline-delimited JSON
|
58
58
|
printf("{\"index\":%zu,\"flags\":%u,\"id\":%llu}\n", index, eventFlags[i], eventIds[i]);
|
59
59
|
} else {
|
60
|
-
fprintf(stderr, "Path not found
|
60
|
+
fprintf(stderr, "io-watch:IO_Watch_FSEvent_callback: Path not found %s\n", eventPaths[i]);
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
data/ext/io/watch/inotify.c
CHANGED
@@ -33,7 +33,7 @@ void IO_Watch_Watch_Array_initialize(struct IO_Watch_Watch_Array *array) {
|
|
33
33
|
array->capacity = 16;
|
34
34
|
array->watches = malloc(array->capacity * sizeof(struct IO_Watch_Watch));
|
35
35
|
if (!array->watches) {
|
36
|
-
perror("malloc");
|
36
|
+
perror("io-watch:IO_Watch_Watch_Array_initialize:malloc");
|
37
37
|
exit(EXIT_FAILURE);
|
38
38
|
}
|
39
39
|
}
|
@@ -42,7 +42,7 @@ void IO_Watch_Watch_Array_resize(struct IO_Watch_Watch_Array *array) {
|
|
42
42
|
array->capacity *= 2;
|
43
43
|
array->watches = realloc(array->watches, array->capacity * sizeof(struct IO_Watch_Watch));
|
44
44
|
if (!array->watches) {
|
45
|
-
perror("realloc");
|
45
|
+
perror("io-watch:IO_Watch_Watch_Array_resize:realloc");
|
46
46
|
exit(EXIT_FAILURE);
|
47
47
|
}
|
48
48
|
}
|
@@ -67,21 +67,30 @@ ssize_t IO_Watch_Watch_Array_find(struct IO_Watch_Watch_Array *array, int watch_
|
|
67
67
|
}
|
68
68
|
|
69
69
|
void IO_Watch_Watch_Array_watch(int fd, struct IO_Watch_Watch_Array *watch_array, char *path, int index) {
|
70
|
-
int
|
70
|
+
int mask =
|
71
|
+
IN_MODIFY | // File was modified.
|
72
|
+
IN_ATTRIB | // Metadata (permissions, timestamps, etc.) changed.
|
73
|
+
IN_CLOSE_WRITE | // Writable file was closed.
|
74
|
+
IN_MOVE_SELF | // Watched file/directory was moved.
|
75
|
+
IN_CREATE | // File or directory was created within the watched directory.
|
76
|
+
IN_DELETE; // File or directory was deleted within the watched directory.
|
77
|
+
|
78
|
+
int watch_descriptor = inotify_add_watch(fd, path, mask);
|
79
|
+
|
71
80
|
if (watch_descriptor == -1) {
|
72
|
-
perror("inotify_add_watch");
|
81
|
+
perror("io-watch:IO_Watch_Watch_Array_watch:inotify_add_watch");
|
73
82
|
exit(EXIT_FAILURE);
|
74
83
|
}
|
75
84
|
|
76
85
|
IO_Watch_Watch_Array_add(watch_array, watch_descriptor, path, index);
|
77
86
|
|
78
|
-
if (DEBUG) fprintf(stderr, "Added watch
|
87
|
+
if (DEBUG) fprintf(stderr, "io-watch:IO_Watch_Watch_Array_watch: Added watch %s\n", path);
|
79
88
|
}
|
80
89
|
|
81
90
|
void IO_Watch_Watch_Array_scan(int fd, struct IO_Watch_Watch_Array *watch_array, const char *root, int index) {
|
82
91
|
DIR *dir = opendir(root);
|
83
92
|
if (!dir) {
|
84
|
-
perror("opendir");
|
93
|
+
perror("io-watch:IO_Watch_Watch_Array_scan:opendir");
|
85
94
|
return;
|
86
95
|
}
|
87
96
|
|
@@ -94,13 +103,13 @@ void IO_Watch_Watch_Array_scan(int fd, struct IO_Watch_Watch_Array *watch_array,
|
|
94
103
|
size_t size = strlen(root) + 1 + strlen(entry->d_name) + 1;
|
95
104
|
char *path = malloc(size);
|
96
105
|
snprintf(path, size, "%s/%s", root, entry->d_name);
|
97
|
-
|
106
|
+
|
98
107
|
struct stat statbuf;
|
99
108
|
if (stat(path, &statbuf) == -1) {
|
100
|
-
perror("stat");
|
109
|
+
perror("io-watch:IO_Watch_Watch_Array_scan:stat");
|
101
110
|
continue;
|
102
111
|
}
|
103
|
-
|
112
|
+
|
104
113
|
if (S_ISDIR(statbuf.st_mode)) {
|
105
114
|
IO_Watch_Watch_Array_watch(fd, watch_array, path, index);
|
106
115
|
IO_Watch_Watch_Array_scan(fd, watch_array, path, index);
|
@@ -108,7 +117,7 @@ void IO_Watch_Watch_Array_scan(int fd, struct IO_Watch_Watch_Array *watch_array,
|
|
108
117
|
free(path);
|
109
118
|
}
|
110
119
|
}
|
111
|
-
|
120
|
+
|
112
121
|
closedir(dir);
|
113
122
|
}
|
114
123
|
|
@@ -116,7 +125,7 @@ void IO_Watch_Watch_Array_add_subdirectory(int fd, struct IO_Watch_Watch_Array *
|
|
116
125
|
size_t size = strlen(watch.path) + 1 + strlen(name) + 1;
|
117
126
|
char *path = malloc(size);
|
118
127
|
snprintf(path, size, "%s/%s", watch.path, name);
|
119
|
-
|
128
|
+
|
120
129
|
IO_Watch_Watch_Array_watch(fd, watch_array, path, watch.index);
|
121
130
|
IO_Watch_Watch_Array_scan(fd, watch_array, path, watch.index);
|
122
131
|
}
|
@@ -124,7 +133,7 @@ void IO_Watch_Watch_Array_add_subdirectory(int fd, struct IO_Watch_Watch_Array *
|
|
124
133
|
void IO_Watch_Watch_Array_remove(int fd, struct IO_Watch_Watch_Array *watch_array, size_t index) {
|
125
134
|
struct IO_Watch_Watch watch = watch_array->watches[index];
|
126
135
|
|
127
|
-
if (DEBUG) fprintf(stderr, "Removing watch
|
136
|
+
if (DEBUG) fprintf(stderr, "io-watch:IO_Watch_Watch_Array_add_subdirectory: Removing watch %s\n", watch.path);
|
128
137
|
|
129
138
|
inotify_rm_watch(fd, watch.watch_descriptor);
|
130
139
|
free(watch.path);
|
@@ -138,7 +147,7 @@ void IO_Watch_Watch_Array_remove(int fd, struct IO_Watch_Watch_Array *watch_arra
|
|
138
147
|
|
139
148
|
static
|
140
149
|
void IO_Watch_INotify_print_event(struct inotify_event *event) {
|
141
|
-
fprintf(stderr, "Event
|
150
|
+
fprintf(stderr, "Event wd=%d", event->wd);
|
142
151
|
|
143
152
|
uint32_t mask = event->mask;
|
144
153
|
if (mask & IN_ACCESS) fprintf(stderr, " ACCESS");
|
@@ -170,41 +179,54 @@ void IO_Watch_INotify_print_event(struct inotify_event *event) {
|
|
170
179
|
void IO_Watch_run(struct IO_Watch *watch) {
|
171
180
|
int fd = inotify_init1(IN_NONBLOCK);
|
172
181
|
if (fd == -1) {
|
173
|
-
perror("inotify_init1");
|
182
|
+
perror("io-watch:IO_Watch_run:inotify_init1");
|
174
183
|
exit(EXIT_FAILURE);
|
175
184
|
}
|
176
|
-
|
185
|
+
|
177
186
|
struct IO_Watch_Watch_Array watch_array;
|
178
187
|
IO_Watch_Watch_Array_initialize(&watch_array);
|
179
|
-
|
188
|
+
|
180
189
|
for (size_t i = 0; i < watch->size; i++) {
|
181
190
|
char *path = strdup(watch->paths[i]);
|
182
191
|
|
183
192
|
IO_Watch_Watch_Array_watch(fd, &watch_array, path, i);
|
184
193
|
IO_Watch_Watch_Array_scan(fd, &watch_array, path, i);
|
185
194
|
}
|
186
|
-
|
195
|
+
|
187
196
|
printf("{\"status\":\"started\"}\n");
|
188
197
|
fflush(stdout);
|
189
|
-
|
198
|
+
|
190
199
|
char buffer[BUFFER_SIZE] __attribute__ ((aligned(8)));
|
191
200
|
|
192
201
|
while (1) {
|
193
202
|
ssize_t result = read(fd, buffer, BUFFER_SIZE);
|
194
203
|
if (result == -1 && errno != EAGAIN) {
|
195
|
-
perror("read");
|
204
|
+
perror("(io-watch:IO_Watch_run:read)");
|
196
205
|
exit(EXIT_FAILURE);
|
197
206
|
}
|
198
|
-
|
207
|
+
|
199
208
|
for (ssize_t offset = 0; offset < result;) {
|
200
209
|
struct inotify_event *event = (struct inotify_event *) &buffer[offset];
|
201
|
-
if (DEBUG)
|
210
|
+
if (DEBUG) {
|
211
|
+
fprintf(stderr, "io-watch:IO_Watch_run: ");
|
212
|
+
IO_Watch_INotify_print_event(event);
|
213
|
+
}
|
214
|
+
|
215
|
+
if (event->wd == -1) {
|
216
|
+
if (event->mask & IN_Q_OVERFLOW) {
|
217
|
+
fprintf(stderr, "io-watch:IO_Watch_run: Queue overflow\n");
|
218
|
+
} else {
|
219
|
+
fprintf(stderr, "io-watch:IO_Watch_run: Unknown error ");
|
220
|
+
IO_Watch_INotify_print_event(event);
|
221
|
+
}
|
222
|
+
break;
|
223
|
+
}
|
202
224
|
|
203
225
|
ssize_t index = IO_Watch_Watch_Array_find(&watch_array, event->wd);
|
204
|
-
|
226
|
+
|
205
227
|
if (index != -1) {
|
206
228
|
printf("{\"index\":%d,\"mask\":%u}\n", watch_array.watches[index].index, event->mask);
|
207
|
-
|
229
|
+
|
208
230
|
// If a new directory is created, add a watch for it
|
209
231
|
if (event->mask & IN_CREATE && event->mask & IN_ISDIR) {
|
210
232
|
IO_Watch_Watch_Array_add_subdirectory(fd, &watch_array, watch_array.watches[index], event->name);
|
@@ -212,9 +234,9 @@ void IO_Watch_run(struct IO_Watch *watch) {
|
|
212
234
|
IO_Watch_Watch_Array_remove(fd, &watch_array, index);
|
213
235
|
}
|
214
236
|
} else {
|
215
|
-
fprintf(stderr, "Watch descriptor not found
|
237
|
+
fprintf(stderr, "io-watch:IO_Watch_run: Watch descriptor %d not found!\n", event->wd);
|
216
238
|
}
|
217
|
-
|
239
|
+
|
218
240
|
offset += sizeof(struct inotify_event) + event->len;
|
219
241
|
}
|
220
242
|
fflush(stdout);
|
data/ext/io/watch.c
CHANGED
@@ -27,10 +27,10 @@ int main(int argc, char **argv) {
|
|
27
27
|
for (size_t i = 0; i < watch.size; i++) {
|
28
28
|
char *real_path = realpath(watch.paths[i], NULL);
|
29
29
|
if (real_path == NULL) {
|
30
|
-
fprintf(stderr, "
|
30
|
+
fprintf(stderr, "io-watch:main: Realpath failed for %s\n", watch.paths[i]);
|
31
31
|
return 1;
|
32
32
|
} else {
|
33
|
-
if (DEBUG) fprintf(stderr, "
|
33
|
+
if (DEBUG) fprintf(stderr, "io-watch:main: Watching %s\n", real_path);
|
34
34
|
watch.paths[i] = real_path;
|
35
35
|
}
|
36
36
|
}
|
data/lib/io/watch/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-watch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date: 2024-
|
40
|
+
date: 2024-08-11 00:00:00.000000000 Z
|
41
41
|
dependencies: []
|
42
42
|
description:
|
43
43
|
email:
|
metadata.gz.sig
CHANGED
Binary file
|