diff options
-rw-r--r-- | src/filesystem.c | 55 | ||||
-rw-r--r-- | src/filesystem.h | 4 | ||||
-rw-r--r-- | src/state.c | 7 | ||||
-rw-r--r-- | test/test_filesystem.c | 34 | ||||
-rw-r--r-- | test/test_state.c | 4 | ||||
-rw-r--r-- | test/test_util.c | 6 |
6 files changed, 7 insertions, 103 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)) { diff --git a/test/test_filesystem.c b/test/test_filesystem.c index 0e199c7..2057101 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -178,7 +178,7 @@ test_copy_file(void) fclose(f); assert(!lilv_copy_file(file_path, copy_path)); - assert(lilv_file_equals(file_path, copy_path)); + assert(zix_file_equals(NULL, file_path, copy_path)); if (zix_file_type("/dev/full") != ZIX_FILE_TYPE_NONE) { // Copy short file (error after flushing) @@ -325,37 +325,6 @@ test_create_directories(void) free(temp_dir); } -static void -test_file_equals(void) -{ - char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX"); - char* const path1 = zix_path_join(NULL, temp_dir, "lilv_test_1"); - char* const path2 = zix_path_join(NULL, temp_dir, "lilv_test_2"); - - FILE* const f1 = fopen(path1, "w"); - FILE* const f2 = fopen(path2, "w"); - fprintf(f1, "test\n"); - fprintf(f2, "test\n"); - - assert(lilv_file_equals(path1, path2)); - - fprintf(f2, "diff\n"); - fflush(f2); - - assert(!lilv_file_equals(path1, path2)); - - fclose(f2); - fclose(f1); - - assert(!lilv_remove(path2)); - assert(!lilv_remove(path1)); - assert(!lilv_remove(temp_dir)); - - free(path2); - free(path1); - free(temp_dir); -} - int main(void) { @@ -372,7 +341,6 @@ main(void) test_dir_for_each(); test_create_temporary_directory(); test_create_directories(); - test_file_equals(); return 0; } diff --git a/test/test_state.c b/test/test_state.c index 78a4e5d..e80ec89 100644 --- a/test/test_state.c +++ b/test/test_state.c @@ -627,7 +627,7 @@ test_to_files(void) #endif // Check that link points to the corresponding copy - assert(lilv_file_equals(recfile_link_1, recfile_copy_1)); + assert(zix_file_equals(NULL, recfile_link_1, recfile_copy_1)); // Run plugin again to modify recording file data lilv_instance_run(instance, 2); @@ -658,7 +658,7 @@ test_to_files(void) #endif // Check that link points to the corresponding copy - assert(lilv_file_equals(recfile_link_2, recfile_copy_2)); + assert(zix_file_equals(NULL, recfile_link_2, recfile_copy_2)); lilv_instance_free(instance); lilv_dir_for_each(bundle_2_path, NULL, remove_file); diff --git a/test/test_util.c b/test/test_util.c index 94e5567..529719e 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -28,12 +28,6 @@ main(void) assert(lilv_copy_file("does/not/exist", "copy")); assert(lilv_copy_file(a_path, "not/a/dir/copy")); assert(!lilv_copy_file(a_path, "copy_c")); - assert(!lilv_file_equals(a_path, b_path)); - assert(lilv_file_equals(a_path, a_path)); - assert(lilv_file_equals(a_path, "copy_c")); - assert(!lilv_file_equals("does/not/exist", b_path)); - assert(!lilv_file_equals(a_path, "does/not/exist")); - assert(!lilv_file_equals("does/not/exist", "/does/not/either")); assert(!lilv_remove(a_path)); assert(!lilv_remove(b_path)); |