From 15cc0c61096bc78c34c1d27be3816fe9e435a082 Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Wed, 20 Jan 2016 22:53:35 +0200 Subject: [PATCH] SyncDav update --- .gitignore | 1 + source/vibedav/base.d | 29 ++++++++++++++++++----------- source/vibedav/plugins/syncdav.d | 12 +++++------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index d613452..44f2ec2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ examples/fileDav/dub.selections.json examples/fileDav/dub.selections.json examples/fileDav/dub.selections.json +examples diff --git a/source/vibedav/base.d b/source/vibedav/base.d index 57724e4..2dfd543 100644 --- a/source/vibedav/base.d +++ b/source/vibedav/base.d @@ -59,6 +59,13 @@ class DavException : Exception { } } + +enum NoticeAction { + created, + deleted, + changed +} + string stripSlashes(string path) { return path.stripBeginSlashes.stripEndSlasshes; } @@ -180,7 +187,7 @@ interface IDavPlugin : IDavResourceAccess { bool hasReport(URL url, string username, string name); void report(DavRequest request, DavResponse response); - void notice(string action, DavResource resource); + void notice(NoticeAction action, DavResource resource); @property { IDav dav(); @@ -255,7 +262,7 @@ abstract class BaseDavPlugin : IDavPlugin { throw new DavException(HTTPStatus.internalServerError, "Can't get report."); } - void notice(string action, DavResource resource) { + void notice(NoticeAction action, DavResource resource) { } @@ -283,7 +290,7 @@ interface IDav : IDavResourceAccess, IDavPluginHub { void copy(DavRequest request, DavResponse response); void report(DavRequest request, DavResponse response); - void notice(string action, DavResource resource); + void notice(NoticeAction action, DavResource resource); DavResource[] getResources(URL url, ulong depth, string username); @@ -396,7 +403,7 @@ class Dav : IDav { void removeResource(URL url, string username) { foreach_reverse(plugin; plugins) if(plugin.exists(url, username)) { - notice("deleted", getResource(url, username)); + notice(NoticeAction.deleted, getResource(url, username)); return plugin.removeResource(url, username); } @@ -460,7 +467,7 @@ class Dav : IDav { auto res = plugin.createCollection(url, username); bindResourcePlugins(res); - notice("created", res); + notice(NoticeAction.created, res); return res; } @@ -474,7 +481,7 @@ class Dav : IDav { auto res = plugin.createResource(url, username); bindResourcePlugins(res); - notice("created", res); + notice(NoticeAction.created, res); return res; } @@ -566,7 +573,7 @@ class Dav : IDav { DavStorage.locks.check(request.url, ifHeader); DavResource resource = getResource(request.url, request.username); - notice("changed", resource); + notice(NoticeAction.changed, resource); auto xmlString = resource.propPatch(request.content); @@ -691,7 +698,7 @@ class Dav : IDav { DavStorage.locks.check(request.url, request.ifCondition); resource.setContent(request.stream, request.contentLength); - notice("changed", resource); + notice(NoticeAction.changed, resource); DavStorage.locks.setETag(resource.url, resource.eTag); @@ -713,7 +720,7 @@ class Dav : IDav { response.statusCode = HTTPStatus.created; createCollection(request.url, request.username); - notice("created", getResource(request.url, request.username)); + notice(NoticeAction.created, getResource(request.url, request.username)); response.flush; } @@ -822,12 +829,12 @@ class Dav : IDav { } localCopy(source, destination); - notice("changed", destination); + notice(NoticeAction.changed, destination); response.flush; } - void notice(string action, DavResource resource) { + void notice(NoticeAction action, DavResource resource) { foreach_reverse(plugin; plugins) plugin.notice(action, resource); } diff --git a/source/vibedav/plugins/syncdav.d b/source/vibedav/plugins/syncdav.d index 2584535..21fedcc 100644 --- a/source/vibedav/plugins/syncdav.d +++ b/source/vibedav/plugins/syncdav.d @@ -71,7 +71,7 @@ class SyncDavPlugin : BaseDavPlugin, ISyncDavReports { struct Change { Path path; - string type; + NoticeAction type; SysTime time; } @@ -136,7 +136,7 @@ class SyncDavPlugin : BaseDavPlugin, ISyncDavReports { foreach(i; token..changeNr-1) { auto change = log[i]; - wasRemoved[change.path.toString] = (change.type == "deleted"); + wasRemoved[change.path.toString] = (change.type == NoticeAction.deleted); } return wasRemoved; @@ -196,11 +196,9 @@ class SyncDavPlugin : BaseDavPlugin, ISyncDavReports { resource.registerPlugin(new SyncDavDataPlugin(this)); } - void notice(string action, DavResource resource) { - if(action == "created" || action == "deleted" || action == "changed") { - changeNr++; - log ~= Change(resource.url.path, action, Clock.currTime); - } + void notice(NoticeAction action, DavResource resource) { + changeNr++; + log ~= Change(resource.url.path, action, Clock.currTime); } }