New function object_add_ow().

This commit is contained in:
default 2022-11-26 05:18:48 +01:00
parent 17d4e4f5dd
commit 1243e26a0d
2 changed files with 21 additions and 5 deletions

View file

@ -65,7 +65,6 @@ int actor_request(snac *snac, char *actor, d_char **data)
if (valid_status(status2)) {
/* renew data */
object_del(actor);
status = actor_add(snac, actor, payload);
if (data != NULL) {
@ -918,7 +917,6 @@ int process_message(snac *snac, char *msg, char *req)
else
if (strcmp(type, "Update") == 0) {
if (strcmp(utype, "Person") == 0) {
object_del(actor);
actor_add(snac, actor, xs_dict_get(msg, "object"));
snac_log(snac, xs_fmt("updated actor %s", actor));

24
data.c
View file

@ -428,14 +428,14 @@ int object_get(const char *id, d_char **obj, const char *type)
}
int object_add(const char *id, d_char *obj)
int _object_add(const char *id, d_char *obj, int ow)
/* stores an object */
{
int status = 201; /* Created */
xs *fn = _object_fn(id);
FILE *f;
if (mtime(fn) > 0.0) {
if (!ow && mtime(fn) > 0.0) {
/* object already here */
srv_debug(0, xs_fmt("object_add object already here %s", id));
return 204; /* No content */
@ -471,6 +471,20 @@ int object_add(const char *id, d_char *obj)
}
int object_add(const char *id, d_char *obj)
/* stores an object */
{
return _object_add(id, obj, 0);
}
int object_add_ow(const char *id, d_char *obj)
/* stores an object (overwriting allowed) */
{
return _object_add(id, obj, 1);
}
int object_del_by_md5(const char *md5)
/* deletes an object by its md5 */
{
@ -1231,7 +1245,7 @@ int is_hidden(snac *snac, const char *id)
int actor_add(snac *snac, const char *actor, d_char *msg)
/* adds an actor */
{
return object_add(actor, msg);
return object_add_ow(actor, msg);
}
@ -1381,6 +1395,8 @@ d_char *history_list(snac *snac)
}
/** the queue **/
static int _enqueue_put(char *fn, char *msg)
/* writes safely to the queue */
{
@ -1527,6 +1543,8 @@ d_char *dequeue(snac *snac, char *fn)
}
/** the purge **/
static void _purge_file(const char *fn, time_t mt)
/* purge fn if it's older than days */
{