diff options
author | David Robillard <d@drobilla.net> | 2022-11-12 17:54:15 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-11-16 10:22:55 -0500 |
commit | ab98128551cc97e333caf714830f807bbe25bae7 (patch) | |
tree | c63f14badd247071bbe54971ef7d75e5b81bd18d /src | |
parent | dd5e8510cb40b853a5d252084660dc38aab7c665 (diff) | |
download | lilv-ab98128551cc97e333caf714830f807bbe25bae7.tar.gz lilv-ab98128551cc97e333caf714830f807bbe25bae7.tar.bz2 lilv-ab98128551cc97e333caf714830f807bbe25bae7.zip |
Use zix_file_equals()
Diffstat (limited to 'src')
-rw-r--r-- | src/filesystem.c | 55 | ||||
-rw-r--r-- | src/filesystem.h | 4 | ||||
-rw-r--r-- | src/state.c | 7 |
3 files changed, 4 insertions, 62 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index cce197d..48e046d 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -5,8 +5,6 @@ #include "lilv_config.h" #include "lilv_internal.h" -#include "zix/allocator.h" -#include "zix/filesystem.h" #include "zix/path.h" #ifdef _WIN32 @@ -408,16 +406,6 @@ lilv_create_directories(const char* dir_path) return 0; } -static off_t -lilv_file_size(const char* path) -{ - struct stat buf; - if (stat(path, &buf)) { - return 0; - } - return buf.st_size; -} - int lilv_remove(const char* path) { @@ -429,46 +417,3 @@ lilv_remove(const char* path) return remove(path); } - -bool -lilv_file_equals(const char* a_path, const char* b_path) -{ - if (!strcmp(a_path, b_path)) { - return true; // Paths match - } - - bool match = false; - FILE* a_file = NULL; - FILE* b_file = NULL; - char* const a_real = zix_canonical_path(NULL, a_path); - char* const b_real = zix_canonical_path(NULL, b_path); - if (!a_real || !b_real) { - match = false; // At least one file doesn't exist - } else if (!strcmp(a_real, b_real)) { - match = true; // Real paths match - } else if (lilv_file_size(a_real) != lilv_file_size(b_real)) { - match = false; // Sizes differ - } else if (!(a_file = fopen(a_real, "rb")) || - !(b_file = fopen(b_real, "rb"))) { - match = false; // Missing file matches nothing - } else { - // TODO: Improve performance by reading chunks - match = true; - while (!feof(a_file) && !feof(b_file)) { - if (fgetc(a_file) != fgetc(b_file)) { - match = false; - break; - } - } - } - - if (a_file) { - fclose(a_file); - } - if (b_file) { - fclose(b_file); - } - zix_free(NULL, a_real); - zix_free(NULL, b_real); - return match; -} diff --git a/src/filesystem.h b/src/filesystem.h index ffbcbe5..e995cf4 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -128,7 +128,3 @@ lilv_create_directories(const char* dir_path); /// Remove the file or empty directory at `path` int lilv_remove(const char* path); - -/// Return true iff the given paths point to files with identical contents -bool -lilv_file_equals(const char* a_path, const char* b_path); diff --git a/src/state.c b/src/state.c index 61558e9..920d067 100644 --- a/src/state.c +++ b/src/state.c @@ -295,7 +295,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path) char* cpath = zix_path_join(NULL, state->copy_dir, path); char* copy = lilv_get_latest_copy(real_path, cpath); - if (!copy || !lilv_file_equals(real_path, copy)) { + 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); @@ -1483,8 +1483,9 @@ lilv_state_equals(const LilvState* a, const LilvState* b) } if (ap->type == a->atom_Path) { - if (!lilv_file_equals(lilv_state_rel2abs(a, (char*)ap->value), - lilv_state_rel2abs(b, (char*)bp->value))) { + if (!zix_file_equals(NULL, + lilv_state_rel2abs(a, (char*)ap->value), + lilv_state_rel2abs(b, (char*)bp->value))) { return false; } } else if (ap->size != bp->size || memcmp(ap->value, bp->value, ap->size)) { |