From 8a059dc0e1ae81794bdebf77d0d7e8ebede280db Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sat, 21 Apr 2018 07:19:04 +1000 Subject: [PATCH] Revert "Switch to using list_children for an item id's children" This reverts commit fedaedacd777548b3651071519b61a8544e03ade. --- src/onedrive.d | 15 ++++++++------- src/sync.d | 20 +++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index 1c731977..976d6951 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -114,15 +114,16 @@ final class OneDriveApi return get(url); } - // https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children - JSONValue viewChildrenById(const(char)[] driveId, const(char)[] id) + // https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delta + JSONValue viewChangesByPath(const(char)[] path, const(char)[] deltaLink) { - // Get a list of children for a given item id - // Returns a value array where each array element has the following: - // id,name,eTag,cTag,file,folder,fileSystemInfo,remoteItem,parentReference checkAccessTokenExpired(); - // GET /drives/{drive-id}/items/{item-id}/children - const(char)[] url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/children"; + const(char)[] url = deltaLink; + if (url == null) { + if (path == ".") url = driveUrl ~ "/root/delta"; + else url = itemByPathUrl ~ encodeComponent(path) ~ ":/delta"; + url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference"; + } return get(url); } diff --git a/src/sync.d b/src/sync.d index 76be306d..e47d9633 100644 --- a/src/sync.d +++ b/src/sync.d @@ -181,14 +181,13 @@ final class SyncEngine if (e.httpStatusCode == 404) { // The directory was not found log.vlog("ERROR: The requested single directory to sync was not found on OneDrive"); - // We are expecting this directory however as this is a single directory sync - uploadCreateDir(path); + return; } } // OK - it should exist, get the driveId and rootId for this folder log.vlog("Checking for differences from OneDrive ..."); - // If the OneDrive Root is not in the local database, creating a remote folder in the selected path will fail + // If the OneDrive Root is not in the local database, creating a remote folder will fail checkDatabaseForOneDriveRoot(); // Configure driveID and folderId @@ -289,10 +288,17 @@ final class SyncEngine log.vlog("Applying changes of Path ID: " ~ id); for (;;) { - // Will provide a JSON of children of the item id - changes = onedrive.viewChildrenById(driveId, id); - - // For each 'value' item (child resource .. + try { + changes = onedrive.viewChangesById(driveId, id, deltaLink); + } catch (OneDriveException e) { + if (e.httpStatusCode == 410) { + log.vlog("Delta link expired, resyncing..."); + deltaLink = null; + continue; + } else { + throw e; + } + } foreach (item; changes["value"].array) { bool isRoot = (id == defaultRootId); // fix for https://github.com/skilion/onedrive/issues/269 // Apply the change