diff options
| author | 2022-10-03 10:56:15 +0200 | |
|---|---|---|
| committer | 2022-10-03 10:56:15 +0200 | |
| commit | 365b27ffb255e5ea9529640b17001e4ad5fcca2d (patch) | |
| tree | 80dd8210f6b128c57a971d0ac11b80abd09a92d6 | |
| parent | Use xs_glob() in user_list(). (diff) | |
| download | penes-snac2-365b27ffb255e5ea9529640b17001e4ad5fcca2d.tar.gz penes-snac2-365b27ffb255e5ea9529640b17001e4ad5fcca2d.tar.xz penes-snac2-365b27ffb255e5ea9529640b17001e4ad5fcca2d.zip | |
Use xs_glob() in follower_list().
| -rw-r--r-- | data.c | 30 |
1 files changed, 13 insertions, 17 deletions
| @@ -256,34 +256,30 @@ int follower_check(snac *snac, char *actor) | |||
| 256 | d_char *follower_list(snac *snac) | 256 | d_char *follower_list(snac *snac) |
| 257 | /* returns the list of followers */ | 257 | /* returns the list of followers */ |
| 258 | { | 258 | { |
| 259 | d_char *list; | 259 | xs *spec = xs_fmt("%s/followers/" "*.json", snac->basedir); |
| 260 | xs *spec; | 260 | xs *glist = xs_glob(spec, 0, 0); |
| 261 | glob_t globbuf; | 261 | char *p, *v; |
| 262 | 262 | d_char *list = xs_list_new(); | |
| 263 | list = xs_list_new(); | ||
| 264 | spec = xs_fmt("%s/followers/" "*.json", snac->basedir); | ||
| 265 | 263 | ||
| 266 | if (glob(spec, 0, NULL, &globbuf) == 0) { | 264 | /* iterate the list of files */ |
| 267 | int n; | 265 | p = glist; |
| 268 | char *fn; | 266 | while (xs_list_iter(&p, &v)) { |
| 267 | FILE *f; | ||
| 269 | 268 | ||
| 270 | for (n = 0; (fn = globbuf.gl_pathv[n]) != NULL; n++) { | 269 | /* load the follower data */ |
| 271 | FILE *f; | 270 | if ((f = fopen(v, "r")) != NULL) { |
| 271 | xs *j = xs_readall(f); | ||
| 272 | fclose(f); | ||
| 272 | 273 | ||
| 273 | if ((f = fopen(fn, "r")) != NULL) { | 274 | if (j != NULL) { |
| 274 | xs *j = xs_readall(f); | ||
| 275 | xs *o = xs_json_loads(j); | 275 | xs *o = xs_json_loads(j); |
| 276 | 276 | ||
| 277 | if (o != NULL) | 277 | if (o != NULL) |
| 278 | list = xs_list_append(list, o); | 278 | list = xs_list_append(list, o); |
| 279 | |||
| 280 | fclose(f); | ||
| 281 | } | 279 | } |
| 282 | } | 280 | } |
| 283 | } | 281 | } |
| 284 | 282 | ||
| 285 | globfree(&globbuf); | ||
| 286 | |||
| 287 | return list; | 283 | return list; |
| 288 | } | 284 | } |
| 289 | 285 | ||