Add test for creating a symlink node and change to using lstat

instead of `stat` to check file type.
This commit is contained in:
Nathan Fisher 2023-09-15 01:49:16 -04:00
parent ee7c9b1b5d
commit 7671e9e29e
5 changed files with 26 additions and 1 deletions

View file

@ -530,7 +530,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_linkmap *
node = calloc(1, sizeof(haggis_node));
if (node == NULL) return NULL;
if (stat(file, &st) != 0) {
if (lstat(file, &st) != 0) {
free(node);
return NULL;
}

View file

@ -66,6 +66,7 @@ tests += fnv1a_hash_str
tests += linkmap_init
tests += linkmap_put
tests += create_dir_node
tests += create_symlink_node
total != echo $(tests) | wc -w | awk '{ print $$1 }'

View file

@ -16,4 +16,5 @@ int main() {
assert(memcmp(path, node->name.name, 6) == 0);
haggis_node_deinit(node);
haggis_linkmap_deinit(map);
return 0;
}

View file

@ -0,0 +1,23 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "haggis.h"
int main() {
haggis_linkmap *map;
haggis_node *node;
char *path = "output/dev";
map = haggis_linkmap_init();
assert(map != NULL);
symlink("device", "output/dev");
node = haggis_create_node(path, sha256, map);
assert(node->filetype.tag == softlink);
assert(memcmp(path, node->name.name, 10) == 0);
assert(memcmp(node->filetype.f_type.target.name, "device", 6) == 0);
haggis_node_deinit(node);
haggis_linkmap_deinit(map);
return 0;
}

Binary file not shown.