Add wildcard support to excludes.
This commit is contained in:
parent
04078d12ef
commit
b6362a8680
@ -77,8 +77,7 @@ struct Iso_Image
|
|||||||
int ignore_special;
|
int ignore_special;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Files to exclude
|
* Files to exclude. Wildcard support is included.
|
||||||
* TODO add wildcard support
|
|
||||||
*/
|
*/
|
||||||
char** excludes;
|
char** excludes;
|
||||||
int nexcludes;
|
int nexcludes;
|
||||||
|
@ -1825,6 +1825,40 @@ int iso_tree_get_ignore_special(IsoImage *image);
|
|||||||
*
|
*
|
||||||
* the directory /home/user/data/private won't be added to image.
|
* the directory /home/user/data/private won't be added to image.
|
||||||
*
|
*
|
||||||
|
* However, if you explicity add a deeper dir, it won't be excluded. i.e.,
|
||||||
|
* in the following example.
|
||||||
|
*
|
||||||
|
* iso_tree_add_exclude(image, "/home/user/data");
|
||||||
|
* iso_tree_add_dir_rec(image, root, "/home/user/data/private");
|
||||||
|
*
|
||||||
|
* the directory /home/user/data/private is added. On the other, side, and
|
||||||
|
* foollowing the the example above,
|
||||||
|
*
|
||||||
|
* iso_tree_add_dir_rec(image, root, "/home/user");
|
||||||
|
*
|
||||||
|
* will exclude the directory "/home/user/data".
|
||||||
|
*
|
||||||
|
* Absolute paths are not mandatory, you can, for example, add a relative
|
||||||
|
* path such as:
|
||||||
|
*
|
||||||
|
* iso_tree_add_exclude(image, "private");
|
||||||
|
* iso_tree_add_exclude(image, "user/data");
|
||||||
|
*
|
||||||
|
* to excluve, respectively, all files or dirs named private, and also all
|
||||||
|
* files or dirs named data that belong to a folder named "user". Not that the
|
||||||
|
* above rule about deeper dirs is still valid. i.e., if you call
|
||||||
|
*
|
||||||
|
* iso_tree_add_dir_rec(image, root, "/home/user/data/music");
|
||||||
|
*
|
||||||
|
* it is included even containing "user/data" string. However, a possible
|
||||||
|
* "/home/user/data/music/user/data" is not added.
|
||||||
|
*
|
||||||
|
* Usual wildcards, such as * or ? are also supported, with the usual meaning
|
||||||
|
* as stated in "man 7 glob". For example
|
||||||
|
*
|
||||||
|
* // to exclude backup text files
|
||||||
|
* iso_tree_add_exclude(image, "*.~");
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* 1 on success, < 0 on error
|
* 1 on success, < 0 on error
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <fnmatch.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new directory to the iso tree.
|
* Add a new directory to the iso tree.
|
||||||
@ -479,10 +480,25 @@ static
|
|||||||
int check_excludes(IsoImage *image, const char *path)
|
int check_excludes(IsoImage *image, const char *path)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < image->nexcludes; ++i) {
|
for (i = 0; i < image->nexcludes; ++i) {
|
||||||
if (strcmp(image->excludes[i], path) == 0) {
|
char *exclude = image->excludes[i];
|
||||||
|
if (exclude[0] == '/') {
|
||||||
|
/* absolute exclude, must completely match path */
|
||||||
|
if (!fnmatch(exclude, path, FNM_PERIOD|FNM_FILE_NAME)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* relative exclude, it is enought if a part of the path matches */
|
||||||
|
char *pos = (char*)path;
|
||||||
|
while (pos != NULL) {
|
||||||
|
pos++;
|
||||||
|
if (!fnmatch(exclude, pos, FNM_PERIOD|FNM_FILE_NAME)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
pos = strchr(pos, '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user