diff --git a/haggis.c b/haggis.c index 9ab43e1..b743bdc 100644 --- a/haggis.c +++ b/haggis.c @@ -651,6 +651,9 @@ haggis_node* haggis_create_node( return NULL; } else if (S_ISDIR(st.st_mode)) { node->filetype.tag = directory; + body.f_name = strndup(file, PATH_MAX); + msg = haggis_msg_init(NodeCreated, body); + haggis_mq_push(mq, msg); } else if (S_ISFIFO(st.st_mode)) { node->filetype.tag = fifo; if (st.st_nlink > 1) { diff --git a/test/Makefile b/test/Makefile index 8c94194..520573a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -72,6 +72,7 @@ tests += create_dev_node tests += create_file_node tests += mq_push_pop tests += extract_dev_node +tests += extract_dir_node total != echo $(tests) | wc -w | awk '{ print $$1 }' diff --git a/test/extract_dev_node.c b/test/extract_dev_node.c index 87bc0dd..6b376c5 100644 --- a/test/extract_dev_node.c +++ b/test/extract_dev_node.c @@ -14,7 +14,7 @@ int main() { haggis_linkmap *map = NULL; haggis_mq mq; haggis_msg *msg; - char *path = "/dev/null", *msg_text; + char *path = "/dev/null"; int ret = 0; if (geteuid() != 0) diff --git a/test/extract_dir_node.c b/test/extract_dir_node.c new file mode 100644 index 0000000..3d870a8 --- /dev/null +++ b/test/extract_dir_node.c @@ -0,0 +1,36 @@ +#include +#include +#include + +#include "haggis.h" +#include "mq.h" + +int main() { + haggis_node *node = NULL; + haggis_linkmap *map = NULL; + haggis_mq mq; + haggis_msg *msg = NULL; + char *path = "output"; + int ret = 0; + + map = haggis_linkmap_init(); + assert(map != NULL); + assert(haggis_mq_init(&mq) == 0); + node = haggis_create_node(path, skip, map, &mq); + assert(node != NULL); + assert(node->filetype.tag == directory); + assert(memcmp(node->name.name, path, 6) == 0); + msg = haggis_mq_pop(&mq); + assert(msg->tag == NodeCreated); + assert(memcmp(msg->body.f_name, path, 6) == 0); + haggis_msg_deinit(msg); + ret = haggis_extract_node("output/extracted", node, &mq); + assert(ret == 0); + msg = haggis_mq_pop(&mq); + assert(msg->tag == NodeExtracted); + assert(memcmp(msg->body.f_name, path, 6) == 0); + haggis_msg_deinit(msg); + haggis_node_deinit(node); + haggis_linkmap_deinit(map); + return 0; +} \ No newline at end of file