diff options
| -rw-r--r-- | data.c | 26 |
1 files changed, 20 insertions, 6 deletions
| @@ -1661,7 +1661,7 @@ static int _purge_file(const char *fn, time_t mt) | |||
| 1661 | if (mtime(fn) < mt) { | 1661 | if (mtime(fn) < mt) { |
| 1662 | /* older than the minimum time: delete it */ | 1662 | /* older than the minimum time: delete it */ |
| 1663 | unlink(fn); | 1663 | unlink(fn); |
| 1664 | srv_debug(1, xs_fmt("purged %s", fn)); | 1664 | srv_debug(2, xs_fmt("purged %s", fn)); |
| 1665 | ret = 1; | 1665 | ret = 1; |
| 1666 | } | 1666 | } |
| 1667 | 1667 | ||
| @@ -1669,23 +1669,33 @@ static int _purge_file(const char *fn, time_t mt) | |||
| 1669 | } | 1669 | } |
| 1670 | 1670 | ||
| 1671 | 1671 | ||
| 1672 | static void _purge_user_subdir(snac *snac, const char *subdir, int days) | 1672 | static void _purge_dir(const char *dir, int days) |
| 1673 | /* purges all files in subdir older than days */ | 1673 | /* purges all files in a directory older than days */ |
| 1674 | { | 1674 | { |
| 1675 | int cnt = 0; | 1675 | int cnt = 0; |
| 1676 | 1676 | ||
| 1677 | if (days) { | 1677 | if (days) { |
| 1678 | time_t mt = time(NULL) - days * 24 * 3600; | 1678 | time_t mt = time(NULL) - days * 24 * 3600; |
| 1679 | xs *spec = xs_fmt("%s/%s/" "*", snac->basedir, subdir); | 1679 | xs *spec = xs_fmt("%s/" "*", dir); |
| 1680 | xs *list = xs_glob(spec, 0, 0); | 1680 | xs *list = xs_glob(spec, 0, 0); |
| 1681 | char *p, *v; | 1681 | xs_list *p; |
| 1682 | xs_str *v; | ||
| 1682 | 1683 | ||
| 1683 | p = list; | 1684 | p = list; |
| 1684 | while (xs_list_iter(&p, &v)) | 1685 | while (xs_list_iter(&p, &v)) |
| 1685 | cnt += _purge_file(v, mt); | 1686 | cnt += _purge_file(v, mt); |
| 1687 | |||
| 1688 | srv_debug(1, xs_fmt("purge: %s %d", dir, cnt)); | ||
| 1686 | } | 1689 | } |
| 1690 | } | ||
| 1691 | |||
| 1687 | 1692 | ||
| 1688 | snac_debug(snac, 1, xs_fmt("purge: ~/%s/ %d", subdir, cnt)); | 1693 | static void _purge_user_subdir(snac *snac, const char *subdir, int days) |
| 1694 | /* purges all files in a user subdir older than days */ | ||
| 1695 | { | ||
| 1696 | xs *u_subdir = xs_fmt("%s/%s", snac->basedir, subdir); | ||
| 1697 | |||
| 1698 | _purge_dir(u_subdir, days); | ||
| 1689 | } | 1699 | } |
| 1690 | 1700 | ||
| 1691 | 1701 | ||
| @@ -1755,6 +1765,10 @@ void purge_server(void) | |||
| 1755 | } | 1765 | } |
| 1756 | } | 1766 | } |
| 1757 | 1767 | ||
| 1768 | /* purge collected inboxes */ | ||
| 1769 | xs *ib_dir = xs_fmt("%s/inbox", srv_basedir); | ||
| 1770 | _purge_dir(ib_dir, 7); | ||
| 1771 | |||
| 1758 | srv_debug(1, xs_fmt("purge: global (obj: %d, idx: %d)", cnt, icnt)); | 1772 | srv_debug(1, xs_fmt("purge: global (obj: %d, idx: %d)", cnt, icnt)); |
| 1759 | } | 1773 | } |
| 1760 | 1774 | ||