Browse Source

Add support for excluding arbitrary files when adding a dir recursively.

release-1.5.4.branch
Vreixo Formoso 14 years ago
parent
commit
ff0dd38e9f
  1. 8
      libisofs/image.c
  2. 1
      libisofs/image.h
  3. 25
      libisofs/libisofs.h
  4. 73
      libisofs/tree.c

8
libisofs/image.c

@ -92,11 +92,19 @@ void iso_image_ref(IsoImage *image)
void iso_image_unref(IsoImage *image)
{
if (--image->refcount == 0) {
int nexcl;
/* we need to free the image */
if (image->user_data != NULL) {
/* free attached 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_builder_unref(image->builder);
iso_filesystem_unref(image->fs);

1
libisofs/image.h

@ -81,6 +81,7 @@ struct Iso_Image
* TODO add wildcard support
*/
char** excludes;
int nexcludes;
/**
* if the dir already contains a node with the same name, whether to

25
libisofs/libisofs.h

@ -1784,6 +1784,31 @@ void iso_tree_set_ignore_special(IsoImage *image, int skip);
*/
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
* added to the given image by a recursive addition function. This includes

73
libisofs/tree.c

@ -350,6 +350,68 @@ void iso_tree_set_report_callback(IsoImage *image,
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
int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent,
IsoFileSource *src, IsoNodeBuilder *builder,
@ -416,16 +478,11 @@ int iso_tree_add_node(IsoImage *image, IsoDir *parent, const char *path,
static
int check_excludes(IsoImage *image, const char *path)
{
char **exclude;
if (image->excludes == NULL) {
return 0;
}
exclude = image->excludes;
while (*exclude) {
if (strcmp(*exclude, path) == 0) {
int i;
for (i = 0; i < image->nexcludes; ++i) {
if (strcmp(image->excludes[i], path) == 0) {
return 1;
}
++exclude;
}
return 0;
}

Loading…
Cancel
Save