Add support for excluding arbitrary files when adding a dir recursively.
This commit is contained in:
parent
69d0503053
commit
ff0dd38e9f
@ -92,11 +92,19 @@ void iso_image_ref(IsoImage *image)
|
|||||||
void iso_image_unref(IsoImage *image)
|
void iso_image_unref(IsoImage *image)
|
||||||
{
|
{
|
||||||
if (--image->refcount == 0) {
|
if (--image->refcount == 0) {
|
||||||
|
int nexcl;
|
||||||
|
|
||||||
/* we need to free the image */
|
/* we need to free the image */
|
||||||
if (image->user_data != NULL) {
|
if (image->user_data != NULL) {
|
||||||
/* free attached data */
|
/* free attached data */
|
||||||
image->user_data_free(image->user_data);
|
image->user_data_free(image->user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (nexcl = 0; nexcl < image->nexcludes; ++nexcl) {
|
||||||
|
free(image->excludes[nexcl]);
|
||||||
|
}
|
||||||
|
free(image->excludes);
|
||||||
|
|
||||||
iso_node_unref((IsoNode*)image->root);
|
iso_node_unref((IsoNode*)image->root);
|
||||||
iso_node_builder_unref(image->builder);
|
iso_node_builder_unref(image->builder);
|
||||||
iso_filesystem_unref(image->fs);
|
iso_filesystem_unref(image->fs);
|
||||||
|
@ -81,6 +81,7 @@ struct Iso_Image
|
|||||||
* TODO add wildcard support
|
* TODO add wildcard support
|
||||||
*/
|
*/
|
||||||
char** excludes;
|
char** excludes;
|
||||||
|
int nexcludes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if the dir already contains a node with the same name, whether to
|
* if the dir already contains a node with the same name, whether to
|
||||||
|
@ -1784,6 +1784,31 @@ void iso_tree_set_ignore_special(IsoImage *image, int skip);
|
|||||||
*/
|
*/
|
||||||
int iso_tree_get_ignore_special(IsoImage *image);
|
int iso_tree_get_ignore_special(IsoImage *image);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a excluded path. These are paths that won't never added to image,
|
||||||
|
* and will be excluded even when adding recursively its parent directory.
|
||||||
|
*
|
||||||
|
* For example, in
|
||||||
|
*
|
||||||
|
* iso_tree_add_exclude(image, "/home/user/data/private");
|
||||||
|
* iso_tree_add_dir_rec(image, root, "/home/user/data");
|
||||||
|
*
|
||||||
|
* the directory /home/user/data/private won't be added to image.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* 1 on success, < 0 on error
|
||||||
|
*/
|
||||||
|
int iso_tree_add_exclude(IsoImage *image, const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a previously added exclude.
|
||||||
|
*
|
||||||
|
* @see iso_tree_add_exclude
|
||||||
|
* @return
|
||||||
|
* 1 on success, 0 exclude do not exists, < 0 on error
|
||||||
|
*/
|
||||||
|
int iso_tree_remove_exclude(IsoImage *image, const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a callback function that libisofs will call for each file that is
|
* Set a callback function that libisofs will call for each file that is
|
||||||
* added to the given image by a recursive addition function. This includes
|
* added to the given image by a recursive addition function. This includes
|
||||||
|
@ -350,6 +350,68 @@ void iso_tree_set_report_callback(IsoImage *image,
|
|||||||
image->report = report;
|
image->report = report;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a excluded path. These are paths that won't never added to image,
|
||||||
|
* and will be excluded even when adding recursively its parent directory.
|
||||||
|
*
|
||||||
|
* For example, in
|
||||||
|
*
|
||||||
|
* iso_tree_add_exclude(image, "/home/user/data/private");
|
||||||
|
* iso_tree_add_dir_rec(image, root, "/home/user/data");
|
||||||
|
*
|
||||||
|
* the directory /home/user/data/private won't be added to image.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* 1 on success, < 0 on error
|
||||||
|
*/
|
||||||
|
int iso_tree_add_exclude(IsoImage *image, const char *path)
|
||||||
|
{
|
||||||
|
if (image == NULL || path == NULL) {
|
||||||
|
return ISO_NULL_POINTER;
|
||||||
|
}
|
||||||
|
image->excludes = realloc(image->excludes, ++image->nexcludes *
|
||||||
|
sizeof(void*));
|
||||||
|
if (image->excludes == NULL) {
|
||||||
|
return ISO_OUT_OF_MEM;
|
||||||
|
}
|
||||||
|
image->excludes[image->nexcludes - 1] = strdup(path);
|
||||||
|
if (image->excludes[image->nexcludes - 1] == NULL) {
|
||||||
|
return ISO_OUT_OF_MEM;
|
||||||
|
}
|
||||||
|
return ISO_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a previously added exclude.
|
||||||
|
*
|
||||||
|
* @see iso_tree_add_exclude
|
||||||
|
* @return
|
||||||
|
* 1 on success, 0 exclude do not exists, < 0 on error
|
||||||
|
*/
|
||||||
|
int iso_tree_remove_exclude(IsoImage *image, const char *path)
|
||||||
|
{
|
||||||
|
size_t i, j;
|
||||||
|
|
||||||
|
if (image == NULL || path == NULL) {
|
||||||
|
return ISO_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < image->nexcludes; ++i) {
|
||||||
|
if (strcmp(image->excludes[i], path) == 0) {
|
||||||
|
/* exclude found */
|
||||||
|
free(image->excludes[i]);
|
||||||
|
--image->nexcludes;
|
||||||
|
for (j = i; j < image->nexcludes; ++j) {
|
||||||
|
image->excludes[j] = image->excludes[j+1];
|
||||||
|
}
|
||||||
|
image->excludes = realloc(image->excludes, image->nexcludes *
|
||||||
|
sizeof(void*));
|
||||||
|
return ISO_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent,
|
int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent,
|
||||||
IsoFileSource *src, IsoNodeBuilder *builder,
|
IsoFileSource *src, IsoNodeBuilder *builder,
|
||||||
@ -416,16 +478,11 @@ int iso_tree_add_node(IsoImage *image, IsoDir *parent, const char *path,
|
|||||||
static
|
static
|
||||||
int check_excludes(IsoImage *image, const char *path)
|
int check_excludes(IsoImage *image, const char *path)
|
||||||
{
|
{
|
||||||
char **exclude;
|
int i;
|
||||||
if (image->excludes == NULL) {
|
for (i = 0; i < image->nexcludes; ++i) {
|
||||||
return 0;
|
if (strcmp(image->excludes[i], path) == 0) {
|
||||||
}
|
|
||||||
exclude = image->excludes;
|
|
||||||
while (*exclude) {
|
|
||||||
if (strcmp(*exclude, path) == 0) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
++exclude;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user