|
|
@@ -244,32 +244,11 @@ double mtime_nl(const char *fn, int *n_link)
|
|
|
/** indexes **/
|
|
|
|
|
|
|
|
|
-FILE *index_lock(const char *fn)
|
|
|
-{
|
|
|
- xs *lck = xs_fmt("%s.lck", fn);
|
|
|
- FILE *f = fopen(lck, "a");
|
|
|
- flock(fileno(f), LOCK_EX);
|
|
|
-
|
|
|
- return f;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void index_unlock(FILE *f, const char *fn)
|
|
|
-{
|
|
|
- xs *lck = xs_fmt("%s.lck", fn);
|
|
|
- unlink(lck);
|
|
|
- fclose(f);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
int index_add_md5(const char *fn, const char *md5)
|
|
|
/* adds an md5 to an index */
|
|
|
{
|
|
|
int status = 201; /* Created */
|
|
|
- FILE *l, *f;
|
|
|
-
|
|
|
- if ((l = index_lock(fn)) == NULL)
|
|
|
- return 500;
|
|
|
+ FILE *f;
|
|
|
|
|
|
if ((f = fopen(fn, "a")) != NULL) {
|
|
|
flock(fileno(f), LOCK_EX);
|
|
|
@@ -283,8 +262,6 @@ int index_add_md5(const char *fn, const char *md5)
|
|
|
else
|
|
|
status = 500;
|
|
|
|
|
|
- index_unlock(l, fn);
|
|
|
-
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
@@ -301,10 +278,7 @@ int index_del_md5(const char *fn, const char *md5)
|
|
|
/* deletes an md5 from an index */
|
|
|
{
|
|
|
int status = 404;
|
|
|
- FILE *l, *i, *o;
|
|
|
-
|
|
|
- if ((l = index_lock(fn)) == NULL)
|
|
|
- return 500;
|
|
|
+ FILE *i, *o;
|
|
|
|
|
|
if ((i = fopen(fn, "r")) != NULL) {
|
|
|
flock(fileno(i), LOCK_EX);
|
|
|
@@ -335,8 +309,6 @@ int index_del_md5(const char *fn, const char *md5)
|
|
|
else
|
|
|
status = 500;
|
|
|
|
|
|
- index_unlock(l, fn);
|
|
|
-
|
|
|
return status;
|
|
|
}
|
|
|
|