diff options
| -rw-r--r-- | data.c | 26 |
1 files changed, 26 insertions, 0 deletions
| @@ -336,6 +336,32 @@ int user_persist(snac *snac, int publish) | |||
| 336 | xs *bfn = xs_fmt("%s.bak", fn); | 336 | xs *bfn = xs_fmt("%s.bak", fn); |
| 337 | FILE *f; | 337 | FILE *f; |
| 338 | 338 | ||
| 339 | if (publish) { | ||
| 340 | /* check if any of the relevant fields have really changed */ | ||
| 341 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 342 | xs *old = xs_json_load(f); | ||
| 343 | fclose(f); | ||
| 344 | |||
| 345 | if (old != NULL) { | ||
| 346 | int nw = 0; | ||
| 347 | const char *fields[] = { "header", "avatar", "name", "bio", "metadata", NULL }; | ||
| 348 | |||
| 349 | for (int n = 0; fields[n]; n++) { | ||
| 350 | const char *of = xs_dict_get(old, fields[n]); | ||
| 351 | const char *nf = xs_dict_get(snac->config, fields[n]); | ||
| 352 | |||
| 353 | if (xs_type(of) != XSTYPE_STRING || xs_type(nf) != XSTYPE_STRING || strcmp(of, nf)) { | ||
| 354 | nw = 1; | ||
| 355 | break; | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | if (!nw) | ||
| 360 | publish = 0; | ||
| 361 | } | ||
| 362 | } | ||
| 363 | } | ||
| 364 | |||
| 339 | rename(fn, bfn); | 365 | rename(fn, bfn); |
| 340 | 366 | ||
| 341 | if ((f = fopen(fn, "w")) != NULL) { | 367 | if ((f = fopen(fn, "w")) != NULL) { |