diff options
| author | 2022-11-28 10:46:42 +0100 | |
|---|---|---|
| committer | 2022-11-28 10:46:42 +0100 | |
| commit | 07fec7127326cf02d50bd148581908d51cc697f6 (patch) | |
| tree | c62856673c0e80a71782fa3bd4f8452e5132638e /upgrade.c | |
| parent | New function object_user_cache_in(). (diff) | |
| download | penes-snac2-07fec7127326cf02d50bd148581908d51cc697f6.tar.gz penes-snac2-07fec7127326cf02d50bd148581908d51cc697f6.tar.xz penes-snac2-07fec7127326cf02d50bd148581908d51cc697f6.zip | |
Upgraded followers to the new db.
Diffstat (limited to 'upgrade.c')
| -rw-r--r-- | upgrade.c | 45 |
1 files changed, 45 insertions, 0 deletions
| @@ -128,6 +128,51 @@ int db_upgrade(d_char **error) | |||
| 128 | 128 | ||
| 129 | nf = 2.4; | 129 | nf = 2.4; |
| 130 | } | 130 | } |
| 131 | else | ||
| 132 | if (f < 2.5) { | ||
| 133 | /* upgrade followers */ | ||
| 134 | xs *users = user_list(); | ||
| 135 | char *p, *v; | ||
| 136 | |||
| 137 | xs_debug(); | ||
| 138 | |||
| 139 | p = users; | ||
| 140 | while (xs_list_iter(&p, &v)) { | ||
| 141 | snac snac; | ||
| 142 | |||
| 143 | if (user_open(&snac, v)) { | ||
| 144 | xs *spec = xs_fmt("%s/followers/" "*.json", snac.basedir); | ||
| 145 | xs *dir = xs_glob(spec, 0, 0); | ||
| 146 | char *p, *v; | ||
| 147 | |||
| 148 | p = dir; | ||
| 149 | while (xs_list_iter(&p, &v)) { | ||
| 150 | FILE *f; | ||
| 151 | |||
| 152 | if ((f = fopen(v, "r")) != NULL) { | ||
| 153 | xs *s = xs_readall(f); | ||
| 154 | xs *o = xs_json_loads(s); | ||
| 155 | fclose(f); | ||
| 156 | |||
| 157 | char *type = xs_dict_get(o, "type"); | ||
| 158 | |||
| 159 | if (!xs_is_null(type) && strcmp(type, "Follow") == 0) { | ||
| 160 | unlink(v); | ||
| 161 | |||
| 162 | char *actor = xs_dict_get(o, "actor"); | ||
| 163 | |||
| 164 | if (!xs_is_null(actor)) | ||
| 165 | follower_add(&snac, actor); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | user_free(&snac); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | nf = 2.5; | ||
| 175 | } | ||
| 131 | 176 | ||
| 132 | if (f < nf) { | 177 | if (f < nf) { |
| 133 | f = nf; | 178 | f = nf; |