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
1b938a58
Commit
1b938a58
authored
Jul 03, 2011
by
nulltoken
Committed by
schu
Jul 06, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicated recursive directory removal related code
parent
1ee5fd90
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
49 deletions
+22
-49
src/fileops.c
+8
-5
src/fileops.h
+2
-3
tests/t00-core.c
+3
-3
tests/t06-index.c
+1
-1
tests/t12-repo.c
+7
-8
tests/test_helpers.c
+1
-29
No files found.
src/fileops.c
View file @
1b938a58
...
...
@@ -301,7 +301,7 @@ int git_futils_mkdir_r(const char *path, int mode)
return
GIT_SUCCESS
;
}
static
int
_rmdir_recurs_
cb
(
void
*
GIT_UNUSED
(
nil
)
,
char
*
path
)
static
int
_rmdir_recurs_
foreach
(
void
*
force_removal_of_non_empty_directory
,
char
*
path
)
{
int
error
=
GIT_SUCCESS
;
...
...
@@ -311,21 +311,24 @@ static int _rmdir_recurs_cb(void *GIT_UNUSED(nil), char *path)
if
(
error
==
GIT_SUCCESS
)
{
size_t
root_size
=
strlen
(
path
);
if
((
error
=
git_futils_direach
(
path
,
GIT_PATH_MAX
,
_rmdir_recurs_
cb
,
NULL
))
<
GIT_SUCCESS
)
if
((
error
=
git_futils_direach
(
path
,
GIT_PATH_MAX
,
_rmdir_recurs_
foreach
,
force_removal_of_non_empty_directory
))
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to remove directory `%s`"
,
path
);
path
[
root_size
]
=
'\0'
;
return
p_rmdir
(
path
);
}
return
git__rethrow
(
error
,
"Failed to remove directory. `%s` is not a directory"
,
path
);
if
(
*
(
int
*
)(
force_removal_of_non_empty_directory
))
return
p_unlink
(
path
);
else
return
git__rethrow
(
error
,
"Failed to remove directory. `%s` is not a directory"
,
path
);
}
int
git_futils_rmdir_recurs
(
const
char
*
path
)
int
git_futils_rmdir_recurs
(
const
char
*
path
,
int
force_removal_of_non_empty_directory
)
{
char
p
[
GIT_PATH_MAX
];
strncpy
(
p
,
path
,
GIT_PATH_MAX
);
return
_rmdir_recurs_
cb
(
NULL
,
p
);
return
_rmdir_recurs_
foreach
(
&
force_removal_of_non_empty_directory
,
p
);
}
int
git_futils_cmp_path
(
const
char
*
name1
,
int
len1
,
int
isdir1
,
...
...
src/fileops.h
View file @
1b938a58
...
...
@@ -80,6 +80,8 @@ extern int git_futils_mkdir_r(const char *path, int mode);
*/
extern
int
git_futils_mkpath2file
(
const
char
*
path
);
extern
int
git_futils_rmdir_recurs
(
const
char
*
path
,
int
force_removal_of_non_empty_directory
);
/**
* Create and open a temporary file with a `_git2_` suffix
*/
...
...
@@ -102,9 +104,6 @@ extern int git_futils_mv_withpath(const char *from, const char *to);
*/
extern
git_off_t
git_futils_filesize
(
git_file
fd
);
/* Recursively remove an empty directory structure */
extern
int
git_futils_rmdir_recurs
(
const
char
*
path
);
/* Taken from git.git */
GIT_INLINE
(
int
)
is_dot_or_dotdot
(
const
char
*
name
)
{
...
...
tests/t00-core.c
View file @
1b938a58
...
...
@@ -508,7 +508,7 @@ static int setup_empty_tmp_dir()
BEGIN_TEST
(
rmdir0
,
"make sure empty dir can be deleted recusively"
)
must_pass
(
setup_empty_tmp_dir
());
must_pass
(
git_futils_rmdir_recurs
(
empty_tmp_dir
));
must_pass
(
git_futils_rmdir_recurs
(
empty_tmp_dir
,
0
));
END_TEST
BEGIN_TEST
(
rmdir1
,
"make sure non-empty dir cannot be deleted recusively"
)
...
...
@@ -520,9 +520,9 @@ BEGIN_TEST(rmdir1, "make sure non-empty dir cannot be deleted recusively")
fd
=
p_creat
(
file
,
0755
);
must_pass
(
fd
);
must_pass
(
p_close
(
fd
));
must_fail
(
git_futils_rmdir_recurs
(
empty_tmp_dir
));
must_fail
(
git_futils_rmdir_recurs
(
empty_tmp_dir
,
0
));
must_pass
(
p_unlink
(
file
));
must_pass
(
git_futils_rmdir_recurs
(
empty_tmp_dir
));
must_pass
(
git_futils_rmdir_recurs
(
empty_tmp_dir
,
0
));
END_TEST
BEGIN_SUITE
(
core
)
...
...
tests/t06-index.c
View file @
1b938a58
...
...
@@ -210,7 +210,7 @@ BEGIN_TEST(add0, "add a new file to the index")
git_index_free
(
index
);
git_repository_free
(
repo
);
rmdir_recurs
(
TEMP_REPO_FOLDER
);
must_pass
(
git_futils_rmdir_recurs
(
TEMP_REPO_FOLDER
,
1
)
);
END_TEST
BEGIN_SUITE
(
index
)
...
...
tests/t12-repo.c
View file @
1b938a58
...
...
@@ -141,13 +141,13 @@ static int ensure_repository_init(
goto
cleanup
;
git_repository_free
(
repo
);
rmdir_recurs
(
working_directory
);
git_futils_rmdir_recurs
(
working_directory
,
1
);
return
GIT_SUCCESS
;
cleanup
:
git_repository_free
(
repo
);
rmdir_recurs
(
working_directory
);
git_futils_rmdir_recurs
(
working_directory
,
1
);
return
GIT_ERROR
;
}
...
...
@@ -193,7 +193,7 @@ BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping
git_repository_free
(
repo
);
must_pass
(
chdir
(
current_workdir
));
rmdir_recurs
(
TEMP_REPO_FOLDER
);
must_pass
(
git_futils_rmdir_recurs
(
TEMP_REPO_FOLDER
,
1
)
);
END_TEST
#define EMPTY_BARE_REPOSITORY_NAME "empty_bare.git"
...
...
@@ -210,7 +210,7 @@ BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git"
must_be_true
(
git_repository_path
(
repo
,
GIT_REPO_PATH_WORKDIR
)
==
NULL
);
git_repository_free
(
repo
);
must_pass
(
rmdir_recurs
(
TEMP_REPO_FOLDER
));
must_pass
(
git_futils_rmdir_recurs
(
TEMP_REPO_FOLDER
,
1
));
END_TEST
#define SOURCE_EMPTY_REPOSITORY_NAME "empty_standard_repo/.gitted"
...
...
@@ -229,7 +229,7 @@ BEGIN_TEST(open1, "Open a standard repository that has just been initialized by
must_be_true
(
git_repository_path
(
repo
,
GIT_REPO_PATH_WORKDIR
)
!=
NULL
);
git_repository_free
(
repo
);
must_pass
(
rmdir_recurs
(
TEMP_REPO_FOLDER
));
must_pass
(
git_futils_rmdir_recurs
(
TEMP_REPO_FOLDER
,
1
));
END_TEST
...
...
@@ -257,7 +257,7 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t
git_repository_free
(
repo
);
must_pass
(
chdir
(
current_workdir
));
rmdir_recurs
(
TEMP_REPO_FOLDER
);
must_pass
(
git_futils_rmdir_recurs
(
TEMP_REPO_FOLDER
,
1
)
);
END_TEST
BEGIN_TEST
(
empty0
,
"test if a repository is empty or not"
)
...
...
@@ -392,7 +392,6 @@ BEGIN_TEST(discover0, "test discover")
char
found_path
[
GIT_PATH_MAX
];
int
mode
=
0755
;
rmdir_recurs
(
DISCOVER_FOLDER
);
must_pass
(
append_ceiling_dir
(
ceiling_dirs
,
TEST_RESOURCES
));
git_futils_mkdir_r
(
DISCOVER_FOLDER
,
mode
);
...
...
@@ -447,7 +446,7 @@ BEGIN_TEST(discover0, "test discover")
must_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
));
must_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
repository_path
));
rmdir_recurs
(
DISCOVER_FOLDER
);
must_pass
(
git_futils_rmdir_recurs
(
DISCOVER_FOLDER
,
1
)
);
git_repository_free
(
repo
);
END_TEST
...
...
tests/test_helpers.c
View file @
1b938a58
...
...
@@ -176,34 +176,6 @@ int cmp_files(const char *a, const char *b)
return
error
;
}
static
int
remove_filesystem_element_recurs
(
void
*
GIT_UNUSED
(
nil
),
char
*
path
)
{
int
error
=
GIT_SUCCESS
;
GIT_UNUSED_ARG
(
nil
);
error
=
git_futils_isdir
(
path
);
if
(
error
==
GIT_SUCCESS
)
{
size_t
root_size
=
strlen
(
path
);
error
=
git_futils_direach
(
path
,
GIT_PATH_MAX
,
remove_filesystem_element_recurs
,
NULL
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
path
[
root_size
]
=
0
;
return
rmdir
(
path
);
}
return
p_unlink
(
path
);
}
int
rmdir_recurs
(
const
char
*
directory_path
)
{
char
buffer
[
GIT_PATH_MAX
];
strcpy
(
buffer
,
directory_path
);
return
remove_filesystem_element_recurs
(
NULL
,
buffer
);
}
typedef
struct
{
size_t
src_len
,
dst_len
;
char
*
dst
;
...
...
@@ -255,7 +227,7 @@ int open_temp_repo(git_repository **repo, const char *path)
void
close_temp_repo
(
git_repository
*
repo
)
{
git_repository_free
(
repo
);
rmdir_recurs
(
TEMP_REPO_FOLDER
);
git_futils_rmdir_recurs
(
TEMP_REPO_FOLDER
,
1
);
}
static
int
remove_placeholders_recurs
(
void
*
filename
,
char
*
path
)
...
...
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