summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2022-11-26 19:19:52 +0100
committerGravatar default2022-11-26 19:19:52 +0100
commite8c487add7487adcc8eee0b86c7d78bf94fb3311 (patch)
tree924d9f8e4a1b05abd794ed57dbc6b80fd3f4583f /data.c
parenttimeline_top_level() works. (diff)
downloadsnac2-e8c487add7487adcc8eee0b86c7d78bf94fb3311.tar.gz
snac2-e8c487add7487adcc8eee0b86c7d78bf94fb3311.tar.xz
snac2-e8c487add7487adcc8eee0b86c7d78bf94fb3311.zip
Added some tweaks to file locking.
Diffstat (limited to 'data.c')
-rw-r--r--data.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/data.c b/data.c
index 196347c..f780de2 100644
--- a/data.c
+++ b/data.c
@@ -218,6 +218,9 @@ int index_add_md5(const char *fn, const char *md5)
218 if ((f = fopen(fn, "a")) != NULL) { 218 if ((f = fopen(fn, "a")) != NULL) {
219 flock(fileno(f), LOCK_EX); 219 flock(fileno(f), LOCK_EX);
220 220
221 /* ensure the position is at the end after getting the lock */
222 fseek(f, 0, SEEK_END);
223
221 fprintf(f, "%s\n", md5); 224 fprintf(f, "%s\n", md5);
222 fclose(f); 225 fclose(f);
223 } 226 }
@@ -314,6 +317,8 @@ int index_first(const char *fn, char *line, int size)
314 int ret = 0; 317 int ret = 0;
315 318
316 if ((f = fopen(fn, "r")) != NULL) { 319 if ((f = fopen(fn, "r")) != NULL) {
320 flock(fileno(f), LOCK_SH);
321
317 if (fgets(line, size, f) != NULL) { 322 if (fgets(line, size, f) != NULL) {
318 line[32] = '\0'; 323 line[32] = '\0';
319 ret = 1; 324 ret = 1;
@@ -786,6 +791,9 @@ int timeline_del(snac *snac, char *id)
786 object_user_cache_del(snac, id, "public"); 791 object_user_cache_del(snac, id, "public");
787 object_user_cache_del(snac, id, "private"); 792 object_user_cache_del(snac, id, "private");
788 793
794 /* NOTE: this is a good place to count the # of links
795 of the object and object_del() it if it's < 2 */
796
789 return ret; 797 return ret;
790} 798}
791 799