From 675a030f661ccce240d0f380bcd5a5ca105914ad Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Sun, 4 Feb 2024 00:02:59 -0500 Subject: [PATCH 1/2] Fix issues around extracting symlinks which only showed up when using Musl libc --- haggis.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/haggis.c b/haggis.c index 820a194..f7bc1a0 100644 --- a/haggis.c +++ b/haggis.c @@ -355,8 +355,6 @@ int haggis_load_file(FILE *stream, haggis_file *f) { return -1; int res = fread(f->data, 1, (size_t)f->len.val, stream); if (res != (size_t)f->len.val) { - fprintf(stderr, "Error reading file:\n length: %i\n expected: %lu\n", - res, f->len.val); free(f->data); return 1; } @@ -751,6 +749,8 @@ int haggis_extract_dev(haggis_node *node, char *basedir) { } else if (node->filetype.tag == character) { mode = (mode_t)node->mode.val | S_IFCHR; } + if (access(path, F_OK) == 0) + unlink(path); ret = mknod(path, mode, dev); free(path); return ret; @@ -782,6 +782,7 @@ int haggis_extract_fifo(haggis_node *node, char *basedir) { int haggis_extract_symlink(haggis_node *node, char *basedir) { char *path, *target; int ret; + struct stat st; assert(node->filetype.tag == softlink); path = get_full_path(&node->name, basedir); @@ -792,8 +793,8 @@ int haggis_extract_symlink(haggis_node *node, char *basedir) { return 2; } target = node->filetype.f_type.target.name; - if (access(path, F_OK) == 0) - unlink(path); + if (lstat(path, &st) == 0) + unlink(path); ret = symlink(target, path); free(path); if (ret != 0) @@ -870,7 +871,7 @@ char* haggis_extract_file(haggis_node *node, char *basedir) { free(path); return NULL; } - fd = fopen(path, "w"); + fd = fopen(path, "w+"); if (fd == NULL) { free(path); return NULL; @@ -938,7 +939,8 @@ int haggis_extract_node(char *basedir, haggis_node *node, haggis_mq *mq) { return errno; } } - ret = chmod(path, (mode_t)node->mode.val); + if (node->filetype.tag != softlink) + ret = chmod(path, (mode_t)node->mode.val); if (ret) return ret; msg = calloc(1, sizeof(haggis_msg)); if (msg == NULL) From 06a7c65324b3b978f6b0c75b50eb252dcb3967f1 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Sun, 4 Feb 2024 00:26:49 -0500 Subject: [PATCH 2/2] Add info to README about using dash shell --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c7c3a7a..dd9329f 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ the `Destdir` pattern for ease of packaging. There is a simple test harness which can be invoked via `make test`. If you wish to port this software to an untested platform the tests will greatly assist in that process. +> Note: if your OS uses **dash** as `/bin/sh` then the builtin echo command will not +> be up to the task of printing the escape sequences used by the test runner. If this +> bothers you, you can call `make` with the `SHELL` environment variable overridden +> by calling `make SHELL=/bin/bash all test`. ## Contributing Contributions are always welcome and can be made via pull request or `git send-email`,