diff --git a/demo/iso.c b/demo/iso.c index 1c72798..b16891c 100644 --- a/demo/iso.c +++ b/demo/iso.c @@ -66,7 +66,10 @@ int main(int argc, char **argv) return 1; } iso_image_set_msgs_severities(image, "NEVER", "ALL", ""); - + iso_tree_set_follow_symlinks(image, 0); + iso_tree_set_ignore_hidden(image, 0); + iso_tree_set_stop_on_error(image, 0); + result = iso_tree_add_dir_rec(image, iso_image_get_root(image), argv[1]); if (result < 0) { printf ("Error adding directory %d\n", result); diff --git a/src/image.h b/src/image.h index c8ee002..90bbd33 100644 --- a/src/image.h +++ b/src/image.h @@ -33,18 +33,18 @@ struct Iso_Image_Rec_Opts /** * Whether to follow symlinks or just add them as symlinks */ - unsigned int follow_symlinks; + unsigned int follow_symlinks : 1; /** * Whether to skip hidden files */ - unsigned int ignore_hidden; + unsigned int ignore_hidden : 1; /** * Whether to stop on an error. Some errors, such as memory errors, * always cause a stop */ - unsigned int stop_on_error; + unsigned int stop_on_error : 1; /** * Files to exclude diff --git a/src/libisofs.h b/src/libisofs.h index f4bd69e..92ea549 100644 --- a/src/libisofs.h +++ b/src/libisofs.h @@ -731,6 +731,45 @@ int iso_tree_add_new_symlink(IsoDir *parent, const char *name, int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode, dev_t dev, IsoSpecial **special); +/** + * Set whether to follow or not symbolic links when added a file from a source + * to IsoImage. Default behavior is to not follow symlinks. + */ +void iso_tree_set_follow_symlinks(IsoImage *image, int follow); + +/** + * Get current setting for follow_symlinks. + * + * @see iso_tree_set_follow_symlinks + */ +int iso_tree_get_follow_symlinks(IsoImage *image); + +/** + * Set whether to skip or not hidden files when adding a directory recursibely. + * Default behavior is to not ignore them, i.e., to add hidden files to image. + */ +void iso_tree_set_ignore_hidden(IsoImage *image, int skip); + +/** + * Get current setting for ignore_hidden. + * + * @see iso_tree_set_ignore_hidden + */ +int iso_tree_get_ignore_hidden(IsoImage *image); + +/** + * Set whether to stop or not when an error happens when adding recursively a + * directory to the iso tree. Default value is to skip file and continue. + */ +void iso_tree_set_stop_on_error(IsoImage *image, int stop); + +/** + * Get current setting for stop_on_error. + * + * @see iso_tree_set_stop_on_error + */ +int iso_tree_get_stop_on_error(IsoImage *image); + /** * Add a new node to the image tree, from an existing file. * diff --git a/src/tree.c b/src/tree.c index 1593d5d..5e5a8ba 100644 --- a/src/tree.c +++ b/src/tree.c @@ -296,6 +296,63 @@ int iso_tree_add_new_special(IsoDir *parent, const char *name, mode_t mode, return ++parent->nchildren; } +/** + * Set whether to follow or not symbolic links when added a file from a source + * to IsoImage. + */ +void iso_tree_set_follow_symlinks(IsoImage *image, int follow) +{ + image->recOpts.follow_symlinks = follow ? 1 : 0; +} + +/** + * Get current setting for follow_symlinks. + * + * @see iso_tree_set_follow_symlinks + */ +int iso_tree_get_follow_symlinks(IsoImage *image) +{ + return image->recOpts.follow_symlinks; +} + +/** + * Set whether to skip or not hidden files when adding a directory recursibely. + * Default behavior is to not ignore them, i.e., to add hidden files to image. + */ +void iso_tree_set_ignore_hidden(IsoImage *image, int skip) +{ + image->recOpts.ignore_hidden = skip ? 1 : 0; +} + +/** + * Get current setting for ignore_hidden. + * + * @see iso_tree_set_ignore_hidden + */ +int iso_tree_get_ignore_hidden(IsoImage *image) +{ + return image->recOpts.ignore_hidden; +} + +/** + * Set whether to stop or not when an error happens when adding recursively a + * directory to the iso tree. Default value is to skip file and continue. + */ +void iso_tree_set_stop_on_error(IsoImage *image, int stop) +{ + image->recOpts.stop_on_error = stop ? 1 : 0; +} + +/** + * Get current setting for stop_on_error. + * + * @see iso_tree_set_stop_on_error + */ +int iso_tree_get_stop_on_error(IsoImage *image) +{ + return image->recOpts.stop_on_error; +} + static int iso_tree_add_node_builder(IsoImage *image, IsoDir *parent, IsoFileSource *src, IsoNodeBuilder *builder, @@ -415,15 +472,19 @@ int iso_add_dir_aux(IsoImage *image, IsoDir *parent, IsoFileSource *dir) char *name; IsoNode *new; - iso_msg_debug(image, "Adding file %s", iso_file_source_get_path(file)); - name = iso_file_source_get_name(file); if (check_excludes(image, iso_file_source_get_path(file))) { + iso_msg_debug(image, "Skipping excluded file %s", + iso_file_source_get_path(file)); action = 2; } else if (check_hidden(image, name)) { + iso_msg_debug(image, "Skipping hidden file %s", + iso_file_source_get_path(file)); action = 2; } else { + iso_msg_debug(image, "Adding file %s", + iso_file_source_get_path(file)); action = 1; }