summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c46
-rw-r--r--httpd.c2
2 files changed, 32 insertions, 16 deletions
diff --git a/data.c b/data.c
index 9ce334c..938f0e0 100644
--- a/data.c
+++ b/data.c
@@ -380,7 +380,6 @@ d_char *_object_fn_by_md5(const char *md5)
380d_char *_object_fn(const char *id) 380d_char *_object_fn(const char *id)
381{ 381{
382 xs *md5 = xs_md5_hex(id, strlen(id)); 382 xs *md5 = xs_md5_hex(id, strlen(id));
383
384 return _object_fn_by_md5(md5); 383 return _object_fn_by_md5(md5);
385} 384}
386 385
@@ -425,7 +424,6 @@ int object_get(const char *id, d_char **obj, const char *type)
425/* returns a stored object, optionally of the requested type */ 424/* returns a stored object, optionally of the requested type */
426{ 425{
427 xs *md5 = xs_md5_hex(id, strlen(id)); 426 xs *md5 = xs_md5_hex(id, strlen(id));
428
429 return object_get_by_md5(md5, obj, type); 427 return object_get_by_md5(md5, obj, type);
430} 428}
431 429
@@ -473,18 +471,18 @@ int object_add(const char *id, d_char *obj)
473} 471}
474 472
475 473
476int object_del(const char *id) 474int object_del_by_md5(const char *md5)
477/* deletes an object */ 475/* deletes an object by its md5 */
478{ 476{
479 int status = 404; 477 int status = 404;
480 xs *fn = _object_fn(id); 478 xs *fn = _object_fn_by_md5(md5);
481 479
482 if (fn != NULL && unlink(fn) != -1) { 480 if (fn != NULL && unlink(fn) != -1) {
483 status = 200; 481 status = 200;
484 482
485 /* also delete associated indexes */ 483 /* also delete associated indexes */
486 xs *spec = _object_fn(id); 484 xs *spec = xs_dup(fn);
487 spec = xs_replace_i(spec, ".json", "*.idx"); 485 spec = xs_replace_i(spec, ".json", "*.idx");
488 xs *files = xs_glob(spec, 0, 0); 486 xs *files = xs_glob(spec, 0, 0);
489 char *p, *v; 487 char *p, *v;
490 488
@@ -495,12 +493,20 @@ int object_del(const char *id)
495 } 493 }
496 } 494 }
497 495
498 srv_debug(0, xs_fmt("object_del %s %d", id, status)); 496 srv_debug(0, xs_fmt("object_del %s %d", fn, status));
499 497
500 return status; 498 return status;
501} 499}
502 500
503 501
502int object_del(const char *id)
503/* deletes an object */
504{
505 xs *md5 = xs_md5_hex(id, strlen(id));
506 return object_del_by_md5(md5);
507}
508
509
504d_char *object_children(const char *id) 510d_char *object_children(const char *id)
505/* returns the list of an object's children */ 511/* returns the list of an object's children */
506{ 512{
@@ -1521,13 +1527,12 @@ d_char *dequeue(snac *snac, char *fn)
1521} 1527}
1522 1528
1523 1529
1524static void _purge_file(const char *fn, int days, int n_link) 1530static void _purge_file(const char *fn, int days)
1525/* purge fn if it's older than days and has less than n_link hard links */ 1531/* purge fn if it's older than days */
1526{ 1532{
1527 time_t mt = time(NULL) - days * 24 * 3600; 1533 time_t mt = time(NULL) - days * 24 * 3600;
1528 int nl;
1529 1534
1530 if (mtime_nl(fn, &nl) < mt && nl < n_link) { 1535 if (mtime(fn) < mt) {
1531 /* older than the minimum time: delete it */ 1536 /* older than the minimum time: delete it */
1532 unlink(fn); 1537 unlink(fn);
1533 srv_debug(1, xs_fmt("purged %s", fn)); 1538 srv_debug(1, xs_fmt("purged %s", fn));
@@ -1545,7 +1550,7 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
1545 1550
1546 p = list; 1551 p = list;
1547 while (xs_list_iter(&p, &v)) 1552 while (xs_list_iter(&p, &v))
1548 _purge_file(v, days, XS_ALL); 1553 _purge_file(v, days);
1549 } 1554 }
1550} 1555}
1551 1556
@@ -1558,15 +1563,26 @@ void purge_server(void)
1558 xs *dirs = xs_glob(spec, 0, 0); 1563 xs *dirs = xs_glob(spec, 0, 0);
1559 char *p, *v; 1564 char *p, *v;
1560 1565
1566 time_t mt = time(NULL) - tpd * 24 * 3600;
1567
1561 p = dirs; 1568 p = dirs;
1562 while (xs_list_iter(&p, &v)) { 1569 while (xs_list_iter(&p, &v)) {
1563 xs *spec2 = xs_fmt("%s/" "*", v); 1570 xs *spec2 = xs_fmt("%s/" "*.json", v);
1564 xs *files = xs_glob(spec2, 0, 0); 1571 xs *files = xs_glob(spec2, 0, 0);
1565 char *p2, *v2; 1572 char *p2, *v2;
1566 1573
1567 p2 = files; 1574 p2 = files;
1568 while (xs_list_iter(&p2, &v2)) { 1575 while (xs_list_iter(&p2, &v2)) {
1569 _purge_file(v2, tpd, 2); 1576 int n_link;
1577
1578 /* old and with no hard links? */
1579 if (mtime_nl(v2, &n_link) < mt && n_link < 2) {
1580 xs *s1 = xs_replace(v2, ".json", "");
1581 xs *l = xs_split(s1, "/");
1582 char *md5 = xs_list_get(l, -1);
1583
1584 object_del_by_md5(md5);
1585 }
1570 } 1586 }
1571 } 1587 }
1572} 1588}
diff --git a/httpd.c b/httpd.c
index 76bebad..dd8978d 100644
--- a/httpd.c
+++ b/httpd.c
@@ -222,7 +222,7 @@ static void *queue_thread(void *arg)
222 time_t purge_time; 222 time_t purge_time;
223 223
224 /* first purge time */ 224 /* first purge time */
225 purge_time = time(NULL) + 15 * 60; 225 purge_time = time(NULL) + 10 * 60;
226 226
227 srv_log(xs_fmt("queue thread start")); 227 srv_log(xs_fmt("queue thread start"));
228 228