Commit f5a0e734 by nulltoken

tests: introduce cl_git_remove_placeholders()

parent 5df7207a
......@@ -271,3 +271,52 @@ const char* cl_git_path_url(const char *path)
git_buf_free(&path_buf);
return url;
}
typedef struct {
const char *filename;
size_t filename_len;
} remove_data;
static int remove_placeholders_recurs(void *_data, git_buf *path)
{
remove_data *data = (remove_data *)_data;
size_t pathlen;
if (git_path_isdir(path->ptr) == true)
return git_path_direach(path, remove_placeholders_recurs, data);
pathlen = path->size;
if (pathlen < data->filename_len)
return 0;
/* if path ends in '/'+filename (or equals filename) */
if (!strcmp(data->filename, path->ptr + pathlen - data->filename_len) &&
(pathlen == data->filename_len ||
path->ptr[pathlen - data->filename_len - 1] == '/'))
return p_unlink(path->ptr);
return 0;
}
int cl_git_remove_placeholders(const char *directory_path, const char *filename)
{
int error;
remove_data data;
git_buf buffer = GIT_BUF_INIT;
if (git_path_isdir(directory_path) == false)
return -1;
if (git_buf_sets(&buffer, directory_path) < 0)
return -1;
data.filename = filename;
data.filename_len = strlen(filename);
error = remove_placeholders_recurs(&data, &buffer);
git_buf_free(&buffer);
return error;
}
......@@ -61,4 +61,7 @@ void cl_git_sandbox_cleanup(void);
const char* cl_git_fixture_url(const char *fixturename);
const char* cl_git_path_url(const char *path);
/* Test repository cleaner */
int cl_git_remove_placeholders(const char *directory_path, const char *filename);
#endif
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