From 5c05e60bcecedc2ffbffb33132823b7347659608 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 23 Nov 2022 16:46:18 +0100 Subject: [PATCH] New db_layout 2.2. --- data.c | 4 ++-- upgrade.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/data.c b/data.c index d3e4b9a..2fa7e4f 100644 --- a/data.c +++ b/data.c @@ -14,7 +14,7 @@ #include #include -double db_layout = 2.1; +double db_layout = 2.2; int db_upgrade(d_char **error); @@ -195,7 +195,7 @@ double mtime(char *fn) d_char *_object_fn_by_md5(const char *md5) { - xs *bfn = xs_fmt("%s/object/%c%c/", srv_basedir, md5[0], md5[1]); + xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]); mkdir(bfn, 0755); diff --git a/upgrade.c b/upgrade.c index e4c75bb..d5e5f0c 100644 --- a/upgrade.c +++ b/upgrade.c @@ -40,6 +40,40 @@ int db_upgrade(d_char **error) nf = 2.1; } + else + if (f < 2.2) { + 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/actors/" "*.json", snac.basedir); + xs *list = xs_glob(spec, 0, 0); + char *g, *fn; + + g = list; + while (xs_list_iter(&g, &fn)) { + xs *l = xs_split(fn, "/"); + char *b = xs_list_get(l, -1); + xs *dir = xs_fmt("%s/object/%c%c", srv_basedir, b[0], b[1]); + xs *nfn = xs_fmt("%s/%s", dir, b); + + mkdir(dir, 0755); + rename(fn, nfn); + } + + xs *odir = xs_fmt("%s/actors", snac.basedir); + rmdir(odir); + + user_free(&snac); + } + } + + nf = 2.2; + } if (f < nf) { f = nf;