diff options
-rw-r--r-- | src/filesystem.c | 31 | ||||
-rw-r--r-- | src/filesystem.h | 8 | ||||
-rw-r--r-- | src/state.c | 17 | ||||
-rw-r--r-- | test/lilv_test_utils.c | 4 | ||||
-rw-r--r-- | test/test_filesystem.c | 33 |
5 files changed, 11 insertions, 82 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index ec13df3..548111f 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -356,34 +356,3 @@ lilv_create_temporary_directory(const char* pattern) return result; } - -int -lilv_create_directories(const char* dir_path) -{ - char* path = lilv_strdup(dir_path); - const size_t path_len = strlen(path); - size_t i = 1; - -#ifdef _WIN32 - if (is_windows_path(dir_path)) { - i = 3; - } -#endif - - char prev = path[0]; - for (; i <= path_len; ++i) { - const char c = path[i]; - if (lilv_is_dir_sep(c) || (c == '\0' && !lilv_is_dir_sep(prev))) { - path[i] = '\0'; - if (mkdir(path, 0755) && (errno != EEXIST || !lilv_is_directory(path))) { - free(path); - return errno; - } - path[i] = c; - } - prev = c; - } - - free(path); - return 0; -} diff --git a/src/filesystem.h b/src/filesystem.h index a1b8fd7..157b072 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -112,11 +112,3 @@ lilv_create_temporary_directory_in(const char* pattern, const char* parent); */ char* lilv_create_temporary_directory(const char* pattern); - -/** - Create the directory `dir_path` and any parent directories if necessary. - - @return Zero on success, or an `errno` error code. -*/ -int -lilv_create_directories(const char* dir_path); diff --git a/src/state.c b/src/state.c index bf112b4..bce4eaa 100644 --- a/src/state.c +++ b/src/state.c @@ -11,6 +11,7 @@ #include "zix/allocator.h" #include "zix/filesystem.h" #include "zix/path.h" +#include "zix/status.h" #include "zix/tree.h" #include "lv2/atom/atom.h" @@ -251,7 +252,7 @@ static char* make_path(LV2_State_Make_Path_Handle handle, const char* path) { LilvState* state = (LilvState*)handle; - lilv_create_directories(state->dir); + zix_create_directories(NULL, state->dir); return zix_path_join(NULL, state->dir, path); } @@ -287,10 +288,11 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path) // File created by plugin earlier path = lilv_path_relative_to(real_path, state->scratch_dir); if (state->copy_dir) { - int st = lilv_create_directories(state->copy_dir); + ZixStatus st = zix_create_directories(NULL, state->copy_dir); if (st) { - LILV_ERRORF( - "Error creating directory %s (%s)\n", state->copy_dir, strerror(st)); + LILV_ERRORF("Error creating directory %s (%s)\n", + state->copy_dir, + zix_strerror(st)); } char* cpath = zix_path_join(NULL, state->copy_dir, path); @@ -298,8 +300,9 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path) if (!copy || !zix_file_equals(NULL, real_path, copy)) { // No recent enough copy, make a new one free(copy); - copy = lilv_find_free_path(cpath, path_exists, NULL); - if ((st = lilv_copy_file(real_path, copy))) { + copy = lilv_find_free_path(cpath, path_exists, NULL); + int rc = 0; + if ((rc = lilv_copy_file(real_path, copy))) { LILV_ERRORF("Error copying state file %s (%s)\n", copy, strerror(st)); } } @@ -1223,7 +1226,7 @@ lilv_state_save(LilvWorld* world, const char* dir, const char* filename) { - if (!filename || !dir || lilv_create_directories(dir)) { + if (!filename || !dir || zix_create_directories(NULL, dir)) { return 1; } diff --git a/test/lilv_test_utils.c b/test/lilv_test_utils.c index cca6ac9..260390f 100644 --- a/test/lilv_test_utils.c +++ b/test/lilv_test_utils.c @@ -3,8 +3,6 @@ #include "lilv_test_utils.h" -#include "../src/filesystem.h" - #include "lilv/lilv.h" #include "serd/serd.h" #include "zix/allocator.h" @@ -73,7 +71,7 @@ create_bundle(LilvTestEnv* env, zix_free(NULL, test_dir); } - if (lilv_create_directories(env->test_bundle_path)) { + if (zix_create_directories(NULL, env->test_bundle_path)) { fprintf(stderr, "Failed to create directory '%s' (%s)\n", env->test_bundle_path, diff --git a/test/test_filesystem.c b/test/test_filesystem.c index 25f73ec..301a3d2 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -283,38 +283,6 @@ test_create_temporary_directory(void) free(path1); } -static void -test_create_directories(void) -{ - char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - - assert(lilv_is_directory(temp_dir)); - - char* const child_dir = zix_path_join(NULL, temp_dir, "child"); - char* const grandchild_dir = zix_path_join(NULL, child_dir, "grandchild"); - - assert(!lilv_create_directories(grandchild_dir)); - assert(lilv_is_directory(grandchild_dir)); - assert(lilv_is_directory(child_dir)); - - char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file"); - FILE* const f = fopen(file_path, "w"); - - fprintf(f, "test\n"); - fclose(f); - - assert(lilv_create_directories(file_path)); - - assert(!zix_remove(file_path)); - assert(!zix_remove(grandchild_dir)); - assert(!zix_remove(child_dir)); - assert(!zix_remove(temp_dir)); - free(file_path); - free(child_dir); - free(grandchild_dir); - free(temp_dir); -} - int main(void) { @@ -329,7 +297,6 @@ main(void) test_flock(); test_dir_for_each(); test_create_temporary_directory(); - test_create_directories(); return 0; } |