diff options
author | David Robillard <d@drobilla.net> | 2022-11-12 18:10:14 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-11-16 10:22:55 -0500 |
commit | 6fe4c50fee3adf77f9ef18e89445a043db281eb8 (patch) | |
tree | 2a8872aba4075b0abd8c0a6d8a9001dcdcab0b16 | |
parent | d9feb39a41cf3d0dfc4c797f1a7aee99d8609c16 (diff) | |
download | lilv-6fe4c50fee3adf77f9ef18e89445a043db281eb8.tar.gz lilv-6fe4c50fee3adf77f9ef18e89445a043db281eb8.tar.bz2 lilv-6fe4c50fee3adf77f9ef18e89445a043db281eb8.zip |
Remove filesystem module
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | src/filesystem.c | 36 | ||||
-rw-r--r-- | src/filesystem.h | 17 | ||||
-rw-r--r-- | src/state.c | 20 | ||||
-rw-r--r-- | test/lilv_test_utils.c | 13 | ||||
-rw-r--r-- | test/lilv_test_utils.h | 4 | ||||
-rw-r--r-- | test/meson.build | 1 | ||||
-rw-r--r-- | test/test_filesystem.c | 35 | ||||
-rw-r--r-- | test/test_state.c | 2 | ||||
-rw-r--r-- | test/test_util.c | 2 |
10 files changed, 33 insertions, 98 deletions
diff --git a/meson.build b/meson.build index aecfbda..47f9c56 100644 --- a/meson.build +++ b/meson.build @@ -105,7 +105,6 @@ cpp_headers = files('include/lilv/lilvmm.hpp') sources = files( 'src/collections.c', - 'src/filesystem.c', 'src/instance.c', 'src/lib.c', 'src/node.c', diff --git a/src/filesystem.c b/src/filesystem.c deleted file mode 100644 index 945751f..0000000 --- a/src/filesystem.c +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2007-2021 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#include "filesystem.h" - -#include "zix/allocator.h" -#include "zix/filesystem.h" -#include "zix/path.h" - -#include <stdbool.h> -#include <stdio.h> -#include <string.h> - -bool -lilv_path_is_child(const char* path, const char* dir) -{ - if (path && dir) { - const size_t path_len = strlen(path); - const size_t dir_len = strlen(dir); - return dir && path_len >= dir_len && !strncmp(path, dir, dir_len); - } - return false; -} - -char* -lilv_create_temporary_directory(const char* pattern) -{ - char* const tmpdir = zix_temp_directory_path(NULL); - char* const path_pattern = zix_path_join(NULL, tmpdir, pattern); - char* const result = zix_create_temporary_directory(NULL, path_pattern); - - zix_free(NULL, path_pattern); - zix_free(NULL, tmpdir); - - return result; -} diff --git a/src/filesystem.h b/src/filesystem.h deleted file mode 100644 index acc8845..0000000 --- a/src/filesystem.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2007-2020 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#include <stdbool.h> - -/// Return true iff `path` is a child of `dir` -bool -lilv_path_is_child(const char* path, const char* dir); - -/** - Create a unique temporary directory. - - This is like lilv_create_temporary_directory_in(), except it creates the - directory in the system temporary directory. -*/ -char* -lilv_create_temporary_directory(const char* pattern); diff --git a/src/state.c b/src/state.c index 63b26e6..58aebf6 100644 --- a/src/state.c +++ b/src/state.c @@ -1,7 +1,6 @@ // Copyright 2007-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#include "filesystem.h" #include "lilv_internal.h" #include "lilv/lilv.h" @@ -258,6 +257,17 @@ make_path(LV2_State_Make_Path_Handle handle, const char* path) return zix_path_join(NULL, state->dir, path); } +static bool +path_is_child(const char* path, const char* dir) +{ + if (path && dir) { + const size_t path_len = strlen(path); + const size_t dir_len = strlen(dir); + return dir && path_len >= dir_len && !strncmp(path, dir, dir_len); + } + return false; +} + static char* abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path) { @@ -282,10 +292,10 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path) return lilv_strdup(pm->rel); } - if (lilv_path_is_child(real_path, state->dir)) { + if (path_is_child(real_path, state->dir)) { // File in state directory (loaded, or created by plugin during save) path = zix_path_lexically_relative(NULL, real_path, state->dir); - } else if (lilv_path_is_child(real_path, state->scratch_dir)) { + } else if (path_is_child(real_path, state->scratch_dir)) { // File created by plugin earlier path = zix_path_lexically_relative(NULL, real_path, state->scratch_dir); if (state->copy_dir) { @@ -1193,11 +1203,11 @@ lilv_state_make_links(const LilvState* state, const char* dir) const PathMap* const pm = (const PathMap*)zix_tree_get(i); char* const path = zix_path_join(NULL, dir, pm->rel); - if (lilv_path_is_child(pm->abs, state->copy_dir) && + if (path_is_child(pm->abs, state->copy_dir) && strcmp(state->copy_dir, dir)) { // Link directly to snapshot in the copy directory maybe_symlink(pm->abs, path); - } else if (!lilv_path_is_child(pm->abs, dir)) { + } else if (!path_is_child(pm->abs, dir)) { const char* link_dir = state->link_dir ? state->link_dir : dir; char* pat = zix_path_join(NULL, link_dir, pm->rel); diff --git a/test/lilv_test_utils.c b/test/lilv_test_utils.c index 260390f..c3c47f0 100644 --- a/test/lilv_test_utils.c +++ b/test/lilv_test_utils.c @@ -176,3 +176,16 @@ set_env(const char* name, const char* value) setenv(name, value, 1); #endif } + +char* +lilv_create_temporary_directory(const char* pattern) +{ + char* const tmpdir = zix_temp_directory_path(NULL); + char* const path_pattern = zix_path_join(NULL, tmpdir, pattern); + char* const result = zix_create_temporary_directory(NULL, path_pattern); + + zix_free(NULL, path_pattern); + zix_free(NULL, tmpdir); + + return result; +} diff --git a/test/lilv_test_utils.h b/test/lilv_test_utils.h index 1697a9b..f01b5b4 100644 --- a/test/lilv_test_utils.h +++ b/test/lilv_test_utils.h @@ -79,4 +79,8 @@ delete_bundle(LilvTestEnv* env); void set_env(const char* name, const char* value); +// Create a unique temporary directory +char* +lilv_create_temporary_directory(const char* pattern); + #endif // LILV_TEST_UTILS_H diff --git a/test/meson.build b/test/meson.build index aa6ca2d..a8fe184 100644 --- a/test/meson.build +++ b/test/meson.build @@ -62,7 +62,6 @@ unit_tests = [ 'bad_port_symbol', 'classes', 'discovery', - 'filesystem', 'get_symbol', 'no_author', 'no_verify', diff --git a/test/test_filesystem.c b/test/test_filesystem.c deleted file mode 100644 index 2afbfda..0000000 --- a/test/test_filesystem.c +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#undef NDEBUG - -#include "../src/filesystem.h" - -#include <assert.h> - -static void -test_path_is_child(void) -{ - assert(lilv_path_is_child("/a/b", "/a")); - assert(lilv_path_is_child("/a/b", "/a/")); - assert(lilv_path_is_child("/a/b/", "/a")); - assert(lilv_path_is_child("/a/b/", "/a/")); - - assert(!lilv_path_is_child("/a/b", "/a/c")); - assert(!lilv_path_is_child("/a/b", "/a/c/")); - assert(!lilv_path_is_child("/a/b/", "/a/c")); - assert(!lilv_path_is_child("/a/b/", "/a/c/")); - - assert(!lilv_path_is_child("/a/b", "/c")); - assert(!lilv_path_is_child("/a/b", "/c/")); - assert(!lilv_path_is_child("/a/b/", "/c")); - assert(!lilv_path_is_child("/a/b/", "/c/")); -} - -int -main(void) -{ - test_path_is_child(); - - return 0; -} diff --git a/test/test_state.c b/test/test_state.c index f29949e..798fb6e 100644 --- a/test/test_state.c +++ b/test/test_state.c @@ -6,8 +6,6 @@ #include "lilv_test_uri_map.h" #include "lilv_test_utils.h" -#include "../src/filesystem.h" - #include "lilv/lilv.h" #include "lv2/core/lv2.h" #include "lv2/state/state.h" diff --git a/test/test_util.c b/test/test_util.c index 2e5b2fb..2e609da 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -3,7 +3,7 @@ #undef NDEBUG -#include "../src/filesystem.h" +#include "lilv_test_utils.h" #include "lilv/lilv.h" #include "zix/filesystem.h" |