Skip to content

Commit

Permalink
SyncDav update
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Jan 20, 2016
1 parent 9cc5706 commit 15cc0c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ examples/fileDav/dub.selections.json
examples/fileDav/dub.selections.json

examples/fileDav/dub.selections.json
examples
29 changes: 18 additions & 11 deletions source/vibedav/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class DavException : Exception {
}
}


enum NoticeAction {
created,
deleted,
changed
}

string stripSlashes(string path) {
return path.stripBeginSlashes.stripEndSlasshes;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {

}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -460,7 +467,7 @@ class Dav : IDav {
auto res = plugin.createCollection(url, username);
bindResourcePlugins(res);

notice("created", res);
notice(NoticeAction.created, res);

return res;
}
Expand All @@ -474,7 +481,7 @@ class Dav : IDav {
auto res = plugin.createResource(url, username);
bindResourcePlugins(res);

notice("created", res);
notice(NoticeAction.created, res);

return res;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 5 additions & 7 deletions source/vibedav/plugins/syncdav.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SyncDavPlugin : BaseDavPlugin, ISyncDavReports {

struct Change {
Path path;
string type;
NoticeAction type;
SysTime time;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 15cc0c6

Please sign in to comment.