Add option to exclude paths from scanning based on regex

This commit is contained in:
ejurgensen
2015-01-14 21:50:25 +01:00
parent baa3ee63ca
commit 4df4c50c35
4 changed files with 55 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ static cfg_opt_t sec_library[] =
CFG_STR_LIST("artwork_basenames", "{artwork,cover,Folder}", CFGF_NONE),
CFG_BOOL("artwork_individual", cfg_false, CFGF_NONE),
CFG_STR_LIST("filetypes_ignore", "{.db,.ini,.db-journal,.pdf}", CFGF_NONE),
CFG_STR_LIST("filepath_ignore", NULL, CFGF_NONE),
CFG_BOOL("filescan_disable", cfg_false, CFGF_NONE),
CFG_BOOL("itunes_overrides", cfg_false, CFGF_NONE),
CFG_STR_LIST("no_transcode", NULL, CFGF_NONE),

View File

@@ -53,6 +53,10 @@
# include <sys/eventfd.h>
#endif
#ifdef HAVE_REGEX_H
# include <regex.h>
#endif
#include <event.h>
#include "logger.h"
@@ -172,6 +176,43 @@ pop_dir(struct stacked_dir **s)
return ret;
}
#ifdef HAVE_REGEX_H
/* Checks if the file path is configured to be ignored */
static int
file_path_ignore(const char *path)
{
cfg_t *lib;
regex_t regex;
int n;
int i;
int ret;
lib = cfg_getsec(cfg, "library");
n = cfg_size(lib, "filepath_ignore");
for (i = 0; i < n; i++)
{
ret = regcomp(&regex, cfg_getnstr(lib, "filepath_ignore", i), 0);
if (ret != 0)
{
DPRINTF(E_LOG, L_SCAN, "Could not compile regex for matching with file path\n");
return 0;
}
ret = regexec(&regex, path, 0, NULL, 0);
regfree(&regex);
if (ret == 0)
{
DPRINTF(E_DBG, L_SCAN, "Regex match: %s\n", path);
return 1;
}
}
return 0;
}
#endif
/* Checks if the file extension is in the ignore list */
static int
file_type_ignore(const char *ext)
@@ -203,6 +244,11 @@ file_type_get(const char *path) {
else
filename++;
#ifdef HAVE_REGEX_H
if (file_path_ignore(path))
return FILE_IGNORE;
#endif
ext = strrchr(path, '.');
if (!ext || (strlen(ext) == 1))
return FILE_REGULAR;