diff options
author | Edward Thomson <ethomson@microsoft.com> | 2013-11-07 21:03:44 +0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2013-11-07 21:04:32 +0400 |
commit | 1e60e5f42dbcf081ac7eece12a5eebab5871636f (patch) | |
tree | a01d41a27e19926ea18db1b6976b6455e423ac5a /tests-clar | |
parent | 9018a453ea801a965795af6c8f8523a49f4d167b (diff) |
Allow callers to set mode on packfile creation
Diffstat (limited to 'tests-clar')
-rw-r--r-- | tests-clar/pack/indexer.c | 6 | ||||
-rw-r--r-- | tests-clar/pack/packbuilder.c | 50 |
2 files changed, 50 insertions, 6 deletions
diff --git a/tests-clar/pack/indexer.c b/tests-clar/pack/indexer.c index d7953300f..07963a9e7 100644 --- a/tests-clar/pack/indexer.c +++ b/tests-clar/pack/indexer.c @@ -48,7 +48,7 @@ void test_pack_indexer__out_of_order(void) git_indexer *idx; git_transfer_progress stats; - cl_git_pass(git_indexer_new(&idx, ".", NULL, NULL, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL)); cl_git_pass(git_indexer_append(idx, out_of_order_pack, out_of_order_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -75,7 +75,7 @@ void test_pack_indexer__fix_thin(void) git_oid_fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18"); cl_assert(!git_oid_cmp(&id, &should_id)); - cl_git_pass(git_indexer_new(&idx, ".", odb, NULL, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL, NULL)); cl_git_pass(git_indexer_append(idx, thin_pack, thin_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -108,7 +108,7 @@ void test_pack_indexer__fix_thin(void) cl_git_pass(p_stat(name, &st)); - cl_git_pass(git_indexer_new(&idx, ".", NULL, NULL, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL)); read = p_read(fd, buffer, sizeof(buffer)); cl_assert(read != -1); p_close(fd); diff --git a/tests-clar/pack/packbuilder.c b/tests-clar/pack/packbuilder.c index dd028a143..54d1e8022 100644 --- a/tests-clar/pack/packbuilder.c +++ b/tests-clar/pack/packbuilder.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "fileops.h" +#include "pack.h" #include "hash.h" #include "iterator.h" #include "vector.h" @@ -92,7 +93,7 @@ void test_pack_packbuilder__create_pack(void) seed_packbuilder(); - cl_git_pass(git_indexer_new(&_indexer, ".", NULL, NULL, NULL)); + cl_git_pass(git_indexer_new(&_indexer, ".", 0, NULL, NULL, NULL)); cl_git_pass(git_packbuilder_foreach(_packbuilder, feed_indexer, &stats)); cl_git_pass(git_indexer_commit(_indexer, &stats)); @@ -134,12 +135,55 @@ void test_pack_packbuilder__get_hash(void) seed_packbuilder(); - git_packbuilder_write(_packbuilder, ".", NULL, NULL); + git_packbuilder_write(_packbuilder, ".", 0, NULL, NULL); git_oid_fmt(hex, git_packbuilder_hash(_packbuilder)); cl_assert_equal_s(hex, "80e61eb315239ef3c53033e37fee43b744d57122"); } +static void test_write_pack_permission(mode_t given, mode_t expected) +{ + struct stat statbuf; + mode_t mask, os_mask; + + seed_packbuilder(); + + git_packbuilder_write(_packbuilder, ".", given, NULL, NULL); + + /* Windows does not return group/user bits from stat, + * files are never executable. + */ +#ifdef GIT_WIN32 + os_mask = 0600; +#else + os_mask = 0777; +#endif + + mask = p_umask(0); + p_umask(mask); + + cl_git_pass(p_stat("pack-80e61eb315239ef3c53033e37fee43b744d57122.idx", &statbuf)); + cl_assert_equal_i(statbuf.st_mode & os_mask, (expected & ~mask) & os_mask); + + cl_git_pass(p_stat("pack-80e61eb315239ef3c53033e37fee43b744d57122.pack", &statbuf)); + cl_assert_equal_i(statbuf.st_mode & os_mask, (expected & ~mask) & os_mask); +} + +void test_pack_packbuilder__permissions_standard(void) +{ + test_write_pack_permission(0, GIT_PACK_FILE_MODE); +} + +void test_pack_packbuilder__permissions_readonly(void) +{ + test_write_pack_permission(0444, 0444); +} + +void test_pack_packbuilder__permissions_readwrite(void) +{ + test_write_pack_permission(0666, 0666); +} + static git_transfer_progress stats; static int foreach_cb(void *buf, size_t len, void *payload) { @@ -153,7 +197,7 @@ void test_pack_packbuilder__foreach(void) git_indexer *idx; seed_packbuilder(); - cl_git_pass(git_indexer_new(&idx, ".", NULL, NULL, NULL)); + cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL)); cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx)); cl_git_pass(git_indexer_commit(idx, &stats)); git_indexer_free(idx); |