diff options
author | Yunchih Chen <yunchih.cat@gmail.com> | 2018-03-18 11:07:03 +0800 |
---|---|---|
committer | Yunchih Chen <yunchih.cat@gmail.com> | 2018-03-18 11:07:03 +0800 |
commit | bee96e970918ed4eec62609ba3823797329454fd (patch) | |
tree | 87432cf41f7aece1bf0464ebdc8c33f916f00086 /lib | |
parent | ffd1cc10279ffc4bfe0ff6e37484e5a13e64f619 (diff) | |
download | nfcollect-bee96e970918ed4eec62609ba3823797329454fd.tar nfcollect-bee96e970918ed4eec62609ba3823797329454fd.tar.gz nfcollect-bee96e970918ed4eec62609ba3823797329454fd.tar.bz2 nfcollect-bee96e970918ed4eec62609ba3823797329454fd.tar.lz nfcollect-bee96e970918ed4eec62609ba3823797329454fd.tar.xz nfcollect-bee96e970918ed4eec62609ba3823797329454fd.tar.zst nfcollect-bee96e970918ed4eec62609ba3823797329454fd.zip |
Fix file matching regex
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/common.c b/lib/common.c index d4e9363..2b99dc6 100644 --- a/lib/common.c +++ b/lib/common.c @@ -34,17 +34,20 @@ int nfl_storage_match_index(const char *fn) { regmatch_t match[1]; int ret; + if(unlikely(!strcmp(fn, ".") || !strcmp(fn, ".."))) + return -1; + if (!compiled) { - ERR(regcomp(®ex, "^" STORAGE_PREFIX "_[0-9]+", 0), + ERR(regcomp(®ex, "^" STORAGE_PREFIX "_([0-9]+)", REG_EXTENDED), "Could not compile regex"); compiled = true; } - ret = regexec(®ex, fn, 1, match, 0); + ret = regexec(®ex, fn, 2, match, 0); if (!ret) { - assert(match[0].rm_so != (size_t)-1); - return strtol(fn + match[0].rm_so, NULL, 10); - } else if (ret != REG_NOMATCH) { + assert(match[1].rm_so != (size_t)-1); + return strtol(fn + match[1].rm_so, NULL, 10); + } else { char buf[100]; regerror(ret, ®ex, buf, sizeof(buf)); WARN(1, "Regex match failed: %s", buf) |