diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-07-04 13:43:34 +0400 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-07-05 04:04:03 +0400 |
commit | f79026b4912bcd2336667f4c1663c06e233f0b32 (patch) | |
tree | 645b776032e924b587fad986aa3f3dc08c98d4c5 /tests | |
parent | 678e9e045becdc5d75f2ce2259ed01c3531ee181 (diff) |
fileops: Cleanup
Cleaned up the structure of the whole OS-abstraction layer.
fileops.c now contains a set of utility methods for file management used
by the library. These are abstractions on top of the original POSIX
calls.
There's a new file called `posix.c` that contains
emulations/reimplementations of all the POSIX calls the library uses.
These are prefixed with `p_`. There's a specific posix file for each
platform (win32 and unix).
All the path-related methods have been moved from `utils.c` to `path.c`
and have their own prefix.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/t00-core.c | 82 | ||||
-rw-r--r-- | tests/t03-objwrite.c | 12 | ||||
-rw-r--r-- | tests/t06-index.c | 4 | ||||
-rw-r--r-- | tests/t10-refs.c | 48 | ||||
-rw-r--r-- | tests/t12-repo.c | 52 | ||||
-rw-r--r-- | tests/test_helpers.c | 75 |
6 files changed, 137 insertions, 136 deletions
diff --git a/tests/t00-core.c b/tests/t00-core.c index e1aa6b8f9..7ce51a7ba 100644 --- a/tests/t00-core.c +++ b/tests/t00-core.c @@ -78,9 +78,9 @@ BEGIN_TEST(path0, "get the dirname of a path") char dir[64], *dir2; #define DIRNAME_TEST(A, B) { \ - must_be_true(git__dirname_r(dir, sizeof(dir), A) >= 0); \ + must_be_true(git_path_dirname_r(dir, sizeof(dir), A) >= 0); \ must_be_true(strcmp(dir, B) == 0); \ - must_be_true((dir2 = git__dirname(A)) != NULL); \ + must_be_true((dir2 = git_path_dirname(A)) != NULL); \ must_be_true(strcmp(dir2, B) == 0); \ free(dir2); \ } @@ -107,9 +107,9 @@ BEGIN_TEST(path1, "get the base name of a path") char base[64], *base2; #define BASENAME_TEST(A, B) { \ - must_be_true(git__basename_r(base, sizeof(base), A) >= 0); \ + must_be_true(git_path_basename_r(base, sizeof(base), A) >= 0); \ must_be_true(strcmp(base, B) == 0); \ - must_be_true((base2 = git__basename(A)) != NULL); \ + must_be_true((base2 = git_path_basename(A)) != NULL); \ must_be_true(strcmp(base2, B) == 0); \ free(base2); \ } @@ -132,7 +132,7 @@ BEGIN_TEST(path2, "get the latest component in a path") const char *dir; #define TOPDIR_TEST(A, B) { \ - must_be_true((dir = git__topdir(A)) != NULL); \ + must_be_true((dir = git_path_topdir(A)) != NULL); \ must_be_true(strcmp(dir, B) == 0); \ } @@ -144,10 +144,10 @@ BEGIN_TEST(path2, "get the latest component in a path") TOPDIR_TEST("/", "/"); TOPDIR_TEST("a/", "a/"); - must_be_true(git__topdir("/usr/.git") == NULL); - must_be_true(git__topdir(".") == NULL); - must_be_true(git__topdir("") == NULL); - must_be_true(git__topdir("a") == NULL); + must_be_true(git_path_topdir("/usr/.git") == NULL); + must_be_true(git_path_topdir(".") == NULL); + must_be_true(git_path_topdir("") == NULL); + must_be_true(git_path_topdir("a") == NULL); #undef TOPDIR_TEST END_TEST @@ -165,7 +165,7 @@ static int ensure_normalized(const char *input_path, const char *expected_path, char buffer_out[GIT_PATH_MAX]; char current_workdir[GIT_PATH_MAX]; - error = gitfo_getcwd(current_workdir, sizeof(current_workdir)); + error = p_getcwd(current_workdir, sizeof(current_workdir)); if (error < GIT_SUCCESS) return error; @@ -193,12 +193,12 @@ static int ensure_normalized(const char *input_path, const char *expected_path, static int ensure_dir_path_normalized(const char *input_path, const char *expected_path, int assert_flags) { - return ensure_normalized(input_path, expected_path, gitfo_prettify_dir_path, assert_flags); + return ensure_normalized(input_path, expected_path, git_futils_prettify_dir, assert_flags); } static int ensure_file_path_normalized(const char *input_path, const char *expected_path, int assert_flags) { - return ensure_normalized(input_path, expected_path, gitfo_prettify_file_path, assert_flags); + return ensure_normalized(input_path, expected_path, git_futils_prettyify_file, assert_flags); } BEGIN_TEST(path3, "prettify and validate a path to a file") @@ -355,7 +355,7 @@ END_TEST static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path) { char joined_path[GIT_PATH_MAX]; - git__joinpath(joined_path, path_a, path_b); + git_path_join(joined_path, path_a, path_b); return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR; } @@ -377,7 +377,7 @@ END_TEST static int ensure_joinpath_n(const char *path_a, const char *path_b, const char *path_c, const char *path_d, const char *expected_path) { char joined_path[GIT_PATH_MAX]; - git__joinpath_n(joined_path, 4, path_a, path_b, path_c, path_d); + git_path_join_n(joined_path, 4, path_a, path_b, path_c, path_d); return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR; } @@ -411,14 +411,14 @@ BEGIN_TEST(path7, "prevent a path which escapes the root directory from being pr char prettified[GIT_PATH_MAX]; int i = 0, number_to_escape; - must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir))); + must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); number_to_escape = count_number_of_path_segments(current_workdir); for (i = 0; i < number_to_escape + 1; i++) - git__joinpath(current_workdir, current_workdir, "../"); + git_path_join(current_workdir, current_workdir, "../"); - must_fail(gitfo_prettify_dir_path(prettified, sizeof(prettified), current_workdir, NULL)); + must_fail(git_futils_prettify_dir(prettified, sizeof(prettified), current_workdir, NULL)); END_TEST typedef struct name_data { @@ -451,24 +451,24 @@ static int setup(walk_data *d) { name_data *n; - if (gitfo_mkdir(top_dir, 0755) < 0) + if (p_mkdir(top_dir, 0755) < 0) return error("can't mkdir(\"%s\")", top_dir); - if (gitfo_chdir(top_dir) < 0) + if (p_chdir(top_dir) < 0) return error("can't chdir(\"%s\")", top_dir); if (strcmp(d->sub, ".") != 0) - if (gitfo_mkdir(d->sub, 0755) < 0) + if (p_mkdir(d->sub, 0755) < 0) return error("can't mkdir(\"%s\")", d->sub); strcpy(path_buffer, d->sub); state_loc = d; for (n = d->names; n->name; n++) { - git_file fd = gitfo_creat(n->name, 0600); + git_file fd = p_creat(n->name, 0600); if (fd < 0) return GIT_ERROR; - gitfo_close(fd); + p_close(fd); n->count = 0; } @@ -480,18 +480,18 @@ static int knockdown(walk_data *d) name_data *n; for (n = d->names; n->name; n++) { - if (gitfo_unlink(n->name) < 0) + if (p_unlink(n->name) < 0) return error("can't unlink(\"%s\")", n->name); } if (strcmp(d->sub, ".") != 0) - if (gitfo_rmdir(d->sub) < 0) + if (p_rmdir(d->sub) < 0) return error("can't rmdir(\"%s\")", d->sub); - if (gitfo_chdir("..") < 0) + if (p_chdir("..") < 0) return error("can't chdir(\"..\")"); - if (gitfo_rmdir(top_dir) < 0) + if (p_rmdir(top_dir) < 0) return error("can't rmdir(\"%s\")", top_dir); return 0; @@ -546,7 +546,7 @@ BEGIN_TEST(dirent0, "make sure that the '.' folder is not traversed") must_pass(setup(&dot)); - must_pass(gitfo_dirent(path_buffer, + must_pass(git_futils_direach(path_buffer, sizeof(path_buffer), one_entry, &dot)); @@ -571,7 +571,7 @@ BEGIN_TEST(dirent1, "traverse a subfolder") must_pass(setup(&sub)); - must_pass(gitfo_dirent(path_buffer, + must_pass(git_futils_direach(path_buffer, sizeof(path_buffer), one_entry, &sub)); @@ -590,7 +590,7 @@ BEGIN_TEST(dirent2, "traverse a slash-terminated subfolder") must_pass(setup(&sub_slash)); - must_pass(gitfo_dirent(path_buffer, + must_pass(git_futils_direach(path_buffer, sizeof(path_buffer), one_entry, &sub_slash)); @@ -619,7 +619,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed") must_pass(setup(&empty)); - must_pass(gitfo_dirent(path_buffer, + must_pass(git_futils_direach(path_buffer, sizeof(path_buffer), one_entry, &empty)); @@ -627,7 +627,7 @@ BEGIN_TEST(dirent3, "make sure that empty folders are not traversed") must_pass(check_counts(&empty)); /* make sure callback not called */ - must_pass(gitfo_dirent(path_buffer, + must_pass(git_futils_direach(path_buffer, sizeof(path_buffer), dont_call_me, &empty)); @@ -652,7 +652,7 @@ BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traver must_pass(setup(&odd)); - must_pass(gitfo_dirent(path_buffer, + must_pass(git_futils_direach(path_buffer, sizeof(path_buffer), one_entry, &odd)); @@ -667,12 +667,12 @@ BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock int fd; char test[] = "test", testlock[] = "test.lock"; - fd = gitfo_creat(testlock, 0744); + fd = p_creat(testlock, 0744); must_pass(fd); - must_pass(gitfo_close(fd)); + must_pass(p_close(fd)); must_fail(git_filebuf_open(&file, test, 0)); - must_pass(gitfo_exists(testlock)); - must_pass(gitfo_unlink(testlock)); + must_pass(git_futils_exists(testlock)); + must_pass(p_unlink(testlock)); END_TEST BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected") @@ -680,16 +680,16 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected") int fd; char test[] = "test"; - fd = gitfo_creat(test, 0644); + fd = p_creat(test, 0644); must_pass(fd); - must_pass(gitfo_write(fd, "libgit2 rocks\n", 14)); - must_pass(gitfo_close(fd)); + must_pass(p_write(fd, "libgit2 rocks\n", 14)); + must_pass(p_close(fd)); must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); must_pass(git_filebuf_commit(&file)); - must_pass(gitfo_unlink(test)); + must_pass(p_unlink(test)); END_TEST BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly") @@ -702,7 +702,7 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly" must_pass(git_filebuf_write(&file, buf, sizeof(buf))); must_pass(git_filebuf_commit(&file)); - must_pass(gitfo_unlink(test)); + must_pass(p_unlink(test)); END_TEST BEGIN_SUITE(core) diff --git a/tests/t03-objwrite.c b/tests/t03-objwrite.c index 08ddc0fd1..31f611a5c 100644 --- a/tests/t03-objwrite.c +++ b/tests/t03-objwrite.c @@ -31,7 +31,7 @@ static char *odb_dir = "test-objects"; static int make_odb_dir(void) { - if (gitfo_mkdir(odb_dir, 0755) < 0) { + if (p_mkdir(odb_dir, 0755) < 0) { int err = errno; fprintf(stderr, "can't make directory \"%s\"", odb_dir); if (err == EEXIST) @@ -44,9 +44,9 @@ static int make_odb_dir(void) static int check_object_files(object_data *d) { - if (gitfo_exists(d->dir) < 0) + if (git_futils_exists(d->dir) < 0) return -1; - if (gitfo_exists(d->file) < 0) + if (git_futils_exists(d->file) < 0) return -1; return 0; } @@ -64,16 +64,16 @@ static int cmp_objects(git_rawobj *o1, git_rawobj *o2) static int remove_object_files(object_data *d) { - if (gitfo_unlink(d->file) < 0) { + if (p_unlink(d->file) < 0) { fprintf(stderr, "can't delete object file \"%s\"\n", d->file); return -1; } - if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { + if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { fprintf(stderr, "can't remove directory \"%s\"\n", d->dir); return -1; } - if (gitfo_rmdir(odb_dir) < 0) { + if (p_rmdir(odb_dir) < 0) { fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir); return -1; } diff --git a/tests/t06-index.c b/tests/t06-index.c index 6a46719ed..3cbb5a9f0 100644 --- a/tests/t06-index.c +++ b/tests/t06-index.c @@ -146,7 +146,7 @@ BEGIN_TEST(write0, "write an index back to disk") git_index_free(index); - gitfo_unlink("index_rewrite"); + p_unlink("index_rewrite"); END_TEST BEGIN_TEST(sort0, "sort the entires in an index") @@ -187,7 +187,7 @@ BEGIN_TEST(add0, "add a new file to the index") must_pass(git_index_entrycount(index) == 0); /* Create a new file in the working directory */ - must_pass(gitfo_mkdir_2file(TEMP_REPO_FOLDER "myrepo/test.txt")); + must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt")); must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0)); must_pass(git_filebuf_write(&file, "hey there\n", 10)); must_pass(git_filebuf_commit(&file)); diff --git a/tests/t10-refs.c b/tests/t10-refs.c index f975c8fba..fb252f427 100644 --- a/tests/t10-refs.c +++ b/tests/t10-refs.c @@ -48,7 +48,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference") must_be_true(git_object_type(object) == GIT_OBJ_TAG); /* Ensure the name of the tag matches the name of the reference */ - git__joinpath(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)); + git_path_join(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)); must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0); git_object_close(object); @@ -209,7 +209,7 @@ BEGIN_TEST(create0, "create a new symbolic reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Retrieve the physical path to the symbolic ref for further cleaning */ - git__joinpath(ref_path, repo->path_repository, new_head_tracker); + git_path_join(ref_path, repo->path_repository, new_head_tracker); /* Create and write the new symbolic reference */ must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); @@ -251,7 +251,7 @@ BEGIN_TEST(create1, "create a deep symbolic reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - git__joinpath(ref_path, repo->path_repository, new_head_tracker); + git_path_join(ref_path, repo->path_repository, new_head_tracker); must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); @@ -273,7 +273,7 @@ BEGIN_TEST(create2, "create a new OID reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Retrieve the physical path to the symbolic ref for further cleaning */ - git__joinpath(ref_path, repo->path_repository, new_head); + git_path_join(ref_path, repo->path_repository, new_head); /* Create and write the new object id reference */ must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id, 0)); @@ -432,8 +432,8 @@ BEGIN_TEST(pack0, "create a packfile for an empty folder") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - git__joinpath_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir"); - must_pass(gitfo_mkdir_recurs(temp_path, mode)); + git_path_join_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir"); + must_pass(git_futils_mkdir_r(temp_path, mode)); must_pass(git_reference_packall(repo)); @@ -460,8 +460,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") must_pass(git_reference_packall(repo)); /* Ensure the packed-refs file exists */ - git__joinpath(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE); - must_pass(gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE); + must_pass(git_futils_exists(temp_path)); /* Ensure the known ref can still be looked up but is now packed */ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); @@ -469,8 +469,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); /* Ensure the known ref has been removed from the loose folder structure */ - git__joinpath(temp_path, repo->path_repository, loose_tag_ref_name); - must_pass(!gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, loose_tag_ref_name); + must_pass(!git_futils_exists(temp_path)); close_temp_repo(repo); END_TEST @@ -484,8 +484,8 @@ BEGIN_TEST(rename0, "rename a loose reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Ensure the ref doesn't exist on the file system */ - git__joinpath(temp_path, repo->path_repository, new_name); - must_pass(!gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, new_name); + must_pass(!git_futils_exists(temp_path)); /* Retrieval of the reference to rename */ must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name)); @@ -509,8 +509,8 @@ BEGIN_TEST(rename0, "rename a loose reference") must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); /* ...and the ref can be found in the file system */ - git__joinpath(temp_path, repo->path_repository, new_name); - must_pass(gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, new_name); + must_pass(git_futils_exists(temp_path)); close_temp_repo(repo); END_TEST @@ -524,8 +524,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Ensure the ref doesn't exist on the file system */ - git__joinpath(temp_path, repo->path_repository, packed_head_name); - must_pass(!gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, packed_head_name); + must_pass(!git_futils_exists(temp_path)); /* The reference can however be looked-up... */ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); @@ -549,8 +549,8 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); /* ...and the ref now happily lives in the file system */ - git__joinpath(temp_path, repo->path_repository, brand_new_name); - must_pass(gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, brand_new_name); + must_pass(git_futils_exists(temp_path)); close_temp_repo(repo); END_TEST @@ -564,8 +564,8 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Ensure the other reference exists on the file system */ - git__joinpath(temp_path, repo->path_repository, packed_test_head_name); - must_pass(gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, packed_test_head_name); + must_pass(git_futils_exists(temp_path)); /* Lookup the other reference */ must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); @@ -589,7 +589,7 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); /* Ensure the other ref still exists on the file system */ - must_pass(gitfo_exists(temp_path)); + must_pass(git_futils_exists(temp_path)); close_temp_repo(repo); END_TEST @@ -694,8 +694,8 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Ensure the loose reference exists on the file system */ - git__joinpath(temp_path, repo->path_repository, packed_test_head_name); - must_pass(gitfo_exists(temp_path)); + git_path_join(temp_path, repo->path_repository, packed_test_head_name); + must_pass(git_futils_exists(temp_path)); /* Lookup the reference */ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); @@ -710,7 +710,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); /* Ensure the loose reference doesn't exist any longer on the file system */ - must_pass(!gitfo_exists(temp_path)); + must_pass(!git_futils_exists(temp_path)); close_temp_repo(repo); END_TEST diff --git a/tests/t12-repo.c b/tests/t12-repo.c index 3b010c886..3b3c7c0ef 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -104,10 +104,10 @@ static int ensure_repository_init( char path_odb[GIT_PATH_MAX]; git_repository *repo; - if (gitfo_isdir(working_directory) == GIT_SUCCESS) + if (git_futils_isdir(working_directory) == GIT_SUCCESS) return GIT_ERROR; - git__joinpath(path_odb, expected_path_repository, GIT_OBJECTS_DIR); + git_path_join(path_odb, expected_path_repository, GIT_OBJECTS_DIR); if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS) return GIT_ERROR; @@ -154,8 +154,8 @@ cleanup: BEGIN_TEST(init0, "initialize a standard repo") char path_index[GIT_PATH_MAX], path_repository[GIT_PATH_MAX]; - git__joinpath(path_repository, TEMP_REPO_FOLDER, GIT_DIR); - git__joinpath(path_index, path_repository, GIT_INDEX_FILE); + git_path_join(path_repository, TEMP_REPO_FOLDER, GIT_DIR); + git_path_join(path_index, path_repository, GIT_INDEX_FILE); must_pass(ensure_repository_init(TEMP_REPO_FOLDER, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER)); must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER)); @@ -164,7 +164,7 @@ END_TEST BEGIN_TEST(init1, "initialize a bare repo") char path_repository[GIT_PATH_MAX]; - git__joinpath(path_repository, TEMP_REPO_FOLDER, ""); + git_path_join(path_repository, TEMP_REPO_FOLDER, ""); must_pass(ensure_repository_init(TEMP_REPO_FOLDER, BARE_REPOSITORY, NULL, path_repository, NULL)); must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL)); @@ -176,10 +176,10 @@ BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping const int mode = 0755; /* or 0777 ? */ git_repository* repo; - must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir))); + must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - git__joinpath(path_repository, TEMP_REPO_FOLDER, "a/b/c/"); - must_pass(gitfo_mkdir_recurs(path_repository, mode)); + git_path_join(path_repository, TEMP_REPO_FOLDER, "a/b/c/"); + must_pass(git_futils_mkdir_r(path_repository, mode)); must_pass(chdir(path_repository)); @@ -242,14 +242,14 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t git_repository* repo; /* Setup the repository to open */ - must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir))); + must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); strcpy(path_repository, current_workdir); - git__joinpath_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git"); + git_path_join_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git"); must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository)); /* Change the current working directory */ - git__joinpath(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/"); - must_pass(gitfo_mkdir_recurs(new_current_workdir, mode)); + git_path_join(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/"); + must_pass(git_futils_mkdir_r(new_current_workdir, mode)); must_pass(chdir(new_current_workdir)); must_pass(git_repository_open(&repo, "../../d/e.git")); @@ -350,20 +350,20 @@ static int write_file(const char *path, const char *content) int error; git_file file; - if (gitfo_exists(path) == GIT_SUCCESS) { - error = gitfo_unlink(path); + if (git_futils_exists(path) == GIT_SUCCESS) { + error = p_unlink(path); if (error < GIT_SUCCESS) return error; } - file = gitfo_creat_force(path, 0644); + file = git_futils_creat_withpath(path, 0644); if (file < GIT_SUCCESS) return file; - error = gitfo_write(file, (void*)content, strlen(content) * sizeof(char)); + error = p_write(file, (void*)content, strlen(content) * sizeof(char)); - gitfo_close(file); + p_close(file); return error; } @@ -374,7 +374,7 @@ static int append_ceiling_dir(char *ceiling_dirs, const char *path) int len = strlen(ceiling_dirs); int error; - error = gitfo_prettify_dir_path(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL); + error = git_futils_prettify_dir(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL); if (error < GIT_SUCCESS) return git__rethrow(error, "Failed to append ceiling directory."); @@ -394,7 +394,7 @@ BEGIN_TEST(discover0, "test discover") rmdir_recurs(DISCOVER_FOLDER); must_pass(append_ceiling_dir(ceiling_dirs,TEST_RESOURCES)); - gitfo_mkdir_recurs(DISCOVER_FOLDER, mode); + git_futils_mkdir_r(DISCOVER_FOLDER, mode); must_be_true(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO); @@ -403,15 +403,15 @@ BEGIN_TEST(discover0, "test discover") git_repository_free(repo); must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0)); - must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); + must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); must_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); - must_pass(gitfo_mkdir_recurs(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); + must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path)); - must_pass(gitfo_mkdir_recurs(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode)); + must_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode)); must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../")); @@ -420,13 +420,13 @@ BEGIN_TEST(discover0, "test discover") must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); - must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER1, mode)); + must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, mode)); must_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:")); - must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER2, mode)); + must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, mode)); must_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:")); - must_pass(gitfo_mkdir_recurs(ALTERNATE_MALFORMED_FOLDER3, mode)); + must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, mode)); must_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n")); - must_pass(gitfo_mkdir_recurs(ALTERNATE_NOT_FOUND_FOLDER, mode)); + must_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, mode)); must_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist")); must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs)); must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs)); diff --git a/tests/test_helpers.c b/tests/test_helpers.c index 760de238b..5c2ccee15 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -32,17 +32,17 @@ int write_object_data(char *file, void *data, size_t len) git_file fd; int ret; - if ((fd = gitfo_creat(file, S_IREAD | S_IWRITE)) < 0) + if ((fd = p_creat(file, S_IREAD | S_IWRITE)) < 0) return -1; - ret = gitfo_write(fd, data, len); - gitfo_close(fd); + ret = p_write(fd, data, len); + p_close(fd); return ret; } int write_object_files(const char *odb_dir, object_data *d) { - if (gitfo_mkdir(odb_dir, 0755) < 0) { + if (p_mkdir(odb_dir, 0755) < 0) { int err = errno; fprintf(stderr, "can't make directory \"%s\"", odb_dir); if (err == EEXIST) @@ -51,7 +51,7 @@ int write_object_files(const char *odb_dir, object_data *d) return -1; } - if ((gitfo_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) { + if ((p_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) { fprintf(stderr, "can't make object directory \"%s\"\n", d->dir); return -1; } @@ -65,16 +65,16 @@ int write_object_files(const char *odb_dir, object_data *d) int remove_object_files(const char *odb_dir, object_data *d) { - if (gitfo_unlink(d->file) < 0) { + if (p_unlink(d->file) < 0) { fprintf(stderr, "can't delete object file \"%s\"\n", d->file); return -1; } - if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { + if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir); return -1; } - if (gitfo_rmdir(odb_dir) < 0) { + if (p_rmdir(odb_dir) < 0) { fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir); return -1; } @@ -104,14 +104,14 @@ int remove_loose_object(const char *repository_folder, git_object *object) ptr += GIT_OID_HEXSZ + 1; *ptr = 0; - if (gitfo_unlink(full_path) < 0) { + if (p_unlink(full_path) < 0) { fprintf(stderr, "can't delete object file \"%s\"\n", full_path); return -1; } *top_folder = 0; - if ((gitfo_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) { + if ((p_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) { fprintf(stderr, "can't remove object directory \"%s\"\n", full_path); return -1; } @@ -134,44 +134,44 @@ int cmp_objects(git_rawobj *o, object_data *d) int copy_file(const char *src, const char *dst) { - gitfo_buf source_buf; + git_fbuffer source_buf; git_file dst_fd; int error = GIT_ERROR; - if (gitfo_read_file(&source_buf, src) < GIT_SUCCESS) + if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS) return GIT_ENOTFOUND; - dst_fd = gitfo_creat_force(dst, 0644); + dst_fd = git_futils_creat_withpath(dst, 0644); if (dst_fd < 0) goto cleanup; - error = gitfo_write(dst_fd, source_buf.data, source_buf.len); + error = p_write(dst_fd, source_buf.data, source_buf.len); cleanup: - gitfo_free_buf(&source_buf); - gitfo_close(dst_fd); + git_futils_freebuffer(&source_buf); + p_close(dst_fd); return error; } int cmp_files(const char *a, const char *b) { - gitfo_buf buf_a, buf_b; + git_fbuffer buf_a, buf_b; int error = GIT_ERROR; - if (gitfo_read_file(&buf_a, a) < GIT_SUCCESS) + if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS) return GIT_ERROR; - if (gitfo_read_file(&buf_b, b) < GIT_SUCCESS) { - gitfo_free_buf(&buf_a); + if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) { + git_futils_freebuffer(&buf_a); return GIT_ERROR; } if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len)) error = GIT_SUCCESS; - gitfo_free_buf(&buf_a); - gitfo_free_buf(&buf_b); + git_futils_freebuffer(&buf_a); + git_futils_freebuffer(&buf_b); return error; } @@ -182,11 +182,11 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path) GIT_UNUSED_ARG(nil); - error = gitfo_isdir(path); + error = git_futils_isdir(path); if (error == GIT_SUCCESS) { size_t root_size = strlen(path); - error = gitfo_dirent(path, GIT_PATH_MAX, remove_filesystem_element_recurs, NULL); + error = git_futils_direach(path, GIT_PATH_MAX, remove_filesystem_element_recurs, NULL); if (error < GIT_SUCCESS) return error; @@ -194,7 +194,7 @@ static int remove_filesystem_element_recurs(void *GIT_UNUSED(nil), char *path) return rmdir(path); } - return gitfo_unlink(path); + return p_unlink(path); } int rmdir_recurs(const char *directory_path) @@ -214,10 +214,10 @@ static int copy_filesystem_element_recurs(void *_data, char *source) copydir_data *data = (copydir_data *)_data; data->dst[data->dst_len] = 0; - git__joinpath(data->dst, data->dst, source + data->src_len); + git_path_join(data->dst, data->dst, source + data->src_len); - if (gitfo_isdir(source) == GIT_SUCCESS) - return gitfo_dirent(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data); + if (git_futils_isdir(source) == GIT_SUCCESS) + return git_futils_direach(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data); return copy_file(source, data->dst); } @@ -229,13 +229,14 @@ int copydir_recurs(const char *source_directory_path, const char *destination_di copydir_data data; /* Source has to exist, Destination hast to _not_ exist */ - if (gitfo_isdir(source_directory_path) || !gitfo_isdir(destination_directory_path)) + if (git_futils_isdir(source_directory_path) != GIT_SUCCESS || + git_futils_isdir(destination_directory_path) == GIT_SUCCESS) return GIT_EINVALIDPATH; - git__joinpath(source_buffer, source_directory_path, ""); + git_path_join(source_buffer, source_directory_path, ""); data.src_len = strlen(source_buffer); - git__joinpath(dest_buffer, destination_directory_path, ""); + git_path_join(dest_buffer, destination_directory_path, ""); data.dst = dest_buffer; data.dst_len = strlen(dest_buffer); @@ -262,14 +263,14 @@ static int remove_placeholders_recurs(void *filename, char *path) char passed_filename[GIT_PATH_MAX]; char *data = (char *)filename; - if (!gitfo_isdir(path)) - return gitfo_dirent(path, GIT_PATH_MAX, remove_placeholders_recurs, data); + if (!git_futils_isdir(path)) + return git_futils_direach(path, GIT_PATH_MAX, remove_placeholders_recurs, data); - if (git__basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS) - return GIT_EINVALIDPATH; + if (git_path_basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS) + return GIT_EINVALIDPATH; if (!strcmp(data, passed_filename)) - return gitfo_unlink(path); + return p_unlink(path); return GIT_SUCCESS; } @@ -278,7 +279,7 @@ int remove_placeholders(char *directory_path, char *filename) { char buffer[GIT_PATH_MAX]; - if (gitfo_isdir(directory_path)) + if (git_futils_isdir(directory_path)) return GIT_EINVALIDPATH; strcpy(buffer, directory_path); |