Fix regression of Microsoft OneNote package folder being created in error (#3160)

* Fix regression of Microsoft OneNote package folder being created in error
This commit is contained in:
abraunegg 2025-03-20 20:27:44 +11:00 committed by GitHub
commit fd74b19cae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 19 deletions

View file

@ -527,7 +527,7 @@ class OneDriveApi {
url = itemByPathUrl ~ encodeComponent(path) ~ ":/";
}
// Add select clause
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy,package";
return get(url);
}
@ -536,7 +536,7 @@ class OneDriveApi {
JSONValue getPathDetailsById(string driveId, string id) {
string url;
url = driveByIdUrl ~ driveId ~ "/items/" ~ id;
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy,webUrl,lastModifiedDateTime";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy,webUrl,lastModifiedDateTime,package";
return get(url);
}
@ -561,7 +561,7 @@ class OneDriveApi {
// https://learn.microsoft.com/en-us/onedrive/developer/rest-api/concepts/addressing-driveitems?view=odsp-graph-online
// Required format: /drives/{drive-id}/root:/{item-path}:
url = driveByIdUrl ~ driveId ~ "/root:/" ~ encodeComponent(path) ~ ":";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy,package";
return get(url);
}
@ -591,7 +591,7 @@ class OneDriveApi {
if (deltaLink.empty) {
url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/delta";
// Reduce what we ask for in the response - which reduces the data transferred back to us, and reduces what is held in memory during initial JSON processing
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy,package";
} else {
url = deltaLink;
}
@ -621,7 +621,7 @@ class OneDriveApi {
// configure URL to query
if (nextLink.empty) {
url = driveByIdUrl ~ driveId ~ "/items/" ~ id ~ "/children";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy";
url ~= "?select=id,name,eTag,cTag,deleted,file,folder,root,fileSystemInfo,remoteItem,parentReference,size,createdBy,lastModifiedBy,package";
} else {
url = nextLink;
}

View file

@ -1744,20 +1744,16 @@ class SyncEngine {
// Do we discard this JSON item?
bool discardDeltaJSONItem = false;
// Microsoft OneNote container objects present neither folder or file but has file size
if ((!isItemFile(onedriveJSONItem)) && (!isItemFolder(onedriveJSONItem)) && (hasFileSize(onedriveJSONItem))) {
// This JSON:
// - Is not a file
// - Is not a folder
// - Has a 'size' element
// Online Shared Folder Shortcuts can match the same criteria - we need to ensure this is not a Online Shared Folder Shortcuts
if (!itemIsRemoteItem) {
// Not a pointer to a remote item, thus high confidence this is not a shared folder link
// Log that this was skipped as this was a Microsoft OneNote item and unsupported
if (verboseLogging) {addLogEntry("Skipping path - The Microsoft OneNote Notebook '" ~ generatePathFromJSONData(onedriveJSONItem) ~ "' is not supported by this client", ["verbose"]);}
discardDeltaJSONItem = true;
}
// Microsoft OneNote container objects present neither folder or file but contain a 'package' element
// "package": {
// "type": "oneNote"
// },
// Confirmed with Microsoft OneDrive Personal
// Confirmed with Microsoft OneDrive Business
if (isOneNotePackageFolder(onedriveJSONItem)) {
// This JSON has this element
if (verboseLogging) {addLogEntry("Skipping path - The Microsoft OneNote Notebook Package '" ~ generatePathFromJSONData(onedriveJSONItem) ~ "' is not supported by this client", ["verbose"]);}
discardDeltaJSONItem = true;
}
// Microsoft OneDrive OneNote file objects will report as files but have 'application/msonenote' or 'application/octet-stream' as their mime type and will not have any hash entry

View file

@ -1142,6 +1142,16 @@ bool isMalware(const ref JSONValue item) {
return ("malware" in item) != null;
}
bool isOneNotePackageFolder(const ref JSONValue item) {
if ("package" in item) {
auto pkg = item["package"];
if ("type" in pkg && pkg["type"].type == JSONType.string) {
return pkg["type"].str == "oneNote";
}
}
return false;
}
bool hasHashes(const ref JSONValue item) {
return ("hashes" in item["file"]) != null;
}