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

@ -40,6 +40,7 @@ AC_CHECK_HEADERS([sys/wait.h])
AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([regex.h])
AC_CHECK_FUNCS(posix_fadvise)
AC_CHECK_FUNCS(strptime)
AC_CHECK_FUNCS(strtok_r)

View File

@ -102,6 +102,12 @@ library {
# scan time. By default .db, .ini, .db-journal and .pdf are ignored.
# filetypes_ignore = { ".db", ".ini", ".db-journal", ".pdf" }
# File paths the scanner should ignore
# If you want to exclude files on a more advanced basis you can enter
# one or more POSIX regular expressions, and any file with a matching
# path will be ignored.
# filepath_ignore = { "myregex" }
# Disable startup file scanning
# When forked-daapd starts it will do an initial file scan of your
# library (and then watch it for changes). If you are sure your library
@ -109,7 +115,7 @@ library {
# initial file scan and save some system ressources. Disabling this scan
# may lead to forked-daapd's database coming out of sync with the
# library. If that happens read the instructions in the README on how
# to trigger a full rescan.
# to trigger a rescan.
# filescan_disable = false
# Should iTunes metadata override ours?

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;