summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c47
-rw-r--r--snac.h2
2 files changed, 40 insertions, 9 deletions
diff --git a/data.c b/data.c
index bcfdd9b..15ca18d 100644
--- a/data.c
+++ b/data.c
@@ -185,7 +185,7 @@ d_char *user_list(void)
185} 185}
186 186
187 187
188double mtime(char *fn) 188double mtime(const char *fn)
189/* returns the mtime of a file or directory, or 0.0 */ 189/* returns the mtime of a file or directory, or 0.0 */
190{ 190{
191 struct stat st; 191 struct stat st;
@@ -1477,22 +1477,51 @@ d_char *dequeue(snac *snac, char *fn)
1477} 1477}
1478 1478
1479 1479
1480static void _purge_file(const char *fn, int days)
1481{
1482 time_t mt = time(NULL) - days * 24 * 3600;
1483
1484 if (mtime(fn) < mt) {
1485 /* older than the minimum time: delete it */
1486 unlink(fn);
1487 srv_debug(1, xs_fmt("purged %s", fn));
1488 }
1489}
1490
1491
1480static void _purge_subdir(snac *snac, const char *subdir, int days) 1492static void _purge_subdir(snac *snac, const char *subdir, int days)
1481/* purges all files in subdir older than days */ 1493/* purges all files in subdir older than days */
1482{ 1494{
1483 if (days) { 1495 if (days) {
1484 time_t mt = time(NULL) - days * 24 * 3600;
1485 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir); 1496 xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir);
1486 xs *list = xs_glob(spec, 0, 0); 1497 xs *list = xs_glob(spec, 0, 0);
1487 char *p, *v; 1498 char *p, *v;
1488 1499
1489 p = list; 1500 p = list;
1490 while (xs_list_iter(&p, &v)) { 1501 while (xs_list_iter(&p, &v))
1491 if (mtime(v) < mt) { 1502 _purge_file(v, days);
1492 /* older than the minimum time: delete it */ 1503 }
1493 unlink(v); 1504}
1494 snac_debug(snac, 1, xs_fmt("purged %s", v)); 1505
1495 } 1506
1507void purge_server(void)
1508/* purge global server data */
1509{
1510 int tpd = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
1511// int lpd = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
1512 xs *spec = xs_fmt("%s/object/??", srv_basedir);
1513 xs *dirs = xs_glob(spec, 0, 0);
1514 char *p, *v;
1515
1516 p = dirs;
1517 while (xs_list_iter(&p, &v)) {
1518 xs *spec2 = xs_fmt("%s/" "*", v);
1519 xs *files = xs_glob(spec2, 0, 0);
1520 char *p2, *v2;
1521
1522 p2 = files;
1523 while (xs_list_iter(&p2, &v2)) {
1524 _purge_file(v2, tpd);
1496 } 1525 }
1497 } 1526 }
1498} 1527}
@@ -1515,6 +1544,8 @@ void purge_user(snac *snac)
1515void purge_all(void) 1544void purge_all(void)
1516/* purge all users */ 1545/* purge all users */
1517{ 1546{
1547 purge_server();
1548
1518 snac snac; 1549 snac snac;
1519 xs *list = user_list(); 1550 xs *list = user_list();
1520 char *p, *uid; 1551 char *p, *uid;
diff --git a/snac.h b/snac.h
index bdbdade..be8aaae 100644
--- a/snac.h
+++ b/snac.h
@@ -50,7 +50,7 @@ int check_password(char *uid, char *passwd, char *hash);
50void srv_archive(char *direction, char *req, char *payload, int p_size, 50void srv_archive(char *direction, char *req, char *payload, int p_size,
51 int status, char *headers, char *body, int b_size); 51 int status, char *headers, char *body, int b_size);
52 52
53double mtime(char *fn); 53double mtime(const char *fn);
54 54
55int index_add(const char *fn, const char *md5); 55int index_add(const char *fn, const char *md5);
56int index_del(const char *fn, const char *md5); 56int index_del(const char *fn, const char *md5);