diff options
author | David Robillard <d@drobilla.net> | 2020-08-04 16:07:48 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-06 17:34:19 +0200 |
commit | 18c8af55e63653c74d58137cd12434f1213f4230 (patch) | |
tree | 902c20f451ab01b30f91d218a9a291fb3190b085 /src | |
parent | dd521d78d1959d694e6e5a565a37e9693756cb00 (diff) | |
download | lilv-18c8af55e63653c74d58137cd12434f1213f4230.tar.gz lilv-18c8af55e63653c74d58137cd12434f1213f4230.tar.bz2 lilv-18c8af55e63653c74d58137cd12434f1213f4230.zip |
Rename some filename utilities for clarity
Loosely inspired by Python and the std::filesystem API.
Diffstat (limited to 'src')
-rw-r--r-- | src/filesystem.c | 10 | ||||
-rw-r--r-- | src/filesystem.h | 6 | ||||
-rw-r--r-- | src/state.c | 14 | ||||
-rw-r--r-- | src/util.c | 2 |
4 files changed, 16 insertions, 16 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index dbb528f..45ece12 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -149,7 +149,7 @@ lilv_path_relative_to(const char* path, const char* base) } char* -lilv_dirname(const char* path) +lilv_path_parent(const char* path) { const char* s = path + strlen(path) - 1; // Last character for (; s > path && lilv_is_dir_sep(*s); --s) {} // Last non-slash @@ -207,7 +207,7 @@ lilv_dir_path(const char* path) } char* -lilv_realpath(const char* path) +lilv_path_canonical(const char* path) { if (!path) { return NULL; @@ -325,7 +325,7 @@ lilv_dir_for_each(const char* path, } int -lilv_mkdir_p(const char* dir_path) +lilv_create_directories(const char* dir_path) { char* path = lilv_strdup(dir_path); const size_t path_len = strlen(path); @@ -373,8 +373,8 @@ lilv_file_equals(const char* a_path, const char* b_path) bool match = false; FILE* a_file = NULL; FILE* b_file = NULL; - char* const a_real = lilv_realpath(a_path); - char* const b_real = lilv_realpath(b_path); + char* const a_real = lilv_path_canonical(a_path); + char* const b_real = lilv_path_canonical(b_path); if (!strcmp(a_real, b_real)) { match = true; // Real paths match } else if (lilv_file_size(a_path) != lilv_file_size(b_path)) { diff --git a/src/filesystem.h b/src/filesystem.h index de06214..eb00e60 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -50,7 +50,7 @@ lilv_path_relative_to(const char* path, const char* base); Returns the root path if `path` is the root path. */ char* -lilv_dirname(const char* path); +lilv_path_parent(const char* path); /// Join path `a` and path `b` with a single directory separator between them char* @@ -67,7 +67,7 @@ lilv_dir_path(const char* path); directory separators. */ char* -lilv_realpath(const char* path); +lilv_path_canonical(const char* path); /// Return true iff `path` points to an existing file system entry bool @@ -122,7 +122,7 @@ lilv_dir_for_each(const char* path, @return Zero on success, or an `errno` error code. */ int -lilv_mkdir_p(const char* dir_path); +lilv_create_directories(const char* dir_path); /// Return true iff the given paths point to files with identical contents bool diff --git a/src/state.c b/src/state.c index 749316c..85e8d0f 100644 --- a/src/state.c +++ b/src/state.c @@ -244,7 +244,7 @@ static char* make_path(LV2_State_Make_Path_Handle handle, const char* path) { LilvState* state = (LilvState*)handle; - lilv_mkdir_p(state->dir); + lilv_create_directories(state->dir); return lilv_path_join(state->dir, path); } @@ -255,7 +255,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, { LilvState* state = (LilvState*)handle; char* path = NULL; - char* real_path = lilv_realpath(abs_path); + char* real_path = lilv_path_canonical(abs_path); const PathMap key = { real_path, NULL }; ZixTreeIter* iter = NULL; @@ -273,7 +273,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, // File created by plugin earlier path = lilv_path_relative_to(real_path, state->scratch_dir); if (state->copy_dir) { - int st = lilv_mkdir_p(state->copy_dir); + int st = lilv_create_directories(state->copy_dir); if (st) { LILV_ERRORF("Error creating directory %s (%s)\n", state->copy_dir, strerror(st)); @@ -725,8 +725,8 @@ lilv_state_new_from_file(LilvWorld* world, ? subject->node : sord_node_from_serd_node(world->world, env, &node, NULL, NULL); - char* dirname = lilv_dirname(path); - char* real_path = lilv_realpath(dirname); + char* dirname = lilv_path_parent(path); + char* real_path = lilv_path_canonical(dirname); char* dir_path = lilv_dir_path(real_path); LilvState* state = new_state_from_model(world, map, model, subject_node, dir_path); @@ -966,7 +966,7 @@ link_exists(const char* path, const void* data) if (!lilv_path_exists(path)) { return false; } - char* real_path = lilv_realpath(path); + char* real_path = lilv_path_canonical(path); bool matches = !strcmp(real_path, target); free(real_path); return !matches; @@ -1174,7 +1174,7 @@ lilv_state_save(LilvWorld* world, const char* dir, const char* filename) { - if (!filename || !dir || lilv_mkdir_p(dir)) { + if (!filename || !dir || lilv_create_directories(dir)) { return 1; } @@ -264,7 +264,7 @@ update_latest(const char* path, const char* name, void* data) char* lilv_get_latest_copy(const char* path, const char* copy_path) { - char* copy_dir = lilv_dirname(copy_path); + char* copy_dir = lilv_path_parent(copy_path); Latest latest = { lilv_strjoin(copy_path, ".%u", NULL), 0, NULL }; struct stat st; |