mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
purge_server() deletes using object_del().
This commit is contained in:
parent
9867f321b5
commit
afb970a757
2 changed files with 32 additions and 16 deletions
46
data.c
46
data.c
|
@ -380,7 +380,6 @@ d_char *_object_fn_by_md5(const char *md5)
|
||||||
d_char *_object_fn(const char *id)
|
d_char *_object_fn(const char *id)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(id, strlen(id));
|
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||||
|
|
||||||
return _object_fn_by_md5(md5);
|
return _object_fn_by_md5(md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +424,6 @@ int object_get(const char *id, d_char **obj, const char *type)
|
||||||
/* returns a stored object, optionally of the requested type */
|
/* returns a stored object, optionally of the requested type */
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(id, strlen(id));
|
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||||
|
|
||||||
return object_get_by_md5(md5, obj, type);
|
return object_get_by_md5(md5, obj, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,18 +471,18 @@ int object_add(const char *id, d_char *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int object_del(const char *id)
|
int object_del_by_md5(const char *md5)
|
||||||
/* deletes an object */
|
/* deletes an object by its md5 */
|
||||||
{
|
{
|
||||||
int status = 404;
|
int status = 404;
|
||||||
xs *fn = _object_fn(id);
|
xs *fn = _object_fn_by_md5(md5);
|
||||||
|
|
||||||
if (fn != NULL && unlink(fn) != -1) {
|
if (fn != NULL && unlink(fn) != -1) {
|
||||||
status = 200;
|
status = 200;
|
||||||
|
|
||||||
/* also delete associated indexes */
|
/* also delete associated indexes */
|
||||||
xs *spec = _object_fn(id);
|
xs *spec = xs_dup(fn);
|
||||||
spec = xs_replace_i(spec, ".json", "*.idx");
|
spec = xs_replace_i(spec, ".json", "*.idx");
|
||||||
xs *files = xs_glob(spec, 0, 0);
|
xs *files = xs_glob(spec, 0, 0);
|
||||||
char *p, *v;
|
char *p, *v;
|
||||||
|
|
||||||
|
@ -495,12 +493,20 @@ int object_del(const char *id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srv_debug(0, xs_fmt("object_del %s %d", id, status));
|
srv_debug(0, xs_fmt("object_del %s %d", fn, status));
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int object_del(const char *id)
|
||||||
|
/* deletes an object */
|
||||||
|
{
|
||||||
|
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||||
|
return object_del_by_md5(md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *object_children(const char *id)
|
d_char *object_children(const char *id)
|
||||||
/* returns the list of an object's children */
|
/* returns the list of an object's children */
|
||||||
{
|
{
|
||||||
|
@ -1521,13 +1527,12 @@ d_char *dequeue(snac *snac, char *fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _purge_file(const char *fn, int days, int n_link)
|
static void _purge_file(const char *fn, int days)
|
||||||
/* purge fn if it's older than days and has less than n_link hard links */
|
/* purge fn if it's older than days */
|
||||||
{
|
{
|
||||||
time_t mt = time(NULL) - days * 24 * 3600;
|
time_t mt = time(NULL) - days * 24 * 3600;
|
||||||
int nl;
|
|
||||||
|
|
||||||
if (mtime_nl(fn, &nl) < mt && nl < n_link) {
|
if (mtime(fn) < mt) {
|
||||||
/* older than the minimum time: delete it */
|
/* older than the minimum time: delete it */
|
||||||
unlink(fn);
|
unlink(fn);
|
||||||
srv_debug(1, xs_fmt("purged %s", fn));
|
srv_debug(1, xs_fmt("purged %s", fn));
|
||||||
|
@ -1545,7 +1550,7 @@ static void _purge_subdir(snac *snac, const char *subdir, int days)
|
||||||
|
|
||||||
p = list;
|
p = list;
|
||||||
while (xs_list_iter(&p, &v))
|
while (xs_list_iter(&p, &v))
|
||||||
_purge_file(v, days, XS_ALL);
|
_purge_file(v, days);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1558,15 +1563,26 @@ void purge_server(void)
|
||||||
xs *dirs = xs_glob(spec, 0, 0);
|
xs *dirs = xs_glob(spec, 0, 0);
|
||||||
char *p, *v;
|
char *p, *v;
|
||||||
|
|
||||||
|
time_t mt = time(NULL) - tpd * 24 * 3600;
|
||||||
|
|
||||||
p = dirs;
|
p = dirs;
|
||||||
while (xs_list_iter(&p, &v)) {
|
while (xs_list_iter(&p, &v)) {
|
||||||
xs *spec2 = xs_fmt("%s/" "*", v);
|
xs *spec2 = xs_fmt("%s/" "*.json", v);
|
||||||
xs *files = xs_glob(spec2, 0, 0);
|
xs *files = xs_glob(spec2, 0, 0);
|
||||||
char *p2, *v2;
|
char *p2, *v2;
|
||||||
|
|
||||||
p2 = files;
|
p2 = files;
|
||||||
while (xs_list_iter(&p2, &v2)) {
|
while (xs_list_iter(&p2, &v2)) {
|
||||||
_purge_file(v2, tpd, 2);
|
int n_link;
|
||||||
|
|
||||||
|
/* old and with no hard links? */
|
||||||
|
if (mtime_nl(v2, &n_link) < mt && n_link < 2) {
|
||||||
|
xs *s1 = xs_replace(v2, ".json", "");
|
||||||
|
xs *l = xs_split(s1, "/");
|
||||||
|
char *md5 = xs_list_get(l, -1);
|
||||||
|
|
||||||
|
object_del_by_md5(md5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
httpd.c
2
httpd.c
|
@ -222,7 +222,7 @@ static void *queue_thread(void *arg)
|
||||||
time_t purge_time;
|
time_t purge_time;
|
||||||
|
|
||||||
/* first purge time */
|
/* first purge time */
|
||||||
purge_time = time(NULL) + 15 * 60;
|
purge_time = time(NULL) + 10 * 60;
|
||||||
|
|
||||||
srv_log(xs_fmt("queue thread start"));
|
srv_log(xs_fmt("queue thread start"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue