mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 21:44:58 +00:00

This converts virtually all of the places that allocate GIT_PATH_MAX buffers on the stack for manipulating paths to use git_buf objects instead. The patch is pretty careful not to touch the public API for libgit2, so there are a few places that still use GIT_PATH_MAX. This extends and changes some details of the git_buf implementation to add a couple of extra functions and to make error handling easier. This includes serious alterations to all the path.c functions, and several of the fileops.c ones, too. Also, there are a number of new functions that parallel existing ones except that use a git_buf instead of a stack-based buffer (such as git_config_find_global_r that exists alongsize git_config_find_global). This also modifies the win32 version of p_realpath to allocate whatever buffer size is needed to accommodate the realpath instead of hardcoding a GIT_PATH_MAX limit, but that change needs to be tested still.
55 lines
1.4 KiB
C
55 lines
1.4 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)
|
|
{
|
|
git_buf path = GIT_BUF_INIT;
|
|
|
|
cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
|
|
|
|
cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
|
|
cl_must_pass(p_mkdir(path.ptr, 0777));
|
|
|
|
cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_one"));
|
|
cl_must_pass(p_mkdir(path.ptr, 0777));
|
|
|
|
cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two"));
|
|
cl_must_pass(p_mkdir(path.ptr, 0777));
|
|
|
|
cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
|
|
cl_must_pass(p_mkdir(path.ptr, 0777));
|
|
|
|
cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two"));
|
|
cl_must_pass(p_mkdir(path.ptr, 0777));
|
|
|
|
git_buf_free(&path);
|
|
}
|
|
|
|
/* 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)
|
|
{
|
|
git_buf file = GIT_BUF_INIT;
|
|
int fd;
|
|
|
|
cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
|
|
|
|
fd = p_creat(file.ptr, 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.ptr));
|
|
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0));
|
|
|
|
git_buf_free(&file);
|
|
}
|