From c2e98ff639069379ad482d019e8bae07369c676f Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 18 Dec 2023 18:55:54 +1100 Subject: [PATCH] Update sync.d * Potentially fix crash identified by #2562 --- src/sync.d | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/sync.d b/src/sync.d index 3e48c6bc..ee63fd95 100644 --- a/src/sync.d +++ b/src/sync.d @@ -3275,8 +3275,16 @@ class SyncEngine { if (("path" in onedriveJSONItem["parentReference"]) != null) { // If there is a parent reference path, try and use it string selfBuiltPath = onedriveJSONItem["parentReference"]["path"].str ~ "/" ~ onedriveJSONItem["name"].str; - auto splitPath = selfBuiltPath.split("root:"); - newItemPath = splitPath[1]; + + // Check for and remove 'root:' prefix if present + auto indexOfRoot = selfBuiltPath.indexOf("root:"); + if (indexOfRoot != -1) { + // Remove 'root:' and everything before it + selfBuiltPath = selfBuiltPath[indexOfRoot + 5 .. $]; + } + + // Set newItemPath to the self built path + newItemPath = selfBuiltPath; } else { // no parent reference path available newItemPath = thisItemName; @@ -6777,8 +6785,16 @@ class SyncEngine { if (("path" in onedriveJSONItem["parentReference"]) != null) { // If there is a parent reference path, try and use it string selfBuiltPath = onedriveJSONItem["parentReference"]["path"].str ~ "/" ~ onedriveJSONItem["name"].str; - auto splitPath = selfBuiltPath.split("root:"); - thisItemPath = splitPath[1]; + + // Check for and remove 'root:' prefix if present + auto indexOfRoot = selfBuiltPath.indexOf("root:"); + if (indexOfRoot != -1) { + // Remove 'root:' and everything before it + selfBuiltPath = selfBuiltPath[indexOfRoot + 5 .. $]; + } + + // Set thisItemPath to the self built path + thisItemPath = selfBuiltPath; } else { // no parent reference path available thisItemPath = onedriveJSONItem["name"].str;