From 71dc3b58c39ba71af6bf41863ffa7c70e076d57b Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Tue, 3 Sep 2024 10:21:39 +0200 Subject: [PATCH] np2_test BUGFIX create test repo dir recursively It can be customized and include more dirs. --- tests/np2_test.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/np2_test.c b/tests/np2_test.c index db326b5b..f510e652 100644 --- a/tests/np2_test.c +++ b/tests/np2_test.c @@ -58,6 +58,38 @@ parse_arg(int argc, char **argv) } } +static int +mkpath(char *path, mode_t mode) +{ + int rc = 0; + char *p = NULL; + + /* create each directory in the path */ + for (p = strchr(path + 1, '/'); p; p = strchr(p + 1, '/')) { + *p = '\0'; + if ((mkdir(path, mode) == -1) && (errno != EEXIST)) { + rc = -1; + goto cleanup; + } + + errno = 0; + *p = '/'; + } + + /* create the last directory in the path */ + if ((mkdir(path, mode) == -1) && (errno != EEXIST)) { + rc = -1; + goto cleanup; + } + errno = 0; + +cleanup: + if (p) { + *p = '/'; + } + return rc; +} + void np2_glob_test_setup_test_name(char *buf) { @@ -293,7 +325,7 @@ np2_glob_test_setup_server(void **state, const char *test_name, const char **mod sprintf(extdata_path, "%s/%s", NP_TEST_MODULE_DIR, NP_EXT_DATA_FILE); /* create the test server dir */ - if ((mkdir(server_dir, 00700) == -1) && (errno != EEXIST)) { + if (mkpath(server_dir, 00700) == -1) { SETUP_FAIL_LOG; return 1; }