abraunegg-onedrive/src/sync.d

595 lines
15 KiB
D
Raw Normal View History

2015-09-22 11:52:28 +02:00
import std.exception: ErrnoException;
2015-09-20 19:07:16 +02:00
import std.algorithm, std.datetime, std.file, std.json, std.path, std.regex;
import std.stdio, std.string;
import config, itemdb, onedrive, upload, util;
static import log;
// threshold after which files will be uploaded using an upload session
private long thresholdFileSize = 10 * 2^^20; // 10 MiB
2015-09-01 20:45:34 +02:00
private bool isItemFolder(const ref JSONValue item)
{
return (("folder" in item.object) !is null);
2015-09-01 20:45:34 +02:00
}
private bool isItemFile(const ref JSONValue item)
{
return (("file" in item.object) !is null);
2015-09-01 20:45:34 +02:00
}
private bool isItemDeleted(const ref JSONValue item)
{
return (("deleted" in item.object) !is null);
2015-09-01 20:45:34 +02:00
}
2015-09-08 18:25:41 +02:00
private bool testCrc32(string path, const(char)[] crc32)
{
if (crc32) {
string localCrc32 = computeCrc32(path);
if (crc32 == localCrc32) return true;
}
return false;
}
2015-09-01 20:45:34 +02:00
class SyncException: Exception
{
@nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
super(msg, file, line, next);
}
@nogc @safe pure nothrow this(string msg, Throwable next, string file = __FILE__, size_t line = __LINE__)
{
super(msg, file, line, next);
}
}
final class SyncEngine
{
2015-09-14 23:56:14 +02:00
private Config cfg;
private OneDriveApi onedrive;
private ItemDatabase itemdb;
private Regex!char skipDir, skipFile;
private UploadSession session;
2015-09-18 21:42:27 +02:00
// token representing the last status correctly synced
2015-09-14 23:56:14 +02:00
private string statusToken;
2015-12-29 19:38:15 +01:00
// list of items to skip while applying the changes
2015-09-16 10:29:20 +02:00
private string[] skippedItems;
2015-09-18 21:42:27 +02:00
// list of items to delete after the changes has been downloaded
2015-09-19 15:38:43 +02:00
private string[] pathsToDelete;
2015-09-14 23:56:14 +02:00
this(Config cfg, OneDriveApi onedrive, ItemDatabase itemdb)
2015-09-01 20:45:34 +02:00
{
2015-09-14 23:56:14 +02:00
assert(onedrive && itemdb);
2015-09-01 20:45:34 +02:00
this.cfg = cfg;
this.onedrive = onedrive;
2015-09-14 23:56:14 +02:00
this.itemdb = itemdb;
skipDir = wild2regex(cfg.getValue("skip_dir"));
skipFile = wild2regex(cfg.getValue("skip_file"));
session = UploadSession(onedrive, cfg.uploadStateFilePath);
2015-09-01 20:45:34 +02:00
}
void init()
2015-09-01 20:45:34 +02:00
{
// restore the previous status token
try {
statusToken = readText(cfg.statusTokenFilePath);
} catch (FileException e) {
// swallow exception
}
// check if there is an interrupted upload session
if (session.restore()) {
log.log("Continuing the upload session ...");
auto item = session.upload();
saveItem(item);
}
2015-09-14 23:56:14 +02:00
}
2015-09-01 20:45:34 +02:00
2015-09-14 23:56:14 +02:00
void applyDifferences()
{
log.vlog("Applying differences ...");
2015-09-22 11:52:28 +02:00
try {
JSONValue changes;
do {
2016-12-14 15:17:20 +01:00
// get changes from the server
try {
changes = onedrive.viewChangesByPath("/", statusToken);
} catch (OneDriveException e) {
if (e.httpStatusCode == 410) {
log.log("Status token expired, resyncing");
statusToken = null;
continue;
}
else {
throw e;
}
}
2015-09-22 11:52:28 +02:00
foreach (item; changes["value"].array) {
applyDifference(item);
}
statusToken = changes["@delta.token"].str;
std.file.write(cfg.statusTokenFilePath, statusToken);
2016-12-14 19:51:23 +01:00
} while ((changes.type != JSON_TYPE.OBJECT) && (("@odata.nextLink" in changes) !is null));
2015-09-22 11:52:28 +02:00
} catch (ErrnoException e) {
throw new SyncException(e.msg, e);
} catch (FileException e) {
throw new SyncException(e.msg, e);
} catch (OneDriveException e) {
throw new SyncException(e.msg, e);
}
2015-09-19 15:38:43 +02:00
// delete items in pathsToDelete
if (pathsToDelete.length > 0) deleteItems();
2015-09-16 10:29:20 +02:00
// empty the skipped items
skippedItems.length = 0;
assumeSafeAppend(skippedItems);
2015-09-01 20:45:34 +02:00
}
private void applyDifference(JSONValue item)
{
string id = item["id"].str;
string name = item["name"].str;
string eTag = item["eTag"].str;
2015-09-22 16:14:16 +02:00
string parentId = item["parentReference"]["id"].str;
2015-09-19 15:38:43 +02:00
// HACK: recognize the root directory
if (name == "root" && parentId[$ - 1] == '0' && parentId[$ - 2] == '!') {
parentId = null;
}
// skip unwanted items early
if (skippedItems.find(parentId).length != 0) {
skippedItems ~= id;
return;
}
2015-09-01 20:45:34 +02:00
log.vlog(id, " ", name);
2015-09-14 23:56:14 +02:00
// rename the local item if it is unsynced and there is a new version of it
2015-09-19 15:38:43 +02:00
Item oldItem;
string oldPath;
bool cached = itemdb.selectById(id, oldItem);
if (cached && eTag != oldItem.eTag) {
2015-09-19 15:38:43 +02:00
oldPath = itemdb.computePath(id);
if (!isItemSynced(oldItem, oldPath)) {
log.vlog("The local item is unsynced, renaming");
2015-09-19 15:38:43 +02:00
if (exists(oldPath)) safeRename(oldPath);
cached = false;
}
}
2015-09-14 23:56:14 +02:00
2015-09-19 15:38:43 +02:00
// compute the path of the item
string path = ".";
2015-09-19 15:38:43 +02:00
if (parentId) {
path = itemdb.computePath(parentId) ~ "/" ~ name;
2015-09-14 23:56:14 +02:00
}
2015-09-01 20:45:34 +02:00
ItemType type;
if (isItemDeleted(item)) {
log.vlog("The item is marked for deletion");
2015-09-19 15:38:43 +02:00
if (cached) {
itemdb.deleteById(id);
pathsToDelete ~= oldPath;
}
2015-09-01 20:45:34 +02:00
return;
} else if (isItemFile(item)) {
type = ItemType.file;
2015-09-19 15:38:43 +02:00
if (!path.matchFirst(skipFile).empty) {
log.vlog("Filtered out");
return;
}
2015-09-01 20:45:34 +02:00
} else if (isItemFolder(item)) {
type = ItemType.dir;
2015-09-19 15:38:43 +02:00
if (!path.matchFirst(skipDir).empty) {
log.vlog("Filtered out");
skippedItems ~= id;
return;
}
2015-09-01 20:45:34 +02:00
} else {
log.vlog("The item is neither a file nor a directory, skipping");
2015-09-16 10:29:20 +02:00
skippedItems ~= id;
return;
}
string cTag;
try {
cTag = item["cTag"].str;
} catch (JSONException e) {
// cTag is not returned if the Item is a folder
// https://dev.onedrive.com/resources/item.htm
cTag = "";
}
2015-09-22 16:14:16 +02:00
string mtime = item["fileSystemInfo"]["lastModifiedDateTime"].str;
2015-09-01 20:45:34 +02:00
string crc32;
if (type == ItemType.file) {
try {
2015-09-22 16:14:16 +02:00
crc32 = item["file"]["hashes"]["crc32Hash"].str;
2015-09-01 20:45:34 +02:00
} catch (JSONException e) {
log.vlog("The hash is not available");
2015-09-01 20:45:34 +02:00
}
}
2015-09-19 15:38:43 +02:00
Item newItem = {
id: id,
name: name,
type: type,
eTag: eTag,
cTag: cTag,
mtime: SysTime.fromISOExtString(mtime),
parentId: parentId,
crc32: crc32
};
if (!cached) {
applyNewItem(newItem, path);
2015-09-17 16:28:24 +02:00
} else {
2015-09-19 15:38:43 +02:00
applyChangedItem(oldItem, newItem, path);
2015-09-17 16:28:24 +02:00
}
2015-09-01 20:45:34 +02:00
2015-09-19 15:38:43 +02:00
// save the item in the db
if (oldItem.id) {
itemdb.update(id, name, type, eTag, cTag, mtime, parentId, crc32);
} else {
itemdb.insert(id, name, type, eTag, cTag, mtime, parentId, crc32);
2015-09-01 20:45:34 +02:00
}
}
2015-09-19 15:38:43 +02:00
private void applyNewItem(Item item, string path)
2015-09-01 20:45:34 +02:00
{
2015-09-19 15:38:43 +02:00
if (exists(path)) {
if (isItemSynced(item, path)) {
log.vlog("The item is already present");
2015-09-14 23:56:14 +02:00
// ensure the modified time is correct
2015-09-19 15:38:43 +02:00
setTimes(path, item.mtime, item.mtime);
2015-09-01 20:45:34 +02:00
return;
} else {
log.vlog("The local item is out of sync, renaming ...");
2015-09-19 15:38:43 +02:00
safeRename(path);
2015-09-01 20:45:34 +02:00
}
}
final switch (item.type) {
case ItemType.file:
log.log("Downloading: ", path);
2015-09-22 11:52:28 +02:00
onedrive.downloadById(item.id, path);
2015-09-01 20:45:34 +02:00
break;
case ItemType.dir:
log.log("Creating directory: ", path);
2015-09-19 15:38:43 +02:00
mkdir(path);
2015-09-01 20:45:34 +02:00
break;
}
2015-09-19 15:38:43 +02:00
setTimes(path, item.mtime, item.mtime);
2015-09-01 20:45:34 +02:00
}
2015-09-19 15:38:43 +02:00
private void applyChangedItem(Item oldItem, Item newItem, string newPath)
2015-09-01 20:45:34 +02:00
{
assert(oldItem.id == newItem.id);
2015-09-14 23:56:14 +02:00
assert(oldItem.type == newItem.type);
if (oldItem.eTag != newItem.eTag) {
2015-09-19 15:38:43 +02:00
string oldPath = itemdb.computePath(oldItem.id);
if (oldPath != newPath) {
log.log("Moving: ", oldPath, " -> ", newPath);
2015-09-19 15:38:43 +02:00
if (exists(newPath)) {
log.vlog("The destination is occupied, renaming ...");
2015-09-19 15:38:43 +02:00
safeRename(newPath);
2015-09-01 20:45:34 +02:00
}
2015-09-19 15:38:43 +02:00
rename(oldPath, newPath);
2015-09-01 20:45:34 +02:00
}
2015-09-14 23:56:14 +02:00
if (newItem.type == ItemType.file && oldItem.cTag != newItem.cTag) {
log.log("Downloading: ", newPath);
2015-09-19 15:38:43 +02:00
onedrive.downloadById(newItem.id, newPath);
2015-09-14 23:56:14 +02:00
}
2015-09-19 15:38:43 +02:00
setTimes(newPath, newItem.mtime, newItem.mtime);
2015-09-01 20:45:34 +02:00
} else {
log.vlog("The item has not changed");
2015-09-01 20:45:34 +02:00
}
}
// returns true if the given item corresponds to the local one
2015-09-19 15:38:43 +02:00
private bool isItemSynced(Item item, string path)
2015-09-01 20:45:34 +02:00
{
2015-09-19 15:38:43 +02:00
if (!exists(path)) return false;
2015-09-01 20:45:34 +02:00
final switch (item.type) {
case ItemType.file:
2015-09-19 15:38:43 +02:00
if (isFile(path)) {
SysTime localModifiedTime = timeLastModified(path);
2015-09-01 20:45:34 +02:00
import core.time: Duration;
item.mtime.fracSecs = Duration.zero; // HACK
2015-09-14 23:56:14 +02:00
if (localModifiedTime == item.mtime) {
return true;
} else {
log.vlog("The local item has a different modified time ", localModifiedTime, " remote is ", item.mtime);
2015-09-01 20:45:34 +02:00
}
2015-09-19 15:38:43 +02:00
if (testCrc32(path, item.crc32)) {
return true;
} else {
log.vlog("The local item has a different hash");
2015-09-01 20:45:34 +02:00
}
} else {
log.vlog("The local item is a directory but should be a file");
2015-09-01 20:45:34 +02:00
}
break;
case ItemType.dir:
2015-09-19 15:38:43 +02:00
if (isDir(path)) {
2015-09-14 23:56:14 +02:00
return true;
} else {
log.vlog("The local item is a file but should be a directory");
2015-09-01 20:45:34 +02:00
}
break;
}
return false;
}
2015-09-14 23:56:14 +02:00
private void deleteItems()
2015-09-01 20:45:34 +02:00
{
log.vlog("Deleting files ...");
2015-09-19 15:38:43 +02:00
foreach_reverse (path; pathsToDelete) {
2015-09-14 23:56:14 +02:00
if (exists(path)) {
if (isFile(path)) {
remove(path);
log.log("Deleted file: ", path);
} else {
try {
rmdir(path);
log.log("Deleted directory: ", path);
} catch (FileException e) {
// directory not empty
}
2015-09-06 22:42:44 +02:00
}
2015-09-01 20:45:34 +02:00
}
}
2015-09-19 15:38:43 +02:00
pathsToDelete.length = 0;
assumeSafeAppend(pathsToDelete);
2015-09-01 20:45:34 +02:00
}
2015-09-04 21:00:22 +02:00
2015-09-18 21:42:27 +02:00
// scan the given directory for differences
public void scanForDifferences(string path)
2015-09-04 21:00:22 +02:00
{
2015-09-20 21:21:51 +02:00
try {
log.vlog("Uploading differences ...");
2015-09-20 21:21:51 +02:00
Item item;
if (itemdb.selectByPath(path, item)) {
uploadDifferences(item);
}
log.vlog("Uploading new items ...");
2015-09-20 21:21:51 +02:00
uploadNewItems(path);
2015-09-22 11:52:28 +02:00
} catch (ErrnoException e) {
throw new SyncException(e.msg, e);
2015-09-20 21:21:51 +02:00
} catch (FileException e) {
throw new SyncException(e.msg, e);
} catch (OneDriveException e) {
throw new SyncException(e.msg, e);
2015-09-08 18:25:41 +02:00
}
2015-09-04 21:00:22 +02:00
}
2015-09-20 21:21:51 +02:00
private void uploadDifferences(Item item)
2015-09-11 18:33:22 +02:00
{
log.vlog(item.id, " ", item.name);
2015-09-19 15:38:43 +02:00
string path = itemdb.computePath(item.id);
2015-09-18 21:42:27 +02:00
final switch (item.type) {
case ItemType.dir:
2015-09-19 15:38:43 +02:00
if (!path.matchFirst(skipDir).empty) {
log.vlog("Filtered out");
2015-09-19 09:45:45 +02:00
break;
}
2015-09-19 15:38:43 +02:00
uploadDirDifferences(item, path);
2015-09-18 21:42:27 +02:00
break;
case ItemType.file:
2015-09-19 15:38:43 +02:00
if (!path.matchFirst(skipFile).empty) {
log.vlog("Filtered out");
2015-09-19 09:45:45 +02:00
break;
}
2015-09-19 15:38:43 +02:00
uploadFileDifferences(item, path);
2015-09-18 21:42:27 +02:00
break;
2015-09-11 18:33:22 +02:00
}
}
2015-09-19 15:38:43 +02:00
private void uploadDirDifferences(Item item, string path)
2015-09-04 21:00:22 +02:00
{
2015-09-18 21:42:27 +02:00
assert(item.type == ItemType.dir);
2015-09-19 15:38:43 +02:00
if (exists(path)) {
if (!isDir(path)) {
log.vlog("The item was a directory but now is a file");
2015-09-19 15:38:43 +02:00
uploadDeleteItem(item, path);
uploadNewFile(path);
2015-09-18 21:42:27 +02:00
} else {
log.vlog("The directory has not changed");
2015-09-18 21:42:27 +02:00
// loop trough the children
foreach (Item child; itemdb.selectChildren(item.id)) {
uploadDifferences(child);
}
}
2015-09-18 21:42:27 +02:00
} else {
log.vlog("The directory has been deleted");
2015-09-19 15:38:43 +02:00
uploadDeleteItem(item, path);
2015-09-18 21:42:27 +02:00
}
}
2015-09-19 15:38:43 +02:00
private void uploadFileDifferences(Item item, string path)
2015-09-18 21:42:27 +02:00
{
assert(item.type == ItemType.file);
2015-09-19 15:38:43 +02:00
if (exists(path)) {
if (isFile(path)) {
SysTime localModifiedTime = timeLastModified(path);
2015-09-18 21:42:27 +02:00
import core.time: Duration;
item.mtime.fracSecs = Duration.zero; // HACK
if (localModifiedTime != item.mtime) {
log.vlog("The file last modified time has changed");
2015-09-18 21:42:27 +02:00
string id = item.id;
string eTag = item.eTag;
2015-09-19 15:38:43 +02:00
if (!testCrc32(path, item.crc32)) {
log.vlog("The file content has changed");
log.log("Uploading: ", path);
JSONValue response;
if (getSize(path) <= thresholdFileSize) {
response = onedrive.simpleUpload(path, path, eTag);
} else {
response = session.upload(path, path, eTag);
}
saveItem(response);
id = response["id"].str;
2015-09-21 17:23:12 +02:00
/* use the cTag instead of the eTag because Onedrive changes the
* metadata of some type of files (ex. images) AFTER they have been
* uploaded */
eTag = response["cTag"].str;
2015-09-17 16:28:24 +02:00
}
2015-09-18 21:42:27 +02:00
uploadLastModifiedTime(id, eTag, localModifiedTime.toUTC());
2015-09-06 22:42:44 +02:00
} else {
log.vlog("The file has not changed");
2015-09-06 22:42:44 +02:00
}
2015-09-18 21:42:27 +02:00
} else {
log.vlog("The item was a file but now is a directory");
2015-09-19 15:38:43 +02:00
uploadDeleteItem(item, path);
uploadCreateDir(path);
2015-09-04 21:00:22 +02:00
}
} else {
log.vlog("The file has been deleted");
2015-09-19 15:38:43 +02:00
uploadDeleteItem(item, path);
2015-09-11 18:33:22 +02:00
}
}
2015-09-18 21:42:27 +02:00
private void uploadNewItems(string path)
2015-09-08 18:25:41 +02:00
{
2016-08-22 04:45:24 +02:00
if (isSymlink(path) && !exists(readLink(path))) {
return;
}
2015-09-18 21:42:27 +02:00
if (isDir(path)) {
2015-09-19 15:38:43 +02:00
if (path.matchFirst(skipDir).empty) {
2015-09-18 21:42:27 +02:00
Item item;
if (!itemdb.selectByPath(path, item)) {
2015-09-17 16:28:24 +02:00
uploadCreateDir(path);
2015-09-18 21:42:27 +02:00
}
auto entries = dirEntries(path, SpanMode.shallow, false);
foreach (DirEntry entry; entries) {
uploadNewItems(entry.name);
}
}
} else {
2015-09-19 15:38:43 +02:00
if (path.matchFirst(skipFile).empty) {
2015-09-18 21:42:27 +02:00
Item item;
if (!itemdb.selectByPath(path, item)) {
2015-09-17 16:28:24 +02:00
uploadNewFile(path);
2015-09-18 21:42:27 +02:00
}
2015-09-08 18:25:41 +02:00
}
2015-09-06 22:42:44 +02:00
}
2015-09-08 18:25:41 +02:00
}
2015-09-18 21:42:27 +02:00
private void uploadCreateDir(const(char)[] path)
2015-09-08 18:25:41 +02:00
{
log.log("Creating remote directory: ", path);
2015-09-16 10:29:20 +02:00
JSONValue item = ["name": baseName(path).idup];
2015-09-14 12:57:47 +02:00
item["folder"] = parseJSON("{}");
2015-09-20 19:07:16 +02:00
auto res = onedrive.createByPath(path.dirName ~ "/", item);
2015-09-16 10:29:20 +02:00
saveItem(res);
}
private void uploadNewFile(string path)
{
log.log("Uploading: ", path);
JSONValue response;
if (getSize(path) <= thresholdFileSize) {
response = onedrive.simpleUpload(path, path);
} else {
response = session.upload(path, path);
}
saveItem(response);
string id = response["id"].str;
string cTag = response["cTag"].str;
2015-09-20 21:21:51 +02:00
SysTime mtime = timeLastModified(path).toUTC();
2015-09-21 17:23:12 +02:00
/* use the cTag instead of the eTag because Onedrive changes the
* metadata of some type of files (ex. images) AFTER they have been
* uploaded */
uploadLastModifiedTime(id, cTag, mtime);
2015-09-16 10:29:20 +02:00
}
2015-09-19 15:38:43 +02:00
private void uploadDeleteItem(Item item, const(char)[] path)
2015-09-16 10:29:20 +02:00
{
log.log("Deleting remote item: ", path);
2015-10-04 16:25:31 +02:00
try {
onedrive.deleteById(item.id, item.eTag);
} catch (OneDriveException e) {
2016-12-14 15:17:20 +01:00
if (e.httpStatusCode == 404) log.log(e.msg);
2015-10-04 16:25:31 +02:00
else throw e;
}
2015-09-16 10:29:20 +02:00
itemdb.deleteById(item.id);
2015-09-08 18:25:41 +02:00
}
2015-09-16 10:29:20 +02:00
private void uploadLastModifiedTime(const(char)[] id, const(char)[] eTag, SysTime mtime)
2015-09-08 18:25:41 +02:00
{
JSONValue mtimeJson = [
"fileSystemInfo": JSONValue([
"lastModifiedDateTime": mtime.toISOExtString()
])
];
2015-09-11 18:33:22 +02:00
auto res = onedrive.updateById(id, mtimeJson, eTag);
2015-09-16 10:29:20 +02:00
saveItem(res);
2015-09-08 18:25:41 +02:00
}
2015-09-16 10:29:20 +02:00
private void saveItem(JSONValue item)
2015-09-08 18:25:41 +02:00
{
2015-09-16 10:29:20 +02:00
string id = item["id"].str;
ItemType type;
if (isItemFile(item)) {
type = ItemType.file;
} else if (isItemFolder(item)) {
type = ItemType.dir;
} else {
assert(0);
}
string name = item["name"].str;
string eTag = item["eTag"].str;
string cTag = item["cTag"].str;
2015-09-22 16:14:16 +02:00
string mtime = item["fileSystemInfo"]["lastModifiedDateTime"].str;
string parentId = item["parentReference"]["id"].str;
2015-09-16 10:29:20 +02:00
string crc32;
if (type == ItemType.file) {
try {
2015-09-22 16:14:16 +02:00
crc32 = item["file"]["hashes"]["crc32Hash"].str;
2015-09-16 10:29:20 +02:00
} catch (JSONException e) {
// swallow exception
}
}
2015-09-17 16:28:24 +02:00
itemdb.upsert(id, name, type, eTag, cTag, mtime, parentId, crc32);
2015-09-16 10:29:20 +02:00
}
2015-09-19 15:38:43 +02:00
void uploadMoveItem(string from, string to)
2015-09-16 10:29:20 +02:00
{
log.log("Moving remote item: ", from, " -> ", to);
2015-09-20 19:07:16 +02:00
Item fromItem, toItem, parentItem;
if (!itemdb.selectByPath(from, fromItem)) {
2015-09-20 21:21:51 +02:00
throw new SyncException("Can't move an unsynced item");
2015-09-11 18:33:22 +02:00
}
2015-09-20 19:07:16 +02:00
if (itemdb.selectByPath(to, toItem)) {
// the destination has been overridden
uploadDeleteItem(toItem, to);
}
if (!itemdb.selectByPath(to.dirName, parentItem)) {
2015-09-20 21:21:51 +02:00
throw new SyncException("Can't move an item to an unsynced directory");
2015-09-17 16:28:24 +02:00
}
2015-09-11 18:33:22 +02:00
JSONValue diff = ["name": baseName(to)];
diff["parentReference"] = JSONValue([
2015-09-20 19:07:16 +02:00
"id": parentItem.id
2015-09-11 18:33:22 +02:00
]);
2015-09-20 19:07:16 +02:00
auto res = onedrive.updateById(fromItem.id, diff, fromItem.eTag);
2015-09-16 10:29:20 +02:00
saveItem(res);
2015-09-17 16:28:24 +02:00
string id = res["id"].str;
string eTag = res["eTag"].str;
uploadLastModifiedTime(id, eTag, timeLastModified(to).toUTC());
2015-09-11 18:33:22 +02:00
}
void deleteByPath(const(char)[] path)
{
Item item;
2015-09-14 23:56:14 +02:00
if (!itemdb.selectByPath(path, item)) {
2015-09-17 00:16:23 +02:00
throw new SyncException("Can't delete an unsynced item");
2015-09-11 18:33:22 +02:00
}
2015-10-04 16:25:31 +02:00
try {
uploadDeleteItem(item, path);
} catch (OneDriveException e) {
2016-12-14 15:17:20 +01:00
if (e.httpStatusCode == 404) log.log(e.msg);
2015-10-04 16:25:31 +02:00
else throw e;
}
2015-09-11 18:33:22 +02:00
}
2015-09-01 20:45:34 +02:00
}