mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Added some tweaks to file locking.
This commit is contained in:
parent
2ad703e520
commit
e8c487add7
1 changed files with 8 additions and 0 deletions
8
data.c
8
data.c
|
@ -218,6 +218,9 @@ int index_add_md5(const char *fn, const char *md5)
|
|||
if ((f = fopen(fn, "a")) != NULL) {
|
||||
flock(fileno(f), LOCK_EX);
|
||||
|
||||
/* ensure the position is at the end after getting the lock */
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
fprintf(f, "%s\n", md5);
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -314,6 +317,8 @@ int index_first(const char *fn, char *line, int size)
|
|||
int ret = 0;
|
||||
|
||||
if ((f = fopen(fn, "r")) != NULL) {
|
||||
flock(fileno(f), LOCK_SH);
|
||||
|
||||
if (fgets(line, size, f) != NULL) {
|
||||
line[32] = '\0';
|
||||
ret = 1;
|
||||
|
@ -786,6 +791,9 @@ int timeline_del(snac *snac, char *id)
|
|||
object_user_cache_del(snac, id, "public");
|
||||
object_user_cache_del(snac, id, "private");
|
||||
|
||||
/* NOTE: this is a good place to count the # of links
|
||||
of the object and object_del() it if it's < 2 */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue