Upgrade timeline/ to private/.

This commit is contained in:
default 2022-12-03 18:41:44 +01:00
parent f205d20688
commit 67a81a7bf9
2 changed files with 59 additions and 1 deletions

2
data.c
View file

@ -15,7 +15,7 @@
#include <sys/file.h> #include <sys/file.h>
#include <fcntl.h> #include <fcntl.h>
double db_layout = 2.6; double db_layout = 2.7;
int db_upgrade(d_char **error); int db_upgrade(d_char **error);

View file

@ -230,6 +230,64 @@ int db_upgrade(d_char **error)
nf = 2.6; 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) { if (f < nf) {
f = nf; f = nf;