Return a valid target when adding to linkmap if it exists
This commit is contained in:
parent
e266346bf2
commit
e372af0c42
1 changed files with 9 additions and 2 deletions
11
linkmap.c
11
linkmap.c
|
@ -39,6 +39,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syslimits.h>
|
||||
|
||||
haggis_bucket* haggis_bucket_init(ino_t inode, uint64_t hash, char * path) {
|
||||
haggis_bucket *bucket;
|
||||
|
@ -58,12 +59,18 @@ void haggis_bucket_deinit(haggis_bucket *nod) {
|
|||
free(nod);
|
||||
}
|
||||
|
||||
void haggis_bucket_append(haggis_bucket *head, haggis_bucket *tail) {
|
||||
char* haggis_bucket_search_append(haggis_bucket *head, haggis_bucket *tail) {
|
||||
char* target;
|
||||
|
||||
while (head->next != NULL) {
|
||||
if (head->key.val == tail->key.val) {
|
||||
target = strndup(head->path, PATH_MAX - 1);
|
||||
return target;
|
||||
}
|
||||
head = head->next;
|
||||
}
|
||||
head->next = tail;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
haggis_linkmap* haggis_linkmap_init() {
|
||||
|
@ -131,7 +138,7 @@ char* haggis_linkmap_get_or_add(haggis_linkmap *map, ino_t inode, char * path) {
|
|||
} else {
|
||||
b = haggis_bucket_init(key.val, hash, path);
|
||||
if (b == NULL) return NULL;
|
||||
haggis_bucket_append(&map->buckets[idx], b);
|
||||
target = haggis_bucket_search_append(&map->buckets[idx], b);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue