summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/data.c b/data.c
index fcfd917..121407f 100644
--- a/data.c
+++ b/data.c
@@ -541,17 +541,15 @@ int index_in(const char *fn, const char *id)
541} 541}
542 542
543 543
544int index_first(const char *fn, char *line, int size) 544int index_first(const char *fn, char md5[MD5_HEX_SIZE])
545/* reads the first entry of an index */ 545/* reads the first entry of an index */
546{ 546{
547 FILE *f; 547 FILE *f;
548 int ret = 0; 548 int ret = 0;
549 549
550 if ((f = fopen(fn, "r")) != NULL) { 550 if ((f = fopen(fn, "r")) != NULL) {
551 flock(fileno(f), LOCK_SH); 551 if (fread(md5, MD5_HEX_SIZE, 1, f)) {
552 552 md5[MD5_HEX_SIZE - 1] = '\0';
553 if (fgets(line, size, f) != NULL) {
554 line[MD5_HEX_SIZE - 1] = '\0';
555 ret = 1; 553 ret = 1;
556 } 554 }
557 555
@@ -958,13 +956,13 @@ xs_list *object_announces(const char *id)
958} 956}
959 957
960 958
961int object_parent(const char *md5, char *buf, int size) 959int object_parent(const char *md5, char parent[MD5_HEX_SIZE])
962/* returns the object parent, if any */ 960/* returns the object parent, if any */
963{ 961{
964 xs *fn = _object_fn_by_md5(md5, "object_parent"); 962 xs *fn = _object_fn_by_md5(md5, "object_parent");
965 963
966 fn = xs_replace_i(fn, ".json", "_p.idx"); 964 fn = xs_replace_i(fn, ".json", "_p.idx");
967 return index_first(fn, buf, size); 965 return index_first(fn, parent);
968} 966}
969 967
970 968
@@ -1268,15 +1266,15 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list)
1268 1266
1269 int c = 0; 1267 int c = 0;
1270 while (xs_list_next(list, &v, &c)) { 1268 while (xs_list_next(list, &v, &c)) {
1271 char line[256] = ""; 1269 char line[MD5_HEX_SIZE] = "";
1272 1270
1273 strncpy(line, v, sizeof(line)); 1271 strncpy(line, v, sizeof(line));
1274 1272
1275 for (;;) { 1273 for (;;) {
1276 char line2[256]; 1274 char line2[MD5_HEX_SIZE];
1277 1275
1278 /* if it doesn't have a parent, use this */ 1276 /* if it doesn't have a parent, use this */
1279 if (!object_parent(line, line2, sizeof(line2))) 1277 if (!object_parent(line, line2))
1280 break; 1278 break;
1281 1279
1282 /* well, there is a parent... but is it here? */ 1280 /* well, there is a parent... but is it here? */