summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-25 13:51:56 +0100
committerdefault <nobody@localhost>2022-11-25 13:51:56 +0100
commitee75b3f5f62e077c65aa2edbbbecc38e169b2e9d (patch)
treeee99526a8fc384bd316f9d72897c9328a7da5bcc /data.c
parent2d7c327cbf08a7ebc12df2818289af5d923c48de (diff)
In purge_server(), don't purge objects with 2 (or more) hard links.
This way, an object can be protected from the purge by creating a hard link to it.
Diffstat (limited to 'data.c')
-rw-r--r--data.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/data.c b/data.c
index bb31096..08f7e2d 100644
--- a/data.c
+++ b/data.c
@@ -1492,11 +1492,13 @@ d_char *dequeue(snac *snac, char *fn)
}
-static void _purge_file(const char *fn, int days)
+static void _purge_file(const char *fn, int days, int n_link)
+/* purge fn if it's older than days and has less than n_link hard links */
{
time_t mt = time(NULL) - days * 24 * 3600;
+ int nl;
- if (mtime(fn) < mt) {
+ if (mtime_nl(fn, &nl) < mt && nl < n_link) {
/* older than the minimum time: delete it */
unlink(fn);
srv_debug(1, xs_fmt("purged %s", fn));
@@ -1514,7 +1516,7 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
p = list;
while (xs_list_iter(&p, &v))
- _purge_file(v, days);
+ _purge_file(v, days, XS_ALL);
}
}
@@ -1523,7 +1525,6 @@ 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;
@@ -1536,7 +1537,7 @@ void purge_server(void)
p2 = files;
while (xs_list_iter(&p2, &v2)) {
- _purge_file(v2, tpd);
+ _purge_file(v2, tpd, 2);
}
}
}
@@ -1559,8 +1560,6 @@ void purge_user(snac *snac)
void purge_all(void)
/* purge all users */
{
- purge_server();
-
snac snac;
xs *list = user_list();
char *p, *uid;
@@ -1572,4 +1571,6 @@ void purge_all(void)
user_free(&snac);
}
}
+
+ purge_server();
}