mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-14 03:36:52 +02:00
use wildcards instead of regex
This commit is contained in:
parent
10efa036b4
commit
59d7c0c311
|
@ -2,7 +2,7 @@ import core.sys.linux.sys.inotify;
|
|||
import core.sys.posix.poll;
|
||||
import core.sys.posix.unistd;
|
||||
import std.exception, std.file, std.path, std.regex, std.stdio, std.string;
|
||||
import config;
|
||||
import config, util;
|
||||
|
||||
// relevant inotify events
|
||||
private immutable uint32_t mask = IN_ATTRIB | IN_CLOSE_WRITE | IN_CREATE |
|
||||
|
@ -40,8 +40,8 @@ struct Monitor
|
|||
void init(Config cfg, bool verbose)
|
||||
{
|
||||
this.verbose = verbose;
|
||||
skipDir = regex(cfg.get("skip_dir", ""));
|
||||
skipFile = regex(cfg.get("skip_file", ""));
|
||||
skipDir = regex(wild2regex(cfg.get("skip_dir", "")));
|
||||
skipFile = regex(wild2regex(cfg.get("skip_file", "")));
|
||||
fd = inotify_init();
|
||||
if (fd == -1) throw new MonitorException("inotify_init failed");
|
||||
if (!buffer) buffer = new void[4096];
|
||||
|
|
14
src/sync.d
14
src/sync.d
|
@ -67,8 +67,8 @@ final class SyncEngine
|
|||
this.onedrive = onedrive;
|
||||
this.itemdb = itemdb;
|
||||
this.verbose = verbose;
|
||||
skipDir = regex(cfg.get("skip_dir", ""));
|
||||
skipFile = regex(cfg.get("skip_file", ""));
|
||||
skipDir = regex(wild2regex(cfg.get("skip_dir", "")));
|
||||
skipFile = regex(wild2regex(cfg.get("skip_file", "")));
|
||||
}
|
||||
|
||||
void setStatusToken(string statusToken)
|
||||
|
@ -322,11 +322,17 @@ final class SyncEngine
|
|||
if (verbose) writeln(item.id, " ", item.name);
|
||||
final switch (item.type) {
|
||||
case ItemType.dir:
|
||||
if (!matchFirst(item.name, skipDir).empty) break;
|
||||
if (!matchFirst(item.name, skipDir).empty) {
|
||||
if (verbose) writeln("Filtered out");
|
||||
break;
|
||||
}
|
||||
uploadDirDifferences(item);
|
||||
break;
|
||||
case ItemType.file:
|
||||
if (!matchFirst(item.name, skipFile).empty) break;
|
||||
if (!matchFirst(item.name, skipFile).empty) {
|
||||
if (verbose) writeln("Filtered out");
|
||||
break;
|
||||
}
|
||||
uploadFileDifferences(item);
|
||||
break;
|
||||
}
|
||||
|
|
29
src/util.d
29
src/util.d
|
@ -42,3 +42,32 @@ string computeCrc32(string path)
|
|||
}
|
||||
return crc.finish().toHexString().dup;
|
||||
}
|
||||
|
||||
// convert wildcards (*, ?) to regex
|
||||
string wild2regex(const(char)[] pattern)
|
||||
{
|
||||
string regex;
|
||||
regex.reserve(pattern.length + 2);
|
||||
regex ~= "^";
|
||||
foreach (c; pattern) {
|
||||
switch (c) {
|
||||
case '*':
|
||||
regex ~= ".*";
|
||||
break;
|
||||
case '.':
|
||||
regex ~= "\\.";
|
||||
break;
|
||||
case '?':
|
||||
regex ~= ".";
|
||||
break;
|
||||
case '|':
|
||||
regex ~= "$|^";
|
||||
break;
|
||||
default:
|
||||
regex ~= c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
regex ~= "$";
|
||||
return regex;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue