commit e8c487a

default  ·  2022-11-26 18:19:52 +0000 UTC
parent 2ad703e
Added some tweaks to file locking.
1 files changed,  +8, -0
M data.c
M data.c
+8, -0
 1@@ -218,6 +218,9 @@ int index_add_md5(const char *fn, const char *md5)
 2     if ((f = fopen(fn, "a")) != NULL) {
 3         flock(fileno(f), LOCK_EX);
 4 
 5+        /* ensure the position is at the end after getting the lock */
 6+        fseek(f, 0, SEEK_END);
 7+
 8         fprintf(f, "%s\n", md5);
 9         fclose(f);
10     }
11@@ -314,6 +317,8 @@ int index_first(const char *fn, char *line, int size)
12     int ret = 0;
13 
14     if ((f = fopen(fn, "r")) != NULL) {
15+        flock(fileno(f), LOCK_SH);
16+
17         if (fgets(line, size, f) != NULL) {
18             line[32] = '\0';
19             ret = 1;
20@@ -786,6 +791,9 @@ int timeline_del(snac *snac, char *id)
21     object_user_cache_del(snac, id, "public");
22     object_user_cache_del(snac, id, "private");
23 
24+    /* NOTE: this is a good place to count the # of links
25+       of the object and object_del() it if it's < 2 */
26+
27     return ret;
28 }
29