diff --git a/demo/iso.c b/demo/iso.c index f6f13b1..967a44d 100644 --- a/demo/iso.c +++ b/demo/iso.c @@ -39,6 +39,14 @@ void help() ); } +int callback(IsoFileSource *src) +{ + char *path = iso_file_source_get_path(src); + printf("CALLBACK: %s\n", path); + free(path); + return 1; +} + int main(int argc, char **argv) { int result; @@ -145,6 +153,7 @@ int main(int argc, char **argv) iso_tree_set_ignore_hidden(image, 0); iso_tree_set_ignore_special(image, 0); iso_set_abort_severity("SORRY"); + iso_tree_set_report_callback(image, callback); result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[optind]); if (result < 0) { diff --git a/src/libisofs.h b/src/libisofs.h index efe8c97..8b36dc6 100644 --- a/src/libisofs.h +++ b/src/libisofs.h @@ -1540,6 +1540,22 @@ void iso_tree_set_ignore_special(IsoImage *image, int skip); */ int iso_tree_get_ignore_special(IsoImage *image); +/** + * 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 + * image import. + * + * @param report + * pointer to a function that will be called just before a file will be + * added to the image. You can control whether the file will be in fact + * added or ignored. + * This function should return 1 to add the file, 0 to ignore it and + * continue, < 0 to abort the process + * NULL is allowed if you don't want any callback. + */ +void iso_tree_set_report_callback(IsoImage *image, + int (*report)(IsoFileSource *src)); + /** * Add a new node to the image tree, from an existing file. * diff --git a/src/tree.c b/src/tree.c index ddc08f9..9f4dec2 100644 --- a/src/tree.c +++ b/src/tree.c @@ -362,6 +362,25 @@ int iso_tree_get_ignore_special(IsoImage *image) return image->recOpts.ignore_special; } +/** + * 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 + * image import. + * + * @param report + * pointer to a function that will be called just before a file will be + * added to the image. You can control whether the file will be in fact + * added or ignored. + * This function should return 1 to add the file, 0 to ignore it and + * continue, < 0 to abort the process + * NULL is allowed if you don't want any callback. + */ +void iso_tree_set_report_callback(IsoImage *image, + int (*report)(IsoFileSource *src)) +{ + image->recOpts.report = report; +} + static int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent, IsoFileSource *src, IsoNodeBuilder *builder,