Hash :
01ad7b3a
Author :
Date :
2011-09-06T15:48:45
*: correct and codify various file permissions The following files now have 0444 permissions: - loose objects - pack indexes - pack files - packs downloaded by fetch - packs downloaded by the HTTP transport And the following files now have 0666 permissions: - config files - repository indexes - reflogs - refs This brings libgit2 more in line with Git. Note that git_filebuf_commit() and git_filebuf_commit_at() have both gained a new mode parameter. The latter change fixes an important issue where filebufs created with GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3) usage). Now we chmod() the file before renaming it into place. Tests have been added to confirm that new commit, tag, and tree objects are created with the right permissions. I don't have access to Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include "clay_libgit2.h"
#include "fileops.h"
static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
void test_core_rmdir__initialize(void)
{
char path[GIT_PATH_MAX];
cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
git_path_join(path, empty_tmp_dir, "/one");
cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/one/two_one");
cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/one/two_two");
cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/one/two_two/three");
cl_must_pass(p_mkdir(path, 0777));
git_path_join(path, empty_tmp_dir, "/two");
cl_must_pass(p_mkdir(path, 0777));
}
/* make sure empty dir can be deleted recusively */
void test_core_rmdir__delete_recursive(void)
{
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0));
}
/* make sure non-empty dir cannot be deleted recusively */
void test_core_rmdir__fail_to_delete_non_empty_dir(void)
{
char file[GIT_PATH_MAX];
int fd;
git_path_join(file, empty_tmp_dir, "/two/file.txt");
fd = p_creat(file, 0666);
cl_assert(fd >= 0);
cl_must_pass(p_close(fd));
cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, 0));
cl_must_pass(p_unlink(file));
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0));
}