The global object database is also purged.

This commit is contained in:
default 2022-11-25 11:37:05 +01:00
parent b792417013
commit 200a6a0c91
2 changed files with 40 additions and 9 deletions

45
data.c
View file

@ -185,7 +185,7 @@ d_char *user_list(void)
}
double mtime(char *fn)
double mtime(const char *fn)
/* returns the mtime of a file or directory, or 0.0 */
{
struct stat st;
@ -1477,23 +1477,52 @@ d_char *dequeue(snac *snac, char *fn)
}
static void _purge_file(const char *fn, int days)
{
time_t mt = time(NULL) - days * 24 * 3600;
if (mtime(fn) < mt) {
/* older than the minimum time: delete it */
unlink(fn);
srv_debug(1, xs_fmt("purged %s", fn));
}
}
static void _purge_subdir(snac *snac, const char *subdir, int days)
/* purges all files in subdir older than days */
{
if (days) {
time_t mt = time(NULL) - days * 24 * 3600;
xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
xs *list = xs_glob(spec, 0, 0);
char *p, *v;
p = list;
while (xs_list_iter(&p, &v)) {
if (mtime(v) < mt) {
/* older than the minimum time: delete it */
unlink(v);
snac_debug(snac, 1, xs_fmt("purged %s", v));
while (xs_list_iter(&p, &v))
_purge_file(v, days);
}
}
void purge_server(void)
/* purge global server data */
{
int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
// int lpd = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
xs *spec = xs_fmt("%s/object/??", srv_basedir);
xs *dirs = xs_glob(spec, 0, 0);
char *p, *v;
p = dirs;
while (xs_list_iter(&p, &v)) {
xs *spec2 = xs_fmt("%s/" "*", v);
xs *files = xs_glob(spec2, 0, 0);
char *p2, *v2;
p2 = files;
while (xs_list_iter(&p2, &v2)) {
_purge_file(v2, tpd);
}
}
}
@ -1515,6 +1544,8 @@ void purge_user(snac *snac)
void purge_all(void)
/* purge all users */
{
purge_server();
snac snac;
xs *list = user_list();
char *p, *uid;

2
snac.h
View file

@ -50,7 +50,7 @@ int check_password(char *uid, char *passwd, char *hash);
void srv_archive(char *direction, char *req, char *payload, int p_size,
int status, char *headers, char *body, int b_size);
double mtime(char *fn);
double mtime(const char *fn);
int index_add(const char *fn, const char *md5);
int index_del(const char *fn, const char *md5);