Commit ac2fba0e by Edward Thomson Committed by Edward Thomson

git_futils_mkdir_*: make a relative-to-base mkdir

Untangle git_futils_mkdir from git_futils_mkdir_ext - the latter
assumes that we own everything beneath the base, as if it were
being called with a base of the repository or working directory,
and is tailored towards checkout and ensuring that there is no
bogosity beneath the base that must be cleaned up.

This is (at best) slow and (at worst) unsafe in the larger context
of a filesystem where we do not own things and cannot do things like
unlink symlinks that are in our way.
parent add0378d
...@@ -1366,7 +1366,7 @@ static int checkout_mkdir( ...@@ -1366,7 +1366,7 @@ static int checkout_mkdir(
mkdir_opts.dir_map = data->mkdir_map; mkdir_opts.dir_map = data->mkdir_map;
mkdir_opts.pool = &data->pool; mkdir_opts.pool = &data->pool;
error = git_futils_mkdir_ext( error = git_futils_mkdir_relative(
path, base, mode, flags, &mkdir_opts); path, base, mode, flags, &mkdir_opts);
data->perfdata.mkdir_calls += mkdir_opts.perfdata.mkdir_calls; data->perfdata.mkdir_calls += mkdir_opts.perfdata.mkdir_calls;
......
...@@ -18,7 +18,7 @@ GIT__USE_STRMAP ...@@ -18,7 +18,7 @@ GIT__USE_STRMAP
int git_futils_mkpath2file(const char *file_path, const mode_t mode) int git_futils_mkpath2file(const char *file_path, const mode_t mode)
{ {
return git_futils_mkdir( return git_futils_mkdir(
file_path, NULL, mode, file_path, mode,
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR); GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
} }
...@@ -331,8 +331,8 @@ GIT_INLINE(int) validate_existing( ...@@ -331,8 +331,8 @@ GIT_INLINE(int) validate_existing(
return 0; return 0;
} }
int git_futils_mkdir_ext( int git_futils_mkdir_relative(
const char *path, const char *relative_path,
const char *base, const char *base,
mode_t mode, mode_t mode,
uint32_t flags, uint32_t flags,
...@@ -343,9 +343,13 @@ int git_futils_mkdir_ext( ...@@ -343,9 +343,13 @@ int git_futils_mkdir_ext(
ssize_t root = 0, min_root_len, root_len; ssize_t root = 0, min_root_len, root_len;
char lastch = '/', *tail; char lastch = '/', *tail;
struct stat st; struct stat st;
struct git_futils_mkdir_options empty_opts = {0};
if (!opts)
opts = &empty_opts;
/* build path and find "root" where we should start calling mkdir */ /* build path and find "root" where we should start calling mkdir */
if (git_path_join_unrooted(&make_path, path, base, &root) < 0) if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
return -1; return -1;
if (make_path.size == 0) { if (make_path.size == 0) {
...@@ -503,17 +507,16 @@ done: ...@@ -503,17 +507,16 @@ done:
int git_futils_mkdir( int git_futils_mkdir(
const char *path, const char *path,
const char *base,
mode_t mode, mode_t mode,
uint32_t flags) uint32_t flags)
{ {
struct git_futils_mkdir_options options = {0}; struct git_futils_mkdir_options options = {0};
return git_futils_mkdir_ext(path, base, mode, flags, &options); return git_futils_mkdir_relative(path, NULL, mode, flags, &options);
} }
int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode) int git_futils_mkdir_r(const char *path, const mode_t mode)
{ {
return git_futils_mkdir(path, base, mode, GIT_MKDIR_PATH); return git_futils_mkdir(path, mode, GIT_MKDIR_PATH);
} }
typedef struct { typedef struct {
...@@ -777,7 +780,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from) ...@@ -777,7 +780,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
/* create root directory the first time we need to create a directory */ /* create root directory the first time we need to create a directory */
if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) { if ((info->flags & GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT) == 0) {
error = git_futils_mkdir( error = git_futils_mkdir(
info->to_root, NULL, info->dirmode, info->to_root, info->dirmode,
(info->flags & GIT_CPDIR_CHMOD_DIRS) ? GIT_MKDIR_CHMOD : 0); (info->flags & GIT_CPDIR_CHMOD_DIRS) ? GIT_MKDIR_CHMOD : 0);
info->flags |= GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT; info->flags |= GIT_CPDIR__MKDIR_DONE_FOR_TO_ROOT;
...@@ -785,9 +788,9 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from) ...@@ -785,9 +788,9 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from)
/* create directory with root as base to prevent excess chmods */ /* create directory with root as base to prevent excess chmods */
if (!error) if (!error)
error = git_futils_mkdir( error = git_futils_mkdir_relative(
from->ptr + info->from_prefix, info->to_root, from->ptr + info->from_prefix, info->to_root,
info->dirmode, info->mkdir_flags); info->dirmode, info->mkdir_flags, NULL);
return error; return error;
} }
......
...@@ -55,12 +55,9 @@ extern int git_futils_creat_locked(const char *path, const mode_t mode); ...@@ -55,12 +55,9 @@ extern int git_futils_creat_locked(const char *path, const mode_t mode);
extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode); extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode);
/** /**
* Create a path recursively * Create a path recursively.
*
* If a base parameter is being passed, it's expected to be valued with a
* path pointing to an already existing directory.
*/ */
extern int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode); extern int git_futils_mkdir_r(const char *path, const mode_t mode);
/** /**
* Flags to pass to `git_futils_mkdir`. * Flags to pass to `git_futils_mkdir`.
...@@ -111,20 +108,20 @@ struct git_futils_mkdir_options ...@@ -111,20 +108,20 @@ struct git_futils_mkdir_options
* and optionally chmods the directory immediately after (or each part of the * and optionally chmods the directory immediately after (or each part of the
* path if requested). * path if requested).
* *
* @param path The path to create. * @param path The path to create, relative to base.
* @param base Root for relative path. These directories will never be made. * @param base Root for relative path. These directories will never be made.
* @param mode The mode to use for created directories. * @param mode The mode to use for created directories.
* @param flags Combination of the mkdir flags above. * @param flags Combination of the mkdir flags above.
* @param opts Extended options, use `git_futils_mkdir` if you are not interested. * @param opts Extended options, or null.
* @return 0 on success, else error code * @return 0 on success, else error code
*/ */
extern int git_futils_mkdir_ext(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_options *opts); extern int git_futils_mkdir_relative(const char *path, const char *base, mode_t mode, uint32_t flags, struct git_futils_mkdir_options *opts);
/** /**
* Create a directory or entire path. Similar to `git_futils_mkdir_withperf` * Create a directory or entire path. Similar to `git_futils_mkdir_relative`
* without performance data. * without performance data.
*/ */
extern int git_futils_mkdir(const char *path, const char *base, mode_t mode, uint32_t flags); extern int git_futils_mkdir(const char *path, mode_t mode, uint32_t flags);
/** /**
* Create all the folders required to contain * Create all the folders required to contain
......
...@@ -84,9 +84,9 @@ static int object_file_name( ...@@ -84,9 +84,9 @@ static int object_file_name(
static int object_mkdir(const git_buf *name, const loose_backend *be) static int object_mkdir(const git_buf *name, const loose_backend *be)
{ {
return git_futils_mkdir( return git_futils_mkdir_relative(
name->ptr + be->objects_dirlen, be->objects_dir, be->object_dir_mode, name->ptr + be->objects_dirlen, be->objects_dir, be->object_dir_mode,
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR); GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR, NULL);
} }
static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj) static size_t get_binary_object_header(obj_hdr *hdr, git_buf *obj)
......
...@@ -1413,7 +1413,8 @@ static int setup_namespace(git_buf *path, git_repository *repo) ...@@ -1413,7 +1413,8 @@ static int setup_namespace(git_buf *path, git_repository *repo)
git__free(parts); git__free(parts);
/* Make sure that the folder with the namespace exists */ /* Make sure that the folder with the namespace exists */
if (git_futils_mkdir_r(git_buf_cstr(path), repo->path_repository, 0777) < 0) if (git_futils_mkdir_relative(git_buf_cstr(path), repo->path_repository,
0777, GIT_MKDIR_PATH, NULL) < 0)
return -1; return -1;
/* Return root of the namespaced path, i.e. without the trailing '/refs' */ /* Return root of the namespaced path, i.e. without the trailing '/refs' */
......
...@@ -1441,8 +1441,8 @@ static int repo_init_structure( ...@@ -1441,8 +1441,8 @@ static int repo_init_structure(
if (chmod) if (chmod)
mkdir_flags |= GIT_MKDIR_CHMOD; mkdir_flags |= GIT_MKDIR_CHMOD;
error = git_futils_mkdir( error = git_futils_mkdir_relative(
tpl->path, repo_dir, dmode, mkdir_flags); tpl->path, repo_dir, dmode, mkdir_flags, NULL);
} }
else if (!external_tpl) { else if (!external_tpl) {
const char *content = tpl->content; const char *content = tpl->content;
...@@ -1464,7 +1464,7 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2) ...@@ -1464,7 +1464,7 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
* don't try to set gid or grant world write access * don't try to set gid or grant world write access
*/ */
return git_futils_mkdir( return git_futils_mkdir(
buf->ptr, NULL, mode & ~(S_ISGID | 0002), buf->ptr, mode & ~(S_ISGID | 0002),
GIT_MKDIR_PATH | GIT_MKDIR_VERIFY_DIR | GIT_MKDIR_PATH | GIT_MKDIR_VERIFY_DIR |
(skip2 ? GIT_MKDIR_SKIP_LAST2 : GIT_MKDIR_SKIP_LAST)); (skip2 ? GIT_MKDIR_SKIP_LAST2 : GIT_MKDIR_SKIP_LAST));
} }
...@@ -1568,14 +1568,14 @@ static int repo_init_directories( ...@@ -1568,14 +1568,14 @@ static int repo_init_directories(
/* create path #4 */ /* create path #4 */
if (wd_path->size > 0 && if (wd_path->size > 0 &&
(error = git_futils_mkdir( (error = git_futils_mkdir(
wd_path->ptr, NULL, dirmode & ~S_ISGID, wd_path->ptr, dirmode & ~S_ISGID,
GIT_MKDIR_VERIFY_DIR)) < 0) GIT_MKDIR_VERIFY_DIR)) < 0)
return error; return error;
/* create path #2 (if not the same as #4) */ /* create path #2 (if not the same as #4) */
if (!natural_wd && if (!natural_wd &&
(error = git_futils_mkdir( (error = git_futils_mkdir(
repo_path->ptr, NULL, dirmode & ~S_ISGID, repo_path->ptr, dirmode & ~S_ISGID,
GIT_MKDIR_VERIFY_DIR | GIT_MKDIR_SKIP_LAST)) < 0) GIT_MKDIR_VERIFY_DIR | GIT_MKDIR_SKIP_LAST)) < 0)
return error; return error;
} }
...@@ -1585,7 +1585,7 @@ static int repo_init_directories( ...@@ -1585,7 +1585,7 @@ static int repo_init_directories(
has_dotgit) has_dotgit)
{ {
/* create path #1 */ /* create path #1 */
error = git_futils_mkdir(repo_path->ptr, NULL, dirmode, error = git_futils_mkdir(repo_path->ptr, dirmode,
GIT_MKDIR_VERIFY_DIR | ((dirmode & S_ISGID) ? GIT_MKDIR_CHMOD : 0)); GIT_MKDIR_VERIFY_DIR | ((dirmode & S_ISGID) ? GIT_MKDIR_CHMOD : 0));
} }
......
...@@ -63,7 +63,7 @@ void test_checkout_index__can_remove_untracked_files(void) ...@@ -63,7 +63,7 @@ void test_checkout_index__can_remove_untracked_files(void)
{ {
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_futils_mkdir("./testrepo/dir/subdir/subsubdir", NULL, 0755, GIT_MKDIR_PATH); git_futils_mkdir("./testrepo/dir/subdir/subsubdir", 0755, GIT_MKDIR_PATH);
cl_git_mkfile("./testrepo/dir/one", "one\n"); cl_git_mkfile("./testrepo/dir/one", "one\n");
cl_git_mkfile("./testrepo/dir/subdir/two", "two\n"); cl_git_mkfile("./testrepo/dir/subdir/two", "two\n");
......
...@@ -6,17 +6,17 @@ void test_config_global__initialize(void) ...@@ -6,17 +6,17 @@ void test_config_global__initialize(void)
{ {
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
cl_git_pass(git_futils_mkdir_r("home", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("home", 0777));
cl_git_pass(git_path_prettify(&path, "home", NULL)); cl_git_pass(git_path_prettify(&path, "home", NULL));
cl_git_pass(git_libgit2_opts( cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_futils_mkdir_r("xdg/git", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("xdg/git", 0777));
cl_git_pass(git_path_prettify(&path, "xdg/git", NULL)); cl_git_pass(git_path_prettify(&path, "xdg/git", NULL));
cl_git_pass(git_libgit2_opts( cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
cl_git_pass(git_futils_mkdir_r("etc", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("etc", 0777));
cl_git_pass(git_path_prettify(&path, "etc", NULL)); cl_git_pass(git_path_prettify(&path, "etc", NULL));
cl_git_pass(git_libgit2_opts( cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
......
...@@ -929,7 +929,7 @@ void test_core_buffer__similarity_metric(void) ...@@ -929,7 +929,7 @@ void test_core_buffer__similarity_metric(void)
cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1)); cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
cl_git_pass(git_futils_mkdir("scratch", NULL, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH));
cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1); cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1);
cl_git_pass(git_hashsig_create_fromfile( cl_git_pass(git_hashsig_create_fromfile(
&b, "scratch/testdata", GIT_HASHSIG_NORMAL)); &b, "scratch/testdata", GIT_HASHSIG_NORMAL));
......
...@@ -25,7 +25,7 @@ void test_core_copy__file_in_dir(void) ...@@ -25,7 +25,7 @@ void test_core_copy__file_in_dir(void)
struct stat st; struct stat st;
const char *content = "This is some other stuff to copy\n"; const char *content = "This is some other stuff to copy\n";
cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", 0775, GIT_MKDIR_PATH));
cl_git_mkfile("an_dir/in_a_dir/copy_me", content); cl_git_mkfile("an_dir/in_a_dir/copy_me", content);
cl_assert(git_path_isdir("an_dir")); cl_assert(git_path_isdir("an_dir"));
...@@ -60,9 +60,9 @@ void test_core_copy__tree(void) ...@@ -60,9 +60,9 @@ void test_core_copy__tree(void)
struct stat st; struct stat st;
const char *content = "File content\n"; const char *content = "File content\n";
cl_git_pass(git_futils_mkdir("src/b", NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("src/b", 0775, GIT_MKDIR_PATH));
cl_git_pass(git_futils_mkdir("src/c/d", NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("src/c/d", 0775, GIT_MKDIR_PATH));
cl_git_pass(git_futils_mkdir("src/c/e", NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("src/c/e", 0775, GIT_MKDIR_PATH));
cl_git_mkfile("src/f1", content); cl_git_mkfile("src/f1", content);
cl_git_mkfile("src/b/f2", content); cl_git_mkfile("src/b/f2", content);
......
...@@ -19,37 +19,37 @@ void test_core_mkdir__basic(void) ...@@ -19,37 +19,37 @@ void test_core_mkdir__basic(void)
/* make a directory */ /* make a directory */
cl_assert(!git_path_isdir("d0")); cl_assert(!git_path_isdir("d0"));
cl_git_pass(git_futils_mkdir("d0", NULL, 0755, 0)); cl_git_pass(git_futils_mkdir("d0", 0755, 0));
cl_assert(git_path_isdir("d0")); cl_assert(git_path_isdir("d0"));
/* make a path */ /* make a path */
cl_assert(!git_path_isdir("d1")); cl_assert(!git_path_isdir("d1"));
cl_git_pass(git_futils_mkdir("d1/d1.1/d1.2", NULL, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("d1/d1.1/d1.2", 0755, GIT_MKDIR_PATH));
cl_assert(git_path_isdir("d1")); cl_assert(git_path_isdir("d1"));
cl_assert(git_path_isdir("d1/d1.1")); cl_assert(git_path_isdir("d1/d1.1"));
cl_assert(git_path_isdir("d1/d1.1/d1.2")); cl_assert(git_path_isdir("d1/d1.1/d1.2"));
/* make a dir exclusively */ /* make a dir exclusively */
cl_assert(!git_path_isdir("d2")); cl_assert(!git_path_isdir("d2"));
cl_git_pass(git_futils_mkdir("d2", NULL, 0755, GIT_MKDIR_EXCL)); cl_git_pass(git_futils_mkdir("d2", 0755, GIT_MKDIR_EXCL));
cl_assert(git_path_isdir("d2")); cl_assert(git_path_isdir("d2"));
/* make exclusive failure */ /* make exclusive failure */
cl_git_fail(git_futils_mkdir("d2", NULL, 0755, GIT_MKDIR_EXCL)); cl_git_fail(git_futils_mkdir("d2", 0755, GIT_MKDIR_EXCL));
/* make a path exclusively */ /* make a path exclusively */
cl_assert(!git_path_isdir("d3")); cl_assert(!git_path_isdir("d3"));
cl_git_pass(git_futils_mkdir("d3/d3.1/d3.2", NULL, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); cl_git_pass(git_futils_mkdir("d3/d3.1/d3.2", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
cl_assert(git_path_isdir("d3")); cl_assert(git_path_isdir("d3"));
cl_assert(git_path_isdir("d3/d3.1/d3.2")); cl_assert(git_path_isdir("d3/d3.1/d3.2"));
/* make exclusive path failure */ /* make exclusive path failure */
cl_git_fail(git_futils_mkdir("d3/d3.1/d3.2", NULL, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); cl_git_fail(git_futils_mkdir("d3/d3.1/d3.2", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL));
/* ??? Should EXCL only apply to the last item in the path? */ /* ??? Should EXCL only apply to the last item in the path? */
/* path with trailing slash? */ /* path with trailing slash? */
cl_assert(!git_path_isdir("d4")); cl_assert(!git_path_isdir("d4"));
cl_git_pass(git_futils_mkdir("d4/d4.1/", NULL, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("d4/d4.1/", 0755, GIT_MKDIR_PATH));
cl_assert(git_path_isdir("d4/d4.1")); cl_assert(git_path_isdir("d4/d4.1"));
} }
...@@ -65,38 +65,38 @@ void test_core_mkdir__with_base(void) ...@@ -65,38 +65,38 @@ void test_core_mkdir__with_base(void)
cl_set_cleanup(cleanup_basedir, NULL); cl_set_cleanup(cleanup_basedir, NULL);
cl_git_pass(git_futils_mkdir(BASEDIR, NULL, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir(BASEDIR, 0755, GIT_MKDIR_PATH));
cl_git_pass(git_futils_mkdir("a", BASEDIR, 0755, 0)); cl_git_pass(git_futils_mkdir_relative("a", BASEDIR, 0755, 0, NULL));
cl_assert(git_path_isdir(BASEDIR "/a")); cl_assert(git_path_isdir(BASEDIR "/a"));
cl_git_pass(git_futils_mkdir("b/b1/b2", BASEDIR, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir_relative("b/b1/b2", BASEDIR, 0755, GIT_MKDIR_PATH, NULL));
cl_assert(git_path_isdir(BASEDIR "/b/b1/b2")); cl_assert(git_path_isdir(BASEDIR "/b/b1/b2"));
/* exclusive with existing base */ /* exclusive with existing base */
cl_git_pass(git_futils_mkdir("c/c1/c2", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); cl_git_pass(git_futils_mkdir_relative("c/c1/c2", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL));
/* fail: exclusive with duplicated suffix */ /* fail: exclusive with duplicated suffix */
cl_git_fail(git_futils_mkdir("c/c1/c3", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); cl_git_fail(git_futils_mkdir_relative("c/c1/c3", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL));
/* fail: exclusive with any duplicated component */ /* fail: exclusive with any duplicated component */
cl_git_fail(git_futils_mkdir("c/cz/cz", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); cl_git_fail(git_futils_mkdir_relative("c/cz/cz", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL));
/* success: exclusive without path */ /* success: exclusive without path */
cl_git_pass(git_futils_mkdir("c/c1/c3", BASEDIR, 0755, GIT_MKDIR_EXCL)); cl_git_pass(git_futils_mkdir_relative("c/c1/c3", BASEDIR, 0755, GIT_MKDIR_EXCL, NULL));
/* path with shorter base and existing dirs */ /* path with shorter base and existing dirs */
cl_git_pass(git_futils_mkdir("dir/here/d/", "base", 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir_relative("dir/here/d/", "base", 0755, GIT_MKDIR_PATH, NULL));
cl_assert(git_path_isdir("base/dir/here/d")); cl_assert(git_path_isdir("base/dir/here/d"));
/* fail: path with shorter base and existing dirs */ /* fail: path with shorter base and existing dirs */
cl_git_fail(git_futils_mkdir("dir/here/e/", "base", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); cl_git_fail(git_futils_mkdir_relative("dir/here/e/", "base", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL));
/* fail: base with missing components */ /* fail: base with missing components */
cl_git_fail(git_futils_mkdir("f/", "base/missing", 0755, GIT_MKDIR_PATH)); cl_git_fail(git_futils_mkdir_relative("f/", "base/missing", 0755, GIT_MKDIR_PATH, NULL));
/* success: shift missing component to path */ /* success: shift missing component to path */
cl_git_pass(git_futils_mkdir("missing/f/", "base/", 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir_relative("missing/f/", "base/", 0755, GIT_MKDIR_PATH, NULL));
} }
static void cleanup_chmod_root(void *ref) static void cleanup_chmod_root(void *ref)
...@@ -135,9 +135,9 @@ void test_core_mkdir__chmods(void) ...@@ -135,9 +135,9 @@ void test_core_mkdir__chmods(void)
cl_set_cleanup(cleanup_chmod_root, old); cl_set_cleanup(cleanup_chmod_root, old);
cl_git_pass(git_futils_mkdir("r", NULL, 0777, 0)); cl_git_pass(git_futils_mkdir("r", 0777, 0));
cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH, NULL));
cl_git_pass(git_path_lstat("r/mode", &st)); cl_git_pass(git_path_lstat("r/mode", &st));
check_mode(0755, st.st_mode); check_mode(0755, st.st_mode);
...@@ -146,7 +146,7 @@ void test_core_mkdir__chmods(void) ...@@ -146,7 +146,7 @@ void test_core_mkdir__chmods(void)
cl_git_pass(git_path_lstat("r/mode/is/important", &st)); cl_git_pass(git_path_lstat("r/mode/is/important", &st));
check_mode(0755, st.st_mode); check_mode(0755, st.st_mode);
cl_git_pass(git_futils_mkdir("mode2/is2/important2", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD)); cl_git_pass(git_futils_mkdir_relative("mode2/is2/important2", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD, NULL));
cl_git_pass(git_path_lstat("r/mode2", &st)); cl_git_pass(git_path_lstat("r/mode2", &st));
check_mode(0755, st.st_mode); check_mode(0755, st.st_mode);
...@@ -155,7 +155,7 @@ void test_core_mkdir__chmods(void) ...@@ -155,7 +155,7 @@ void test_core_mkdir__chmods(void)
cl_git_pass(git_path_lstat("r/mode2/is2/important2", &st)); cl_git_pass(git_path_lstat("r/mode2/is2/important2", &st));
check_mode(0777, st.st_mode); check_mode(0777, st.st_mode);
cl_git_pass(git_futils_mkdir("mode3/is3/important3", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH)); cl_git_pass(git_futils_mkdir_relative("mode3/is3/important3", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH, NULL));
cl_git_pass(git_path_lstat("r/mode3", &st)); cl_git_pass(git_path_lstat("r/mode3", &st));
check_mode(0777, st.st_mode); check_mode(0777, st.st_mode);
...@@ -166,7 +166,7 @@ void test_core_mkdir__chmods(void) ...@@ -166,7 +166,7 @@ void test_core_mkdir__chmods(void)
/* test that we chmod existing dir */ /* test that we chmod existing dir */
cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD)); cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD, NULL));
cl_git_pass(git_path_lstat("r/mode", &st)); cl_git_pass(git_path_lstat("r/mode", &st));
check_mode(0755, st.st_mode); check_mode(0755, st.st_mode);
...@@ -177,7 +177,7 @@ void test_core_mkdir__chmods(void) ...@@ -177,7 +177,7 @@ void test_core_mkdir__chmods(void)
/* test that we chmod even existing dirs if CHMOD_PATH is set */ /* test that we chmod even existing dirs if CHMOD_PATH is set */
cl_git_pass(git_futils_mkdir("mode2/is2/important2.1", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH)); cl_git_pass(git_futils_mkdir_relative("mode2/is2/important2.1", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH, NULL));
cl_git_pass(git_path_lstat("r/mode2", &st)); cl_git_pass(git_path_lstat("r/mode2", &st));
check_mode(0777, st.st_mode); check_mode(0777, st.st_mode);
...@@ -200,8 +200,8 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) ...@@ -200,8 +200,8 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void)
*old = p_umask(022); *old = p_umask(022);
cl_set_cleanup(cleanup_chmod_root, old); cl_set_cleanup(cleanup_chmod_root, old);
cl_git_pass(git_futils_mkdir("r", NULL, 0777, 0)); cl_git_pass(git_futils_mkdir("r", 0777, 0));
cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH, NULL));
cl_git_pass(git_path_lstat("r/mode", &st)); cl_git_pass(git_path_lstat("r/mode", &st));
check_mode(0755, st.st_mode); check_mode(0755, st.st_mode);
...@@ -210,7 +210,7 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) ...@@ -210,7 +210,7 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void)
check_mode(0111, st.st_mode); check_mode(0111, st.st_mode);
cl_git_pass( cl_git_pass(
git_futils_mkdir("mode/is/okay/inside", "r", 0777, GIT_MKDIR_PATH)); git_futils_mkdir_relative("mode/is/okay/inside", "r", 0777, GIT_MKDIR_PATH, NULL));
cl_git_pass(git_path_lstat("r/mode/is/okay/inside", &st)); cl_git_pass(git_path_lstat("r/mode/is/okay/inside", &st));
check_mode(0755, st.st_mode); check_mode(0755, st.st_mode);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
void test_core_stat__initialize(void) void test_core_stat__initialize(void)
{ {
cl_git_pass(git_futils_mkdir("root/d1/d2", NULL, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("root/d1/d2", 0755, GIT_MKDIR_PATH));
cl_git_mkfile("root/file", "whatever\n"); cl_git_mkfile("root/file", "whatever\n");
cl_git_mkfile("root/d1/file", "whatever\n"); cl_git_mkfile("root/d1/file", "whatever\n");
} }
......
...@@ -752,7 +752,7 @@ void test_index_tests__reload_from_disk(void) ...@@ -752,7 +752,7 @@ void test_index_tests__reload_from_disk(void)
cl_set_cleanup(&cleanup_myrepo, NULL); cl_set_cleanup(&cleanup_myrepo, NULL);
cl_git_pass(git_futils_mkdir("./myrepo", NULL, 0777, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir("./myrepo", 0777, GIT_MKDIR_PATH));
cl_git_mkfile("./myrepo/a.txt", "a\n"); cl_git_mkfile("./myrepo/a.txt", "a\n");
cl_git_mkfile("./myrepo/b.txt", "b\n"); cl_git_mkfile("./myrepo/b.txt", "b\n");
......
...@@ -29,7 +29,7 @@ static void init_linked_repo(const char *path, const char *alternate) ...@@ -29,7 +29,7 @@ static void init_linked_repo(const char *path, const char *alternate)
cl_git_pass(git_path_prettify(&destpath, alternate, NULL)); cl_git_pass(git_path_prettify(&destpath, alternate, NULL));
cl_git_pass(git_buf_joinpath(&destpath, destpath.ptr, "objects")); cl_git_pass(git_buf_joinpath(&destpath, destpath.ptr, "objects"));
cl_git_pass(git_buf_joinpath(&filepath, git_repository_path(repo), "objects/info")); cl_git_pass(git_buf_joinpath(&filepath, git_repository_path(repo), "objects/info"));
cl_git_pass(git_futils_mkdir(filepath.ptr, NULL, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir(filepath.ptr, 0755, GIT_MKDIR_PATH));
cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates")); cl_git_pass(git_buf_joinpath(&filepath, filepath.ptr , "alternates"));
cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0, 0666)); cl_git_pass(git_filebuf_open(&file, git_buf_cstr(&filepath), 0, 0666));
......
...@@ -36,7 +36,7 @@ void test_refs_pack__empty(void) ...@@ -36,7 +36,7 @@ void test_refs_pack__empty(void)
git_buf temp_path = GIT_BUF_INIT; git_buf temp_path = GIT_BUF_INIT;
cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir")); cl_git_pass(git_buf_join_n(&temp_path, '/', 3, git_repository_path(g_repo), GIT_REFS_HEADS_DIR, "empty_dir"));
cl_git_pass(git_futils_mkdir_r(temp_path.ptr, NULL, GIT_REFS_DIR_MODE)); cl_git_pass(git_futils_mkdir_r(temp_path.ptr, GIT_REFS_DIR_MODE));
git_buf_free(&temp_path); git_buf_free(&temp_path);
packall(); packall();
......
...@@ -77,7 +77,7 @@ void test_repo_discover__0(void) ...@@ -77,7 +77,7 @@ void test_repo_discover__0(void)
const char *ceiling_dirs; const char *ceiling_dirs;
const mode_t mode = 0777; const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, NULL, mode); git_futils_mkdir_r(DISCOVER_FOLDER, mode);
append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER); append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER);
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf); ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
...@@ -88,15 +88,15 @@ void test_repo_discover__0(void) ...@@ -88,15 +88,15 @@ void test_repo_discover__0(void)
git_repository_free(repo); git_repository_free(repo);
cl_git_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0)); cl_git_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
cl_git_pass(git_repository_discover(&sub_repository_path, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); cl_git_pass(git_repository_discover(&sub_repository_path, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, &sub_repository_path); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, &sub_repository_path); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, &sub_repository_path);
cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode));
write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT); write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT); write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../"); write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../");
...@@ -105,13 +105,13 @@ void test_repo_discover__0(void) ...@@ -105,13 +105,13 @@ void test_repo_discover__0(void)
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, &sub_repository_path);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, &repository_path); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, &repository_path);
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, mode));
write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:"); write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, mode));
write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:"); write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, mode));
write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n"); write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, mode));
write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist"); write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist");
cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(&found_path, ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
......
...@@ -99,7 +99,7 @@ void test_repo_init__bare_repo_escaping_current_workdir(void) ...@@ -99,7 +99,7 @@ void test_repo_init__bare_repo_escaping_current_workdir(void)
cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL)); cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c")); cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c"));
cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), NULL, GIT_DIR_MODE)); cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE));
/* Change the current working directory */ /* Change the current working directory */
cl_git_pass(chdir(git_buf_cstr(&path_repository))); cl_git_pass(chdir(git_buf_cstr(&path_repository)));
...@@ -312,7 +312,7 @@ void test_repo_init__extended_0(void) ...@@ -312,7 +312,7 @@ void test_repo_init__extended_0(void)
cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts)); cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts));
/* make the directory first, then it should succeed */ /* make the directory first, then it should succeed */
cl_git_pass(git_futils_mkdir("extended", NULL, 0775, 0)); cl_git_pass(git_futils_mkdir("extended", 0775, 0));
cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts)); cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts));
cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/")); cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/"));
...@@ -631,7 +631,7 @@ void test_repo_init__can_reinit_an_initialized_repository(void) ...@@ -631,7 +631,7 @@ void test_repo_init__can_reinit_an_initialized_repository(void)
cl_set_cleanup(&cleanup_repository, "extended"); cl_set_cleanup(&cleanup_repository, "extended");
cl_git_pass(git_futils_mkdir("extended", NULL, 0775, 0)); cl_git_pass(git_futils_mkdir("extended", 0775, 0));
cl_git_pass(git_repository_init(&_repo, "extended", false)); cl_git_pass(git_repository_init(&_repo, "extended", false));
cl_git_pass(git_repository_init(&reinit, "extended", false)); cl_git_pass(git_repository_init(&reinit, "extended", false));
......
...@@ -848,14 +848,14 @@ static void build_workdir_tree(const char *root, int dirs, int subs) ...@@ -848,14 +848,14 @@ static void build_workdir_tree(const char *root, int dirs, int subs)
for (i = 0; i < dirs; ++i) { for (i = 0; i < dirs; ++i) {
if (i % 2 == 0) { if (i % 2 == 0) {
p_snprintf(buf, sizeof(buf), "%s/dir%02d", root, i); p_snprintf(buf, sizeof(buf), "%s/dir%02d", root, i);
cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir(buf, 0775, GIT_MKDIR_PATH));
p_snprintf(buf, sizeof(buf), "%s/dir%02d/file", root, i); p_snprintf(buf, sizeof(buf), "%s/dir%02d/file", root, i);
cl_git_mkfile(buf, buf); cl_git_mkfile(buf, buf);
buf[strlen(buf) - 5] = '\0'; buf[strlen(buf) - 5] = '\0';
} else { } else {
p_snprintf(buf, sizeof(buf), "%s/DIR%02d", root, i); p_snprintf(buf, sizeof(buf), "%s/DIR%02d", root, i);
cl_git_pass(git_futils_mkdir(buf, NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir(buf, 0775, GIT_MKDIR_PATH));
} }
for (j = 0; j < subs; ++j) { for (j = 0; j < subs; ++j) {
...@@ -865,7 +865,7 @@ static void build_workdir_tree(const char *root, int dirs, int subs) ...@@ -865,7 +865,7 @@ static void build_workdir_tree(const char *root, int dirs, int subs)
case 2: p_snprintf(sub, sizeof(sub), "%s/Sub%02d", buf, j); break; case 2: p_snprintf(sub, sizeof(sub), "%s/Sub%02d", buf, j); break;
case 3: p_snprintf(sub, sizeof(sub), "%s/SUB%02d", buf, j); break; case 3: p_snprintf(sub, sizeof(sub), "%s/SUB%02d", buf, j); break;
} }
cl_git_pass(git_futils_mkdir(sub, NULL, 0775, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir(sub, 0775, GIT_MKDIR_PATH));
if (j % 2 == 0) { if (j % 2 == 0) {
size_t sublen = strlen(sub); size_t sublen = strlen(sub);
......
...@@ -91,7 +91,7 @@ static void make_gitlink_dir(const char *dir, const char *linktext) ...@@ -91,7 +91,7 @@ static void make_gitlink_dir(const char *dir, const char *linktext)
{ {
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
cl_git_pass(git_futils_mkdir(dir, NULL, 0777, GIT_MKDIR_VERIFY_DIR)); cl_git_pass(git_futils_mkdir(dir, 0777, GIT_MKDIR_VERIFY_DIR));
cl_git_pass(git_buf_joinpath(&path, dir, ".git")); cl_git_pass(git_buf_joinpath(&path, dir, ".git"));
cl_git_rewritefile(path.ptr, linktext); cl_git_rewritefile(path.ptr, linktext);
git_buf_free(&path); git_buf_free(&path);
...@@ -222,7 +222,7 @@ void test_repo_open__bad_gitlinks(void) ...@@ -222,7 +222,7 @@ void test_repo_open__bad_gitlinks(void)
cl_git_sandbox_init("attr"); cl_git_sandbox_init("attr");
cl_git_pass(p_mkdir("invalid", 0777)); cl_git_pass(p_mkdir("invalid", 0777));
cl_git_pass(git_futils_mkdir_r("invalid2/.git", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("invalid2/.git", 0777));
for (scan = bad_links; *scan != NULL; scan++) { for (scan = bad_links; *scan != NULL; scan++) {
make_gitlink_dir("alternate", *scan); make_gitlink_dir("alternate", *scan);
......
...@@ -148,7 +148,7 @@ void test_status_ignore__ignore_pattern_contains_space(void) ...@@ -148,7 +148,7 @@ void test_status_ignore__ignore_pattern_contains_space(void)
cl_git_pass(git_status_file(&flags, g_repo, "foo bar.txt")); cl_git_pass(git_status_file(&flags, g_repo, "foo bar.txt"));
cl_assert(flags == GIT_STATUS_IGNORED); cl_assert(flags == GIT_STATUS_IGNORED);
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/foo", NULL, mode)); cl_git_pass(git_futils_mkdir_r("empty_standard_repo/foo", mode));
cl_git_mkfile("empty_standard_repo/foo/look-ma.txt", "I'm not going to be ignored!"); cl_git_mkfile("empty_standard_repo/foo/look-ma.txt", "I'm not going to be ignored!");
cl_git_pass(git_status_file(&flags, g_repo, "foo/look-ma.txt")); cl_git_pass(git_status_file(&flags, g_repo, "foo/look-ma.txt"));
...@@ -206,7 +206,7 @@ void test_status_ignore__subdirectories(void) ...@@ -206,7 +206,7 @@ void test_status_ignore__subdirectories(void)
* used a rooted path for an ignore, so I changed this behavior. * used a rooted path for an ignore, so I changed this behavior.
*/ */
cl_git_pass(git_futils_mkdir_r( cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/test/ignore_me", NULL, 0775)); "empty_standard_repo/test/ignore_me", 0775));
cl_git_mkfile( cl_git_mkfile(
"empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!"); "empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!");
cl_git_mkfile( cl_git_mkfile(
...@@ -230,9 +230,9 @@ static void make_test_data(const char *reponame, const char **files) ...@@ -230,9 +230,9 @@ static void make_test_data(const char *reponame, const char **files)
g_repo = cl_git_sandbox_init(reponame); g_repo = cl_git_sandbox_init(reponame);
for (scan = files; *scan != NULL; ++scan) { for (scan = files; *scan != NULL; ++scan) {
cl_git_pass(git_futils_mkdir( cl_git_pass(git_futils_mkdir_relative(
*scan + repolen, reponame, *scan + repolen, reponame,
0777, GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST)); 0777, GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST, NULL));
cl_git_mkfile(*scan, "contents"); cl_git_mkfile(*scan, "contents");
} }
} }
...@@ -612,7 +612,7 @@ void test_status_ignore__issue_1766_negated_ignores(void) ...@@ -612,7 +612,7 @@ void test_status_ignore__issue_1766_negated_ignores(void)
g_repo = cl_git_sandbox_init("empty_standard_repo"); g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_futils_mkdir_r( cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/a", NULL, 0775)); "empty_standard_repo/a", 0775));
cl_git_mkfile( cl_git_mkfile(
"empty_standard_repo/a/.gitignore", "*\n!.gitignore\n"); "empty_standard_repo/a/.gitignore", "*\n!.gitignore\n");
cl_git_mkfile( cl_git_mkfile(
...@@ -622,7 +622,7 @@ void test_status_ignore__issue_1766_negated_ignores(void) ...@@ -622,7 +622,7 @@ void test_status_ignore__issue_1766_negated_ignores(void)
assert_is_ignored("a/ignoreme"); assert_is_ignored("a/ignoreme");
cl_git_pass(git_futils_mkdir_r( cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/b", NULL, 0775)); "empty_standard_repo/b", 0775));
cl_git_mkfile( cl_git_mkfile(
"empty_standard_repo/b/.gitignore", "*\n!.gitignore\n"); "empty_standard_repo/b/.gitignore", "*\n!.gitignore\n");
cl_git_mkfile( cl_git_mkfile(
...@@ -1033,7 +1033,7 @@ void test_status_ignore__negate_starstar(void) ...@@ -1033,7 +1033,7 @@ void test_status_ignore__negate_starstar(void)
"code/projects/**/packages/*\n" "code/projects/**/packages/*\n"
"!code/projects/**/packages/repositories.config"); "!code/projects/**/packages/repositories.config");
cl_git_pass(git_futils_mkdir_r("code/projects/foo/bar/packages", "empty_standard_repo", 0777)); cl_git_pass(git_futils_mkdir_r("empty_standard_repo/code/projects/foo/bar/packages", 0777));
cl_git_mkfile("empty_standard_repo/code/projects/foo/bar/packages/repositories.config", ""); cl_git_mkfile("empty_standard_repo/code/projects/foo/bar/packages/repositories.config", "");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "code/projects/foo/bar/packages/repositories.config")); cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "code/projects/foo/bar/packages/repositories.config"));
......
...@@ -195,7 +195,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void) ...@@ -195,7 +195,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
cl_git_pass(p_rename("status/subdir", "status/current_file")); cl_git_pass(p_rename("status/subdir", "status/current_file"));
cl_git_pass(p_rename("status/swap", "status/subdir")); cl_git_pass(p_rename("status/swap", "status/subdir"));
cl_git_mkfile("status/.new_file", "dummy"); cl_git_mkfile("status/.new_file", "dummy");
cl_git_pass(git_futils_mkdir_r("status/zzz_new_dir", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("status/zzz_new_dir", 0777));
cl_git_mkfile("status/zzz_new_dir/new_file", "dummy"); cl_git_mkfile("status/zzz_new_dir/new_file", "dummy");
cl_git_mkfile("status/zzz_new_file", "dummy"); cl_git_mkfile("status/zzz_new_file", "dummy");
...@@ -917,7 +917,7 @@ void test_status_worktree__long_filenames(void) ...@@ -917,7 +917,7 @@ void test_status_worktree__long_filenames(void)
// Create directory with amazingly long filename // Create directory with amazingly long filename
sprintf(path, "empty_standard_repo/%s", longname); sprintf(path, "empty_standard_repo/%s", longname);
cl_git_pass(git_futils_mkdir_r(path, NULL, 0777)); cl_git_pass(git_futils_mkdir_r(path, 0777));
sprintf(path, "empty_standard_repo/%s/foo", longname); sprintf(path, "empty_standard_repo/%s/foo", longname);
cl_git_mkfile(path, "dummy"); cl_git_mkfile(path, "dummy");
...@@ -1007,7 +1007,7 @@ void test_status_worktree__unreadable(void) ...@@ -1007,7 +1007,7 @@ void test_status_worktree__unreadable(void)
status_entry_counts counts = {0}; status_entry_counts counts = {0};
/* Create directory with no read permission */ /* Create directory with no read permission */
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", 0777));
cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy"); cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy");
p_chmod("empty_standard_repo/no_permission", 0644); p_chmod("empty_standard_repo/no_permission", 0644);
...@@ -1041,7 +1041,7 @@ void test_status_worktree__unreadable_not_included(void) ...@@ -1041,7 +1041,7 @@ void test_status_worktree__unreadable_not_included(void)
status_entry_counts counts = {0}; status_entry_counts counts = {0};
/* Create directory with no read permission */ /* Create directory with no read permission */
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", 0777));
cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy"); cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy");
p_chmod("empty_standard_repo/no_permission", 0644); p_chmod("empty_standard_repo/no_permission", 0644);
...@@ -1074,7 +1074,7 @@ void test_status_worktree__unreadable_as_untracked(void) ...@@ -1074,7 +1074,7 @@ void test_status_worktree__unreadable_as_untracked(void)
status_entry_counts counts = {0}; status_entry_counts counts = {0};
/* Create directory with no read permission */ /* Create directory with no read permission */
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", NULL, 0777)); cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", 0777));
cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy"); cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy");
p_chmod("empty_standard_repo/no_permission", 0644); p_chmod("empty_standard_repo/no_permission", 0644);
......
...@@ -92,7 +92,7 @@ void test_submodule_status__ignore_none(void) ...@@ -92,7 +92,7 @@ void test_submodule_status__ignore_none(void)
cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
/* now mkdir sm_unchanged to test uninitialized */ /* now mkdir sm_unchanged to test uninitialized */
cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); cl_git_pass(git_futils_mkdir_relative("sm_unchanged", "submod2", 0755, 0, NULL));
status = get_submodule_status(g_repo, "sm_unchanged"); status = get_submodule_status(g_repo, "sm_unchanged");
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
...@@ -141,7 +141,7 @@ void test_submodule_status__ignore_untracked(void) ...@@ -141,7 +141,7 @@ void test_submodule_status__ignore_untracked(void)
cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
/* now mkdir sm_unchanged to test uninitialized */ /* now mkdir sm_unchanged to test uninitialized */
cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); cl_git_pass(git_futils_mkdir_relative("sm_unchanged", "submod2", 0755, 0, NULL));
cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign));
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
...@@ -185,7 +185,7 @@ void test_submodule_status__ignore_dirty(void) ...@@ -185,7 +185,7 @@ void test_submodule_status__ignore_dirty(void)
cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0);
/* now mkdir sm_unchanged to test uninitialized */ /* now mkdir sm_unchanged to test uninitialized */
cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); cl_git_pass(git_futils_mkdir_relative("sm_unchanged", "submod2", 0755, 0, NULL));
cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign));
cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0);
...@@ -229,7 +229,7 @@ void test_submodule_status__ignore_all(void) ...@@ -229,7 +229,7 @@ void test_submodule_status__ignore_all(void)
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
/* now mkdir sm_unchanged to test uninitialized */ /* now mkdir sm_unchanged to test uninitialized */
cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); cl_git_pass(git_futils_mkdir_relative("sm_unchanged", "submod2", 0755, 0, NULL));
cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign));
cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status));
...@@ -338,7 +338,7 @@ void test_submodule_status__untracked_dirs_containing_ignored_files(void) ...@@ -338,7 +338,7 @@ void test_submodule_status__untracked_dirs_containing_ignored_files(void)
"submod2/.git/modules/sm_unchanged/info/exclude", "\n*.ignored\n"); "submod2/.git/modules/sm_unchanged/info/exclude", "\n*.ignored\n");
cl_git_pass( cl_git_pass(
git_futils_mkdir("sm_unchanged/directory", "submod2", 0755, 0)); git_futils_mkdir_relative("sm_unchanged/directory", "submod2", 0755, 0, NULL));
cl_git_mkfile( cl_git_mkfile(
"submod2/sm_unchanged/directory/i_am.ignored", "submod2/sm_unchanged/directory/i_am.ignored",
"ignore this file, please\n"); "ignore this file, please\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment