diff options
| -rw-r--r-- | data.c | 7 |
1 files changed, 6 insertions, 1 deletions
| @@ -10,8 +10,9 @@ | |||
| 10 | #include "snac.h" | 10 | #include "snac.h" |
| 11 | 11 | ||
| 12 | #include <time.h> | 12 | #include <time.h> |
| 13 | #include <glob.h> | ||
| 14 | #include <sys/stat.h> | 13 | #include <sys/stat.h> |
| 14 | #include <sys/file.h> | ||
| 15 | #include <fcntl.h> | ||
| 15 | 16 | ||
| 16 | double db_layout = 2.1; | 17 | double db_layout = 2.1; |
| 17 | 18 | ||
| @@ -218,6 +219,8 @@ int object_get(const char *id, d_char **obj, const char *type) | |||
| 218 | FILE *f; | 219 | FILE *f; |
| 219 | 220 | ||
| 220 | if ((f = fopen(fn, "r")) != NULL) { | 221 | if ((f = fopen(fn, "r")) != NULL) { |
| 222 | flock(fileno(f), LOCK_SH); | ||
| 223 | |||
| 221 | xs *j = xs_readall(f); | 224 | xs *j = xs_readall(f); |
| 222 | fclose(f); | 225 | fclose(f); |
| 223 | 226 | ||
| @@ -252,6 +255,8 @@ int object_add(const char *id, d_char *obj) | |||
| 252 | FILE *f; | 255 | FILE *f; |
| 253 | 256 | ||
| 254 | if ((f = fopen(fn, "w")) != NULL) { | 257 | if ((f = fopen(fn, "w")) != NULL) { |
| 258 | flock(fileno(f), LOCK_EX); | ||
| 259 | |||
| 255 | xs *j = xs_json_dumps_pp(obj, 4); | 260 | xs *j = xs_json_dumps_pp(obj, 4); |
| 256 | 261 | ||
| 257 | fwrite(j, strlen(j), 1, f); | 262 | fwrite(j, strlen(j), 1, f); |