diff options
| -rw-r--r-- | data.c | 40 |
1 files changed, 14 insertions, 26 deletions
| @@ -152,12 +152,19 @@ d_char *xs_glob_n(const char *spec, int basename, int reverse, int max) | |||
| 152 | 152 | ||
| 153 | if (glob(spec, 0, NULL, &globbuf) == 0) { | 153 | if (glob(spec, 0, NULL, &globbuf) == 0) { |
| 154 | int n; | 154 | int n; |
| 155 | char *p; | ||
| 156 | 155 | ||
| 157 | if (reverse) { | 156 | if (max > globbuf.gl_pathc) |
| 158 | } | 157 | max = globbuf.gl_pathc; |
| 159 | else { | 158 | |
| 160 | for (n = 0; n < max && (p = globbuf.gl_pathv[n]) != NULL; n++) { | 159 | for (n = 0; n < max; n++) { |
| 160 | char *p; | ||
| 161 | |||
| 162 | if (reverse) | ||
| 163 | p = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; | ||
| 164 | else | ||
| 165 | p = globbuf.gl_pathv[n]; | ||
| 166 | |||
| 167 | if (p != NULL) { | ||
| 161 | if (basename) { | 168 | if (basename) { |
| 162 | if ((p = strrchr(p, '/')) == NULL) | 169 | if ((p = strrchr(p, '/')) == NULL) |
| 163 | continue; | 170 | continue; |
| @@ -379,36 +386,17 @@ d_char *timeline_get(snac *snac, char *fn) | |||
| 379 | d_char *_timeline_list(snac *snac, char *directory, int max) | 386 | d_char *_timeline_list(snac *snac, char *directory, int max) |
| 380 | /* returns a list of the timeline filenames */ | 387 | /* returns a list of the timeline filenames */ |
| 381 | { | 388 | { |
| 382 | d_char *list; | ||
| 383 | xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, directory); | 389 | xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, directory); |
| 384 | glob_t globbuf; | ||
| 385 | int c_max; | 390 | int c_max; |
| 386 | 391 | ||
| 387 | /* maximum number of items in the timeline */ | 392 | /* maximum number of items in the timeline */ |
| 388 | c_max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); | 393 | c_max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); |
| 389 | 394 | ||
| 395 | /* never more timeline entries than the configured maximum */ | ||
| 390 | if (max > c_max) | 396 | if (max > c_max) |
| 391 | max = c_max; | 397 | max = c_max; |
| 392 | 398 | ||
| 393 | list = xs_list_new(); | 399 | return xs_glob_n(spec, 0, 1, max); |
| 394 | |||
| 395 | /* get the list in reverse order */ | ||
| 396 | if (glob(spec, 0, NULL, &globbuf) == 0) { | ||
| 397 | int n; | ||
| 398 | |||
| 399 | if (max > globbuf.gl_pathc) | ||
| 400 | max = globbuf.gl_pathc; | ||
| 401 | |||
| 402 | for (n = 0; n < max; n++) { | ||
| 403 | char *fn = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; | ||
| 404 | |||
| 405 | list = xs_list_append(list, fn); | ||
| 406 | } | ||
| 407 | } | ||
| 408 | |||
| 409 | globfree(&globbuf); | ||
| 410 | |||
| 411 | return list; | ||
| 412 | } | 400 | } |
| 413 | 401 | ||
| 414 | 402 | ||