Commit 8d6052df by Carlos Martín Nieto

Merge pull request #3432 from ethomson/mkdir

`mkdir`: split into `mkdir` and `mkdir_relative`
parents add0378d 9ce2e7b3
...@@ -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);
} }
...@@ -289,97 +289,230 @@ void git_futils_mmap_free(git_map *out) ...@@ -289,97 +289,230 @@ void git_futils_mmap_free(git_map *out)
p_munmap(out); p_munmap(out);
} }
GIT_INLINE(int) validate_existing( GIT_INLINE(int) mkdir_validate_dir(
const char *make_path, const char *path,
struct stat *st, struct stat *st,
mode_t mode, mode_t mode,
uint32_t flags, uint32_t flags,
struct git_futils_mkdir_perfdata *perfdata) struct git_futils_mkdir_options *opts)
{ {
/* with exclusive create, existing dir is an error */
if ((flags & GIT_MKDIR_EXCL) != 0) {
giterr_set(GITERR_FILESYSTEM,
"Failed to make directory '%s': directory exists", path);
return GIT_EEXISTS;
}
if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) || if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
(S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) { (S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) {
if (p_unlink(make_path) < 0) { if (p_unlink(path) < 0) {
giterr_set(GITERR_OS, "Failed to remove %s '%s'", giterr_set(GITERR_OS, "Failed to remove %s '%s'",
S_ISLNK(st->st_mode) ? "symlink" : "file", make_path); S_ISLNK(st->st_mode) ? "symlink" : "file", path);
return GIT_EEXISTS; return GIT_EEXISTS;
} }
perfdata->mkdir_calls++; opts->perfdata.mkdir_calls++;
if (p_mkdir(make_path, mode) < 0) { if (p_mkdir(path, mode) < 0) {
giterr_set(GITERR_OS, "Failed to make directory '%s'", make_path); giterr_set(GITERR_OS, "Failed to make directory '%s'", path);
return GIT_EEXISTS; return GIT_EEXISTS;
} }
} }
else if (S_ISLNK(st->st_mode)) { else if (S_ISLNK(st->st_mode)) {
/* Re-stat the target, make sure it's a directory */ /* Re-stat the target, make sure it's a directory */
perfdata->stat_calls++; opts->perfdata.stat_calls++;
if (p_stat(make_path, st) < 0) { if (p_stat(path, st) < 0) {
giterr_set(GITERR_OS, "Failed to make directory '%s'", make_path); giterr_set(GITERR_OS, "Failed to make directory '%s'", path);
return GIT_EEXISTS; return GIT_EEXISTS;
} }
} }
else if (!S_ISDIR(st->st_mode)) { else if (!S_ISDIR(st->st_mode)) {
giterr_set(GITERR_FILESYSTEM, giterr_set(GITERR_FILESYSTEM,
"Failed to make directory '%s': directory exists", make_path); "Failed to make directory '%s': directory exists", path);
return GIT_EEXISTS; return GIT_EEXISTS;
} }
return 0; return 0;
} }
int git_futils_mkdir_ext( GIT_INLINE(int) mkdir_validate_mode(
const char *path, const char *path,
const char *base, struct stat *st,
bool terminal_path,
mode_t mode, mode_t mode,
uint32_t flags, uint32_t flags,
struct git_futils_mkdir_options *opts) struct git_futils_mkdir_options *opts)
{ {
int error = -1; if (((terminal_path && (flags & GIT_MKDIR_CHMOD) != 0) ||
git_buf make_path = GIT_BUF_INIT; (flags & GIT_MKDIR_CHMOD_PATH) != 0) && st->st_mode != mode) {
ssize_t root = 0, min_root_len, root_len;
char lastch = '/', *tail;
struct stat st;
/* build path and find "root" where we should start calling mkdir */ opts->perfdata.chmod_calls++;
if (git_path_join_unrooted(&make_path, path, base, &root) < 0)
return -1;
if (make_path.size == 0) { if (p_chmod(path, mode) < 0) {
giterr_set(GITERR_OS, "Attempt to create empty path"); giterr_set(GITERR_OS, "failed to set permissions on '%s'", path);
goto done; return -1;
}
}
return 0;
}
GIT_INLINE(int) mkdir_canonicalize(
git_buf *path,
uint32_t flags)
{
ssize_t root_len;
if (path->size == 0) {
giterr_set(GITERR_OS, "attempt to create empty path");
return -1;
} }
/* Trim trailing slashes (except the root) */ /* Trim trailing slashes (except the root) */
if ((root_len = git_path_root(make_path.ptr)) < 0) if ((root_len = git_path_root(path->ptr)) < 0)
root_len = 0; root_len = 0;
else else
root_len++; root_len++;
while (make_path.size > (size_t)root_len && while (path->size > (size_t)root_len && path->ptr[path->size - 1] == '/')
make_path.ptr[make_path.size - 1] == '/') path->ptr[--path->size] = '\0';
make_path.ptr[--make_path.size] = '\0';
/* if we are not supposed to made the last element, truncate it */ /* if we are not supposed to made the last element, truncate it */
if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) { if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
git_path_dirname_r(&make_path, make_path.ptr); git_path_dirname_r(path, path->ptr);
flags |= GIT_MKDIR_SKIP_LAST; flags |= GIT_MKDIR_SKIP_LAST;
} }
if ((flags & GIT_MKDIR_SKIP_LAST) != 0) { if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
git_path_dirname_r(&make_path, make_path.ptr); git_path_dirname_r(path, path->ptr);
} }
/* We were either given the root path (or trimmed it to /* We were either given the root path (or trimmed it to
* the root), we don't have anything to do. * the root), we don't have anything to do.
*/
if (path->size <= (size_t)root_len)
git_buf_clear(path);
return 0;
}
int git_futils_mkdir(
const char *path,
mode_t mode,
uint32_t flags)
{
git_buf make_path = GIT_BUF_INIT, parent_path = GIT_BUF_INIT;
const char *relative;
struct git_futils_mkdir_options opts = { 0 };
struct stat st;
size_t depth = 0;
int len = 0, root_len, error;
if ((error = git_buf_puts(&make_path, path)) < 0 ||
(error = mkdir_canonicalize(&make_path, flags)) < 0 ||
(error = git_buf_puts(&parent_path, make_path.ptr)) < 0 ||
make_path.size == 0)
goto done;
root_len = git_path_root(make_path.ptr);
/* find the first parent directory that exists. this will be used
* as the base to dirname_relative.
*/ */
if (make_path.size <= (size_t)root_len) { for (relative = make_path.ptr; parent_path.size; ) {
error = 0; error = p_lstat(parent_path.ptr, &st);
if (error == 0) {
break;
} else if (errno != ENOENT) {
giterr_set(GITERR_OS, "failed to stat '%s'", parent_path.ptr);
goto done;
}
depth++;
/* examine the parent of the current path */
if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) {
error = len;
goto done;
}
assert(len);
/* we've walked all the given path's parents and it's either relative
* or rooted. either way, give up and make the entire path.
*/
if ((len == 1 && parent_path.ptr[0] == '.') || len == root_len+1) {
relative = make_path.ptr;
break;
}
relative = make_path.ptr + len + 1;
/* not recursive? just make this directory relative to its parent. */
if ((flags & GIT_MKDIR_PATH) == 0)
break;
}
/* we found an item at the location we're trying to create,
* validate it.
*/
if (depth == 0) {
error = mkdir_validate_dir(make_path.ptr, &st, mode, flags, &opts);
if (!error)
error = mkdir_validate_mode(
make_path.ptr, &st, true, mode, flags, &opts);
goto done; goto done;
} }
/* we already took `SKIP_LAST` and `SKIP_LAST2` into account when
* canonicalizing `make_path`.
*/
flags &= ~(GIT_MKDIR_SKIP_LAST2 | GIT_MKDIR_SKIP_LAST);
error = git_futils_mkdir_relative(relative,
parent_path.size ? parent_path.ptr : NULL, mode, flags, &opts);
done:
git_buf_free(&make_path);
git_buf_free(&parent_path);
return error;
}
int git_futils_mkdir_r(const char *path, const mode_t mode)
{
return git_futils_mkdir(path, mode, GIT_MKDIR_PATH);
}
int git_futils_mkdir_relative(
const char *relative_path,
const char *base,
mode_t mode,
uint32_t flags,
struct git_futils_mkdir_options *opts)
{
git_buf make_path = GIT_BUF_INIT;
ssize_t root = 0, min_root_len;
char lastch = '/', *tail;
struct stat st;
struct git_futils_mkdir_options empty_opts = {0};
int error;
if (!opts)
opts = &empty_opts;
/* build path and find "root" where we should start calling mkdir */
if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0)
return -1;
if ((error = mkdir_canonicalize(&make_path, flags)) < 0 ||
make_path.size == 0)
goto done;
/* if we are not supposed to make the whole path, reset root */ /* if we are not supposed to make the whole path, reset root */
if ((flags & GIT_MKDIR_PATH) == 0) if ((flags & GIT_MKDIR_PATH) == 0)
root = git_buf_rfind(&make_path, '/'); root = git_buf_rfind(&make_path, '/');
...@@ -437,32 +570,15 @@ retry_lstat: ...@@ -437,32 +570,15 @@ retry_lstat:
goto done; goto done;
} }
} else { } else {
/* with exclusive create, existing dir is an error */ if ((error = mkdir_validate_dir(
if ((flags & GIT_MKDIR_EXCL) != 0) { make_path.ptr, &st, mode, flags, opts)) < 0)
giterr_set(GITERR_FILESYSTEM, "Failed to make directory '%s': directory exists", make_path.ptr);
error = GIT_EEXISTS;
goto done; goto done;
}
if ((error = validate_existing(
make_path.ptr, &st, mode, flags, &opts->perfdata)) < 0)
goto done;
} }
/* chmod if requested and necessary */ /* chmod if requested and necessary */
if (((flags & GIT_MKDIR_CHMOD_PATH) != 0 || if ((error = mkdir_validate_mode(
(lastch == '\0' && (flags & GIT_MKDIR_CHMOD) != 0)) && make_path.ptr, &st, (lastch == '\0'), mode, flags, opts)) < 0)
st.st_mode != mode) { goto done;
opts->perfdata.chmod_calls++;
if ((error = p_chmod(make_path.ptr, mode)) < 0 &&
lastch == '\0') {
giterr_set(GITERR_OS, "Failed to set permissions on '%s'",
make_path.ptr);
goto done;
}
}
if (opts->dir_map && opts->pool) { if (opts->dir_map && opts->pool) {
char *cache_path; char *cache_path;
...@@ -501,21 +617,6 @@ done: ...@@ -501,21 +617,6 @@ done:
return error; return error;
} }
int git_futils_mkdir(
const char *path,
const char *base,
mode_t mode,
uint32_t flags)
{
struct git_futils_mkdir_options options = {0};
return git_futils_mkdir_ext(path, base, mode, flags, &options);
}
int git_futils_mkdir_r(const char *path, const char *base, const mode_t mode)
{
return git_futils_mkdir(path, base, mode, GIT_MKDIR_PATH);
}
typedef struct { typedef struct {
const char *base; const char *base;
size_t baselen; size_t baselen;
...@@ -777,7 +878,7 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from) ...@@ -777,7 +878,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 +886,9 @@ static int _cp_r_mkdir(cp_r_info *info, git_buf *from) ...@@ -785,9 +886,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)
......
...@@ -526,6 +526,17 @@ bool git_path_isfile(const char *path) ...@@ -526,6 +526,17 @@ bool git_path_isfile(const char *path)
return S_ISREG(st.st_mode) != 0; return S_ISREG(st.st_mode) != 0;
} }
bool git_path_islink(const char *path)
{
struct stat st;
assert(path);
if (p_lstat(path, &st) < 0)
return false;
return S_ISLNK(st.st_mode) != 0;
}
#ifdef GIT_WIN32 #ifdef GIT_WIN32
bool git_path_is_empty_dir(const char *path) bool git_path_is_empty_dir(const char *path)
......
...@@ -72,7 +72,7 @@ extern const char *git_path_topdir(const char *path); ...@@ -72,7 +72,7 @@ extern const char *git_path_topdir(const char *path);
* This will return a number >= 0 which is the offset to the start of the * This will return a number >= 0 which is the offset to the start of the
* path, if the path is rooted (i.e. "/rooted/path" returns 0 and * path, if the path is rooted (i.e. "/rooted/path" returns 0 and
* "c:/windows/rooted/path" returns 2). If the path is not rooted, this * "c:/windows/rooted/path" returns 2). If the path is not rooted, this
* returns < 0. * returns -1.
*/ */
extern int git_path_root(const char *path); extern int git_path_root(const char *path);
...@@ -169,6 +169,12 @@ extern bool git_path_isdir(const char *path); ...@@ -169,6 +169,12 @@ extern bool git_path_isdir(const char *path);
extern bool git_path_isfile(const char *path); extern bool git_path_isfile(const char *path);
/** /**
* Check if the given path points to a symbolic link.
* @return true or false
*/
extern bool git_path_islink(const char *path);
/**
* Check if the given path is a directory, and is empty. * Check if the given path is a directory, and is empty.
*/ */
extern bool git_path_is_empty_dir(const char *path); extern bool git_path_is_empty_dir(const char *path);
......
...@@ -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));
} }
......
...@@ -148,12 +148,19 @@ static int lstat_w( ...@@ -148,12 +148,19 @@ static int lstat_w(
return git_win32__file_attribute_to_stat(buf, &fdata, path); return git_win32__file_attribute_to_stat(buf, &fdata, path);
} }
errno = ENOENT; switch (GetLastError()) {
case ERROR_ACCESS_DENIED:
errno = EACCES;
break;
default:
errno = ENOENT;
break;
}
/* To match POSIX behavior, set ENOTDIR when any of the folders in the /* To match POSIX behavior, set ENOTDIR when any of the folders in the
* file path is a regular file, otherwise set ENOENT. * file path is a regular file, otherwise set ENOENT.
*/ */
if (posix_enotdir) { if (errno == ENOENT && posix_enotdir) {
size_t path_len = wcslen(path); size_t path_len = wcslen(path);
/* scan up path until we find an existing item */ /* scan up path until we find an existing item */
......
...@@ -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);
......
...@@ -13,43 +13,80 @@ static void cleanup_basic_dirs(void *ref) ...@@ -13,43 +13,80 @@ static void cleanup_basic_dirs(void *ref)
git_futils_rmdir_r("d4", NULL, GIT_RMDIR_EMPTY_HIERARCHY); git_futils_rmdir_r("d4", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
} }
void test_core_mkdir__absolute(void)
{
git_buf path = GIT_BUF_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
git_buf_joinpath(&path, clar_sandbox_path(), "d0");
/* make a directory */
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
git_buf_joinpath(&path, path.ptr, "subdir");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works for a single subdir */
git_buf_joinpath(&path, path.ptr, "another");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works */
git_buf_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure we don't imply recursive */
git_buf_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_fail(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(!git_path_isdir(path.ptr));
}
void test_core_mkdir__basic(void) void test_core_mkdir__basic(void)
{ {
cl_set_cleanup(cleanup_basic_dirs, NULL); cl_set_cleanup(cleanup_basic_dirs, NULL);
/* 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 +102,38 @@ void test_core_mkdir__with_base(void) ...@@ -65,38 +102,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 +172,9 @@ void test_core_mkdir__chmods(void) ...@@ -135,9 +172,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 +183,7 @@ void test_core_mkdir__chmods(void) ...@@ -146,7 +183,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 +192,7 @@ void test_core_mkdir__chmods(void) ...@@ -155,7 +192,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 +203,7 @@ void test_core_mkdir__chmods(void) ...@@ -166,7 +203,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 +214,7 @@ void test_core_mkdir__chmods(void) ...@@ -177,7 +214,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);
...@@ -187,6 +224,40 @@ void test_core_mkdir__chmods(void) ...@@ -187,6 +224,40 @@ void test_core_mkdir__chmods(void)
check_mode(0777, st.st_mode); check_mode(0777, st.st_mode);
} }
void test_core_mkdir__keeps_parent_symlinks(void)
{
#ifndef GIT_WIN32
git_buf path = GIT_BUF_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
/* make a directory */
cl_assert(!git_path_isdir("d0"));
cl_git_pass(git_futils_mkdir("d0", 0755, 0));
cl_assert(git_path_isdir("d0"));
cl_must_pass(symlink("d0", "d1"));
cl_assert(git_path_islink("d1"));
cl_git_pass(git_futils_mkdir("d1/foo/bar", 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
cl_assert(git_path_islink("d1"));
cl_assert(git_path_isdir("d1/foo/bar"));
cl_assert(git_path_isdir("d0/foo/bar"));
cl_must_pass(symlink("d0", "d2"));
cl_assert(git_path_islink("d2"));
git_buf_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
cl_assert(git_path_islink("d2"));
cl_assert(git_path_isdir("d2/other/dir"));
cl_assert(git_path_isdir("d0/other/dir"));
git_buf_free(&path);
#endif
}
void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void)
{ {
struct stat st; struct stat st;
...@@ -200,8 +271,8 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) ...@@ -200,8 +271,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,10 +281,9 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) ...@@ -210,10 +281,9 @@ 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);
cl_must_pass(p_chmod("r/mode", 0777)); cl_must_pass(p_chmod("r/mode", 0777));
} }
...@@ -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