diff options
| -rw-r--r-- | data.c | 32 |
1 files changed, 2 insertions, 30 deletions
| @@ -244,32 +244,11 @@ double mtime_nl(const char *fn, int *n_link) | |||
| 244 | /** indexes **/ | 244 | /** indexes **/ |
| 245 | 245 | ||
| 246 | 246 | ||
| 247 | FILE *index_lock(const char *fn) | ||
| 248 | { | ||
| 249 | xs *lck = xs_fmt("%s.lck", fn); | ||
| 250 | FILE *f = fopen(lck, "a"); | ||
| 251 | flock(fileno(f), LOCK_EX); | ||
| 252 | |||
| 253 | return f; | ||
| 254 | } | ||
| 255 | |||
| 256 | |||
| 257 | void index_unlock(FILE *f, const char *fn) | ||
| 258 | { | ||
| 259 | xs *lck = xs_fmt("%s.lck", fn); | ||
| 260 | unlink(lck); | ||
| 261 | fclose(f); | ||
| 262 | } | ||
| 263 | |||
| 264 | |||
| 265 | int index_add_md5(const char *fn, const char *md5) | 247 | int index_add_md5(const char *fn, const char *md5) |
| 266 | /* adds an md5 to an index */ | 248 | /* adds an md5 to an index */ |
| 267 | { | 249 | { |
| 268 | int status = 201; /* Created */ | 250 | int status = 201; /* Created */ |
| 269 | FILE *l, *f; | 251 | FILE *f; |
| 270 | |||
| 271 | if ((l = index_lock(fn)) == NULL) | ||
| 272 | return 500; | ||
| 273 | 252 | ||
| 274 | if ((f = fopen(fn, "a")) != NULL) { | 253 | if ((f = fopen(fn, "a")) != NULL) { |
| 275 | flock(fileno(f), LOCK_EX); | 254 | flock(fileno(f), LOCK_EX); |
| @@ -283,8 +262,6 @@ int index_add_md5(const char *fn, const char *md5) | |||
| 283 | else | 262 | else |
| 284 | status = 500; | 263 | status = 500; |
| 285 | 264 | ||
| 286 | index_unlock(l, fn); | ||
| 287 | |||
| 288 | return status; | 265 | return status; |
| 289 | } | 266 | } |
| 290 | 267 | ||
| @@ -301,10 +278,7 @@ int index_del_md5(const char *fn, const char *md5) | |||
| 301 | /* deletes an md5 from an index */ | 278 | /* deletes an md5 from an index */ |
| 302 | { | 279 | { |
| 303 | int status = 404; | 280 | int status = 404; |
| 304 | FILE *l, *i, *o; | 281 | FILE *i, *o; |
| 305 | |||
| 306 | if ((l = index_lock(fn)) == NULL) | ||
| 307 | return 500; | ||
| 308 | 282 | ||
| 309 | if ((i = fopen(fn, "r")) != NULL) { | 283 | if ((i = fopen(fn, "r")) != NULL) { |
| 310 | flock(fileno(i), LOCK_EX); | 284 | flock(fileno(i), LOCK_EX); |
| @@ -335,8 +309,6 @@ int index_del_md5(const char *fn, const char *md5) | |||
| 335 | else | 309 | else |
| 336 | status = 500; | 310 | status = 500; |
| 337 | 311 | ||
| 338 | index_unlock(l, fn); | ||
| 339 | |||
| 340 | return status; | 312 | return status; |
| 341 | } | 313 | } |
| 342 | 314 | ||