summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-24 13:06:28 +0100
committerdefault <nobody@localhost>2022-11-24 13:06:28 +0100
commit8be8a9282e0c552256ed95eded9364759db80c53 (patch)
tree1c90b5f32c13b4f68d8e70d1f3964d808382f59a /data.c
parent233ba75d1edfde60dd73474dc7f962f00fdd1580 (diff)
New function index_in().
Diffstat (limited to 'data.c')
-rw-r--r--data.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/data.c b/data.c
index 6820537..316dca2 100644
--- a/data.c
+++ b/data.c
@@ -216,7 +216,6 @@ int index_add(const char *fn, const char *id)
/* adds an id to an index */
{
xs *md5 = xs_md5_hex(id, strlen(id));
-
return index_add_md5(fn, md5);
}
@@ -259,6 +258,39 @@ int index_del(const char *fn, const char *md5)
}
+int index_in_md5(const char *fn, const char *md5)
+/* checks if the md5 is already in the index */
+{
+ FILE *f;
+ int ret = 0;
+
+ if ((f = fopen(fn, "r")) != NULL) {
+ flock(fileno(f), LOCK_SH);
+
+ char line[256];
+
+ while (!ret && fgets(line, sizeof(line), f) != NULL) {
+ line[32] = '\0';
+
+ if (strcmp(line, md5) == 0)
+ ret = 1;
+ }
+
+ fclose(f);
+ }
+
+ return ret;
+}
+
+
+int index_in(const char *fn, const char *id)
+/* checks if the object id is already in the index */
+{
+ xs *md5 = xs_md5_hex(id, strlen(id));
+ return index_in_md5(fn, md5);
+}
+
+
d_char *index_list(const char *fn, int max)
/* returns an index as a list */
{