libgit2/tests-clay/core/rmdir.c
Brodie Rao ce8cd006ce fileops/repository: create (most) directories with 0777 permissions
To further match how Git behaves, this change makes most of the
directories libgit2 creates in a git repo have a file mode of
0777. Specifically:

- Intermediate directories created with git_futils_mkpath2file() have
  0777 permissions. This affects odb_loose, reflog, and refs.

- The top level folder for bare repos is created with 0777
  permissions.

- The top level folder for non-bare repos is created with 0755
  permissions.

- /objects/info/, /objects/pack/, /refs/heads/, and /refs/tags/ are
  created with 0777 permissions.

Additionally, the following changes have been made:

- fileops functions that create intermediate directories have grown a
  new dirmode parameter. The only exception to this is filebuf's
  lock_file(), which unconditionally creates intermediate directories
  with 0777 permissions when GIT_FILEBUF_FORCE is set.

- The test runner now sets the umask to 0 before running any
  tests. This ensurses all file mode checks are consistent across
  systems.

- t09-tree.c now does a directory permissions check. I've avoided
  adding this check to other tests that might reuse existing
  directories from the prefabricated test repos. Because they're
  checked into the repo, they have 0755 permissions.

- Other assorted directories created by tests have 0777 permissions.
2011-10-14 16:04:34 -07:00

51 lines
1.2 KiB
C

#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, 0755);
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));
}