Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
5af52c62
Commit
5af52c62
authored
Aug 25, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2531 from libgit2/rb/mkdir-allow-parent-failures
Allow mkdir helper to skip parent errors
parents
2c1de697
668ae2dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
+36
-3
src/fileops.c
+5
-3
tests/core/mkdir.c
+31
-0
No files found.
src/fileops.c
View file @
5af52c62
...
...
@@ -355,8 +355,9 @@ int git_futils_mkdir(
if
(
p_mkdir
(
make_path
.
ptr
,
mode
)
<
0
)
{
int
tmp_errno
=
giterr_system_last
();
/* ignore error if directory already exists */
if
(
p_stat
(
make_path
.
ptr
,
&
st
)
<
0
||
!
S_ISDIR
(
st
.
st_mode
))
{
/* ignore error if not at end or if directory already exists */
if
(
lastch
==
'\0'
&&
(
p_stat
(
make_path
.
ptr
,
&
st
)
<
0
||
!
S_ISDIR
(
st
.
st_mode
)))
{
giterr_system_set
(
tmp_errno
);
giterr_set
(
GITERR_OS
,
"Failed to make directory '%s'"
,
make_path
.
ptr
);
goto
done
;
...
...
@@ -374,7 +375,8 @@ int git_futils_mkdir(
if
(((
flags
&
GIT_MKDIR_CHMOD_PATH
)
!=
0
||
(
lastch
==
'\0'
&&
(
flags
&
GIT_MKDIR_CHMOD
)
!=
0
))
&&
st
.
st_mode
!=
mode
&&
(
error
=
p_chmod
(
make_path
.
ptr
,
mode
))
<
0
)
{
(
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
;
}
...
...
tests/core/mkdir.c
View file @
5af52c62
...
...
@@ -186,3 +186,34 @@ void test_core_mkdir__chmods(void)
cl_git_pass
(
git_path_lstat
(
"r/mode2/is2/important2.1"
,
&
st
));
check_mode
(
0777
,
st
.
st_mode
);
}
void
test_core_mkdir__mkdir_path_inside_unwriteable_parent
(
void
)
{
struct
stat
st
;
mode_t
*
old
;
/* FAT filesystems don't support exec bit, nor group/world bits */
if
(
!
cl_is_chmod_supported
())
return
;
cl_assert
((
old
=
git__malloc
(
sizeof
(
mode_t
)))
!=
NULL
);
*
old
=
p_umask
(
022
);
cl_set_cleanup
(
cleanup_chmod_root
,
old
);
cl_git_pass
(
git_futils_mkdir
(
"r"
,
NULL
,
0777
,
0
));
cl_git_pass
(
git_futils_mkdir
(
"mode/is/important"
,
"r"
,
0777
,
GIT_MKDIR_PATH
));
cl_git_pass
(
git_path_lstat
(
"r/mode"
,
&
st
));
check_mode
(
0755
,
st
.
st_mode
);
cl_must_pass
(
p_chmod
(
"r/mode"
,
0111
));
cl_git_pass
(
git_path_lstat
(
"r/mode"
,
&
st
));
check_mode
(
0111
,
st
.
st_mode
);
cl_git_pass
(
git_futils_mkdir
(
"mode/is/okay/inside"
,
"r"
,
0777
,
GIT_MKDIR_PATH
));
cl_git_pass
(
git_path_lstat
(
"r/mode/is/okay/inside"
,
&
st
));
check_mode
(
0755
,
st
.
st_mode
);
cl_must_pass
(
p_chmod
(
"r/mode"
,
0777
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment