mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-08 08:52:15 +02:00
* Update handling of shared folders and items which was previously broken to a OneDrive API change * Extract syncFolderName from either local or remote folder - not just local folder.
This commit is contained in:
parent
a571f78ed3
commit
53b72e0d9d
24
src/sync.d
24
src/sync.d
|
@ -40,7 +40,7 @@ private bool isItemRemote(const ref JSONValue item)
|
||||||
return ("remoteItem" in item) != null;
|
return ("remoteItem" in item) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool changeHasParentReferenceId(const ref JSONValue item)
|
private bool hasParentReferenceId(const ref JSONValue item)
|
||||||
{
|
{
|
||||||
return ("id" in item["parentReference"]) != null;
|
return ("id" in item["parentReference"]) != null;
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,10 @@ private Item makeItem(const ref JSONValue driveItem)
|
||||||
|
|
||||||
// root and remote items do not have parentReference
|
// root and remote items do not have parentReference
|
||||||
if (!isItemRoot(driveItem) && ("parentReference" in driveItem) != null) {
|
if (!isItemRoot(driveItem) && ("parentReference" in driveItem) != null) {
|
||||||
item.driveId = driveItem["parentReference"]["driveId"].str,
|
item.driveId = driveItem["parentReference"]["driveId"].str;
|
||||||
item.parentId = driveItem["parentReference"]["id"].str;
|
if (hasParentReferenceId(driveItem)) {
|
||||||
|
item.parentId = driveItem["parentReference"]["id"].str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract the file hash
|
// extract the file hash
|
||||||
|
@ -380,7 +382,8 @@ final class SyncEngine
|
||||||
// Get the name of this 'Path ID'
|
// Get the name of this 'Path ID'
|
||||||
if (("id" in idDetails) != null) {
|
if (("id" in idDetails) != null) {
|
||||||
// valid response from onedrive.getPathDetailsById(driveId, id) - a JSON item object present
|
// valid response from onedrive.getPathDetailsById(driveId, id) - a JSON item object present
|
||||||
if ((idDetails["id"].str == id) && (isItemFolder(idDetails))){
|
if ((idDetails["id"].str == id) && (!isItemFile(idDetails))){
|
||||||
|
// Is a Folder or Remote Folder
|
||||||
syncFolderName = encodeComponent(idDetails["name"].str);
|
syncFolderName = encodeComponent(idDetails["name"].str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,7 +454,7 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test is this a Shared Folder - which should also be classified as a 'root' item
|
// Test is this a Shared Folder - which should also be classified as a 'root' item
|
||||||
if (changeHasParentReferenceId(item)) {
|
if (hasParentReferenceId(item)) {
|
||||||
// item contains parentReference key
|
// item contains parentReference key
|
||||||
if (item["parentReference"]["driveId"].str != defaultDriveId) {
|
if (item["parentReference"]["driveId"].str != defaultDriveId) {
|
||||||
// The change parentReference driveId does not match the defaultDriveId - this could be a Shared Folder root item
|
// The change parentReference driveId does not match the defaultDriveId - this could be a Shared Folder root item
|
||||||
|
@ -465,14 +468,19 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
// How do we handle this change?
|
// How do we handle this change?
|
||||||
if (isRoot || !changeHasParentReferenceId(item) || isItemDeleted(item)){
|
if (isRoot || !hasParentReferenceId(item) || isItemDeleted(item)){
|
||||||
// Is a root item, has no id in parentReference or is a OneDrive deleted item
|
// Is a root item, has no id in parentReference or is a OneDrive deleted item
|
||||||
applyDifference(item, driveId, isRoot);
|
applyDifference(item, driveId, isRoot);
|
||||||
} else {
|
} else {
|
||||||
// What is this item's path?
|
// What is this item's path?
|
||||||
thisItemPath = item["parentReference"]["path"].str;
|
thisItemPath = item["parentReference"]["path"].str;
|
||||||
// Check this item's path to see if this is a change on the path we want
|
// Check this item's path to see if this is a change on the path we want:
|
||||||
if ( (item["id"].str == id) || (item["parentReference"]["id"].str == id) || (canFind(thisItemPath, syncFolderName)) ){
|
// 1. 'item id' matches 'id'
|
||||||
|
// 2. 'parentReference id' matches 'id'
|
||||||
|
// 3. 'item path' contains 'sync folder name'
|
||||||
|
// 4. 'item path' contains 'id'
|
||||||
|
|
||||||
|
if ( (item["id"].str == id) || (item["parentReference"]["id"].str == id) || (canFind(thisItemPath, syncFolderName)) || (canFind(thisItemPath, id)) ){
|
||||||
// This is a change we want to apply
|
// This is a change we want to apply
|
||||||
applyDifference(item, driveId, isRoot);
|
applyDifference(item, driveId, isRoot);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue