case insensitive patterns

This commit is contained in:
skilion 2015-09-21 13:04:05 +02:00
parent d2ec6c688f
commit 7ea7c0f9cd
4 changed files with 17 additions and 23 deletions

View file

@ -40,8 +40,8 @@ struct Monitor
void init(Config cfg, bool verbose)
{
this.verbose = verbose;
skipDir = regex(wild2regex(cfg.get("skip_dir", "")));
skipFile = regex(wild2regex(cfg.get("skip_file", "")));
skipDir = wild2regex(cfg.get("skip_dir", ""));
skipFile = wild2regex(cfg.get("skip_file", ""));
fd = inotify_init();
if (fd == -1) throw new MonitorException("inotify_init failed");
if (!buffer) buffer = new void[4096];

View file

@ -219,7 +219,6 @@ final class OneDriveApi
private void checkAccessTokenExpired()
{
if (Clock.currTime() >= accessTokenExpiration) {
writeln("Access token expired, requesting a new token...");
newToken();
}
}

View file

@ -68,8 +68,8 @@ final class SyncEngine
this.onedrive = onedrive;
this.itemdb = itemdb;
this.verbose = verbose;
skipDir = regex(wild2regex(cfg.get("skip_dir", "")));
skipFile = regex(wild2regex(cfg.get("skip_file", "")));
skipDir = wild2regex(cfg.get("skip_dir", ""));
skipFile = wild2regex(cfg.get("skip_file", ""));
}
void setStatusToken(string statusToken)

View file

@ -1,10 +1,5 @@
import std.conv: to;
import std.digest.crc;
import std.digest.digest;
import std.file: exists, rename;
import std.path: extension;
import std.stdio;
import std.string: chomp;
import std.conv, std.digest.crc, std.digest.digest, std.file, std.path;
import std.regex, std.stdio, std.string: chomp;
private string deviceName;
@ -44,30 +39,30 @@ string computeCrc32(string path)
}
// convert wildcards (*, ?) to regex
string wild2regex(const(char)[] pattern)
Regex!char wild2regex(const(char)[] pattern)
{
string regex;
regex.reserve(pattern.length + 2);
regex ~= "(^|/)";
string str;
str.reserve(pattern.length + 2);
str ~= "(^|/)";
foreach (c; pattern) {
switch (c) {
case '*':
regex ~= "[^/]*";
str ~= "[^/]*";
break;
case '.':
regex ~= "\\.";
str ~= "\\.";
break;
case '?':
regex ~= "[^/]";
str ~= "[^/]";
break;
case '|':
regex ~= "$|(^|/)";
str ~= "$|(^|/)";
break;
default:
regex ~= c;
str ~= c;
break;
}
}
regex ~= "$";
return regex;
str ~= "$";
return regex(str, "i");
}