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
926acbcf
Commit
926acbcf
authored
Mar 01, 2013
by
Jameson Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clone should not delete directories it did not create
parent
cc427158
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
1 deletions
+90
-1
src/clone.c
+9
-0
src/fileops.c
+35
-0
src/fileops.h
+9
-1
tests-clar/clone/nonetwork.c
+37
-0
No files found.
src/clone.c
View file @
926acbcf
...
...
@@ -429,6 +429,7 @@ int git_clone(
int
retcode
=
GIT_ERROR
;
git_repository
*
repo
=
NULL
;
git_clone_options
normOptions
;
int
remove_directory_on_failure
=
0
;
assert
(
out
&&
url
&&
local_path
);
...
...
@@ -439,11 +440,19 @@ int git_clone(
return
GIT_ERROR
;
}
/* Only remove the directory on failure if we create it */
remove_directory_on_failure
=
!
git_path_exists
(
local_path
);
if
(
!
(
retcode
=
git_repository_init
(
&
repo
,
local_path
,
normOptions
.
bare
)))
{
if
((
retcode
=
setup_remotes_and_fetch
(
repo
,
url
,
&
normOptions
))
<
0
)
{
/* Failed to fetch; clean up */
git_repository_free
(
repo
);
if
(
remove_directory_on_failure
)
git_futils_rmdir_r
(
local_path
,
NULL
,
GIT_RMDIR_REMOVE_FILES
);
else
git_futils_cleanupdir_r
(
local_path
);
}
else
{
*
out
=
repo
;
retcode
=
0
;
...
...
src/fileops.c
View file @
926acbcf
...
...
@@ -519,6 +519,41 @@ int git_futils_rmdir_r(
return
error
;
}
int
git_futils_cleanupdir_r
(
const
char
*
path
)
{
int
error
;
git_buf
fullpath
=
GIT_BUF_INIT
;
futils__rmdir_data
data
;
if
((
error
=
git_buf_put
(
&
fullpath
,
path
,
strlen
(
path
))
<
0
))
goto
clean_up
;
data
.
base
=
""
;
data
.
baselen
=
0
;
data
.
flags
=
GIT_RMDIR_REMOVE_FILES
;
data
.
error
=
0
;
if
(
!
git_path_exists
(
path
))
{
giterr_set
(
GITERR_OS
,
"Path does not exist: %s"
,
path
);
error
=
GIT_ERROR
;
goto
clean_up
;
}
if
(
!
git_path_isdir
(
path
))
{
giterr_set
(
GITERR_OS
,
"Path is not a directory: %s"
,
path
);
error
=
GIT_ERROR
;
goto
clean_up
;
}
error
=
git_path_direach
(
&
fullpath
,
futils__rmdir_recurs_foreach
,
&
data
);
if
(
error
==
GIT_EUSER
)
error
=
data
.
error
;
clean_up:
git_buf_free
(
&
fullpath
);
return
error
;
}
int
git_futils_find_system_file
(
git_buf
*
path
,
const
char
*
filename
)
{
#ifdef GIT_WIN32
...
...
src/fileops.h
View file @
926acbcf
...
...
@@ -128,7 +128,7 @@ typedef enum {
/**
* Remove path and any files and directories beneath it.
*
* @param path Path to t
o
top level directory to process.
* @param path Path to t
he
top level directory to process.
* @param base Root for relative path.
* @param flags Combination of git_futils_rmdir_flags values
* @return 0 on success; -1 on error.
...
...
@@ -136,6 +136,14 @@ typedef enum {
extern
int
git_futils_rmdir_r
(
const
char
*
path
,
const
char
*
base
,
uint32_t
flags
);
/**
* Remove all files and directories beneath the specified path.
*
* @param path Path to the top level directory to process.
* @return 0 on success; -1 on error.
*/
extern
int
git_futils_cleanupdir_r
(
const
char
*
path
);
/**
* Create and open a temporary file with a `_git2_` suffix.
* Writes the filename into path_out.
* @return On success, an open file descriptor, else an error code < 0.
...
...
tests-clar/clone/nonetwork.c
View file @
926acbcf
...
...
@@ -52,6 +52,43 @@ void test_clone_nonetwork__bad_url(void)
cl_assert
(
!
git_path_exists
(
"./foo"
));
}
static
int
dont_call_me
(
void
*
state
,
git_buf
*
path
)
{
GIT_UNUSED
(
state
);
GIT_UNUSED
(
path
);
return
GIT_ERROR
;
}
void
test_clone_nonetwork__do_not_clean_existing_directory
(
void
)
{
git_buf
path_buf
=
GIT_BUF_INIT
;
git_buf_put
(
&
path_buf
,
"./foo"
,
5
);
/* Clone should not remove the directory if it already exists, but
* Should clean up entries it creates. */
p_mkdir
(
"./foo"
,
GIT_DIR_MODE
);
cl_git_fail
(
git_clone
(
&
g_repo
,
"not_a_repo"
,
"./foo"
,
&
g_options
));
cl_assert
(
git_path_exists
(
"./foo"
));
/* Make sure the directory is empty. */
cl_git_pass
(
git_path_direach
(
&
path_buf
,
dont_call_me
,
NULL
));
/* Try again with a bare repository. */
g_options
.
bare
=
true
;
cl_git_fail
(
git_clone
(
&
g_repo
,
"not_a_repo"
,
"./foo"
,
&
g_options
));
cl_assert
(
git_path_exists
(
"./foo"
));
/* Make sure the directory is empty. */
cl_git_pass
(
git_path_direach
(
&
path_buf
,
dont_call_me
,
NULL
));
git_buf_free
(
&
path_buf
);
}
void
test_clone_nonetwork__local
(
void
)
{
cl_git_pass
(
git_clone
(
&
g_repo
,
cl_git_fixture_url
(
"testrepo.git"
),
"./foo"
,
&
g_options
));
...
...
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