mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-16 04:35:05 +02:00
added selective sync to monitor.d
This commit is contained in:
parent
79ed0a7883
commit
88d2a94078
|
@ -1,7 +1,7 @@
|
||||||
import core.sys.linux.sys.inotify;
|
import core.sys.linux.sys.inotify;
|
||||||
import core.stdc.errno;
|
import core.stdc.errno;
|
||||||
import core.sys.posix.poll, core.sys.posix.unistd;
|
import core.sys.posix.poll, core.sys.posix.unistd;
|
||||||
import std.exception, std.file, std.path, std.regex, std.stdio, std.string;
|
import std.algorithm, std.exception, std.file, std.path, std.regex, std.stdio, std.string;
|
||||||
import config, util;
|
import config, util;
|
||||||
static import log;
|
static import log;
|
||||||
|
|
||||||
|
@ -20,8 +20,10 @@ class MonitorException: ErrnoException
|
||||||
struct Monitor
|
struct Monitor
|
||||||
{
|
{
|
||||||
bool verbose;
|
bool verbose;
|
||||||
// regex that match files/dirs to skip
|
// regex that match files to skip
|
||||||
private Regex!char skipDir, skipFile;
|
private Regex!char skipFile;
|
||||||
|
// list of paths to sync
|
||||||
|
private string[] selectiveSyncPaths;
|
||||||
// inotify file descriptor
|
// inotify file descriptor
|
||||||
private int fd;
|
private int fd;
|
||||||
// map every inotify watch descriptor to its directory
|
// map every inotify watch descriptor to its directory
|
||||||
|
@ -41,8 +43,18 @@ struct Monitor
|
||||||
void init(Config cfg, bool verbose)
|
void init(Config cfg, bool verbose)
|
||||||
{
|
{
|
||||||
this.verbose = verbose;
|
this.verbose = verbose;
|
||||||
skipDir = wild2regex(cfg.getValue("skip_dir"));
|
|
||||||
skipFile = wild2regex(cfg.getValue("skip_file"));
|
skipFile = wild2regex(cfg.getValue("skip_file"));
|
||||||
|
// read the selective sync list
|
||||||
|
if (exists(cfg.syncListFilePath)) {
|
||||||
|
import std.array;
|
||||||
|
auto file = File(cfg.syncListFilePath);
|
||||||
|
selectiveSyncPaths = file
|
||||||
|
.byLine()
|
||||||
|
.map!(a => buildNormalizedPath(a))
|
||||||
|
.filter!(a => a.length > 0)
|
||||||
|
.array;
|
||||||
|
}
|
||||||
|
|
||||||
fd = inotify_init();
|
fd = inotify_init();
|
||||||
if (fd == -1) throw new MonitorException("inotify_init failed");
|
if (fd == -1) throw new MonitorException("inotify_init failed");
|
||||||
if (!buffer) buffer = new void[4096];
|
if (!buffer) buffer = new void[4096];
|
||||||
|
@ -57,7 +69,16 @@ struct Monitor
|
||||||
|
|
||||||
private void addRecursive(string dirname)
|
private void addRecursive(string dirname)
|
||||||
{
|
{
|
||||||
if (matchFirst(dirname, skipDir).empty) {
|
// skip filtered items
|
||||||
|
if (dirname != ".") {
|
||||||
|
if (!baseName(dirname).matchFirst(skipFile).empty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPathExcluded(buildNormalizedPath(dirname), selectiveSyncPaths)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
add(dirname);
|
add(dirname);
|
||||||
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
|
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
|
||||||
if (entry.isDir) {
|
if (entry.isDir) {
|
||||||
|
@ -65,7 +86,6 @@ struct Monitor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void add(string dirname)
|
private void add(string dirname)
|
||||||
{
|
{
|
||||||
|
@ -85,7 +105,7 @@ struct Monitor
|
||||||
}
|
}
|
||||||
throw new MonitorException("inotify_add_watch failed");
|
throw new MonitorException("inotify_add_watch failed");
|
||||||
}
|
}
|
||||||
wdToDirName[wd] = dirname ~ "/";
|
wdToDirName[wd] = buildNormalizedPath(dirname) ~ "/";
|
||||||
log.vlog("Monitor directory: ", dirname);
|
log.vlog("Monitor directory: ", dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,15 +172,12 @@ struct Monitor
|
||||||
|
|
||||||
// skip filtered items
|
// skip filtered items
|
||||||
path = getPath(event);
|
path = getPath(event);
|
||||||
if (event.mask & IN_ISDIR) {
|
if (!baseName(path).matchFirst(skipFile).empty) {
|
||||||
if (!matchFirst(path, skipDir).empty) {
|
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
} else {
|
if (isPathExcluded(path, selectiveSyncPaths)) {
|
||||||
if (!matchFirst(path, skipFile).empty) {
|
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (event.mask & IN_MOVED_FROM) {
|
if (event.mask & IN_MOVED_FROM) {
|
||||||
cookieToPath[event.cookie] = path;
|
cookieToPath[event.cookie] = path;
|
||||||
|
|
Loading…
Reference in a new issue