From 67a81a7bf9c65b1d7ec5cb5ac255169222be24ac Mon Sep 17 00:00:00 2001 From: default Date: Sat, 3 Dec 2022 18:41:44 +0100 Subject: [PATCH] Upgrade timeline/ to private/. --- data.c | 2 +- upgrade.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index f3a1ce8..90d568f 100644 --- a/data.c +++ b/data.c @@ -15,7 +15,7 @@ #include #include -double db_layout = 2.6; +double db_layout = 2.7; int db_upgrade(d_char **error); diff --git a/upgrade.c b/upgrade.c index dbf878b..4eb211e 100644 --- a/upgrade.c +++ b/upgrade.c @@ -230,6 +230,64 @@ int db_upgrade(d_char **error) nf = 2.6; } + else + if (f < 2.7) { + /* upgrade timeline/ to private/ */ + xs *users = user_list(); + char *p, *v; + + p = users; + while (xs_list_iter(&p, &v)) { + snac snac; + + if (user_open(&snac, v)) { + xs *spec = xs_fmt("%s/timeline/" "*.json", snac.basedir); + xs *dir = xs_glob(spec, 0, 0); + char *p, *v; + + p = dir; + while (xs_list_iter(&p, &v)) { + FILE *f; + + if ((f = fopen(v, "r")) != NULL) { + xs *s = xs_readall(f); + xs *o = xs_json_loads(s); + fclose(f); + + xs *meta = xs_dup(xs_dict_get(o, "_snac")); + o = xs_dict_del(o, "_snac"); + + char *id = xs_dict_get(o, "id"); + + /* store object */ + object_add_ow(id, o); + + { + char *p, *v; + + object_user_cache_add(&snac, id, "private"); + + p = xs_dict_get(meta, "announced_by"); + while (xs_list_iter(&p, &v)) + object_admire(id, v, 0); + p = xs_dict_get(meta, "liked_by"); + while (xs_list_iter(&p, &v)) + object_admire(id, v, 1); + } + + unlink(v); + } + } + + xs *od = xs_fmt("%s/timeline", snac.basedir); + rmdir(od); + + user_free(&snac); + } + } + + nf = 2.7; + } if (f < nf) { f = nf;