Add test for creating a symlink node and change to using lstat
instead of `stat` to check file type.
This commit is contained in:
parent
ee7c9b1b5d
commit
7671e9e29e
5 changed files with 26 additions and 1 deletions
2
haggis.c
2
haggis.c
|
@ -530,7 +530,7 @@ haggis_node* haggis_create_node(char *file, haggis_algorithm a, haggis_linkmap *
|
||||||
|
|
||||||
node = calloc(1, sizeof(haggis_node));
|
node = calloc(1, sizeof(haggis_node));
|
||||||
if (node == NULL) return NULL;
|
if (node == NULL) return NULL;
|
||||||
if (stat(file, &st) != 0) {
|
if (lstat(file, &st) != 0) {
|
||||||
free(node);
|
free(node);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ tests += fnv1a_hash_str
|
||||||
tests += linkmap_init
|
tests += linkmap_init
|
||||||
tests += linkmap_put
|
tests += linkmap_put
|
||||||
tests += create_dir_node
|
tests += create_dir_node
|
||||||
|
tests += create_symlink_node
|
||||||
|
|
||||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||||
|
|
||||||
|
|
|
@ -16,4 +16,5 @@ int main() {
|
||||||
assert(memcmp(path, node->name.name, 6) == 0);
|
assert(memcmp(path, node->name.name, 6) == 0);
|
||||||
haggis_node_deinit(node);
|
haggis_node_deinit(node);
|
||||||
haggis_linkmap_deinit(map);
|
haggis_linkmap_deinit(map);
|
||||||
|
return 0;
|
||||||
}
|
}
|
23
test/create_symlink_node.c
Normal file
23
test/create_symlink_node.c
Normal 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;
|
||||||
|
}
|
BIN
test/init_file
BIN
test/init_file
Binary file not shown.
Loading…
Add table
Reference in a new issue