Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in handling uploading new and modified content to OneDrive Business and SharePoint #3032

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion docs/application-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Before reading this document, please ensure you are running application version
- [classify_as_big_delete](#classify_as_big_delete)
- [cleanup_local_files](#cleanup_local_files)
- [connect_timeout](#connect_timeout)
- [create_new_file_version](#create_new_file_version)
- [data_timeout](#data_timeout)
- [debug_https](#debug_https)
- [disable_download_validation](#disable_download_validation)
Expand Down Expand Up @@ -204,6 +205,23 @@ _**Default Value:**_ 10

_**Config Example:**_ `connect_timeout = "15"`

### create_new_file_version
_**Description:**_ This setting controls how the application handles the Microsoft SharePoint *feature* which modifies all PDF, MS Office & HTML files post upload, effectively breaking the integrity of your data online. By default, when the application determines that this *feature* has modified your file post upload, the now online modified file will be downloaded. When this option is enabled, rather than downloading the file, a new online file version is created which negates the download of the modified file.

_**Value Type:**_ Boolean

_**Default Value:**_ False

_**Config Example:**_ `create_new_file_version = "false"` or `create_new_file_version = "true"`

_**CLI Option Use:**_ *None - this is a config file option only*

> [!IMPORTANT]
> If you enable 'disable_upload_validation' via `disable_upload_validation = "true"` there is zero facility to determine if a file was modified post upload. As such, the application will default to the state that the upload integrity check has failed. When `create_new_file_version = "false"` your uploaded file will be downloaded *regardless* of the online modification state.

> [!WARNING]
> When this option is set to 'true', new file versions will be created online which will count towards your Microsoft OneDrive Quota.

### data_timeout
_**Description:**_ This setting controls the timeout duration, in seconds, for when data is not received on an active connection to Microsoft OneDrive over HTTPS when using the curl library, before that connection is timeout out.

Expand Down Expand Up @@ -515,6 +533,8 @@ _**Default Value:**_ False

_**Config Example:**_ `permanent_delete = "true"`

_**CLI Option Use:**_ *None - this is a config file option only*

> [!IMPORTANT]
> The Microsoft OneDrive API for this capability is also very narrow:
> | Account Type | Config Option is Supported |
Expand Down Expand Up @@ -772,7 +792,7 @@ _**Default Value:**_ False

_**Config Example:**_ `sync_business_shared_items = "false"` or `sync_business_shared_items = "true"`

_**CLI Option Use:**_ *none* - this is a config file option only
_**CLI Option Use:**_ *None - this is a config file option only*

> [!NOTE]
> This option is considered a 'Client Side Filtering Rule' and if configured, is utilised for all sync operations. After changing this option, you will be required to perform a resync.
Expand Down
5 changes: 5 additions & 0 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ class ApplicationConfig {
boolValues["cleanup_local_files"] = false;
// - Perform a permanentDelete on deletion activities
boolValues["permanent_delete"] = false;
// - Controls how the application handles the Microsoft SharePoint 'feature' of modifying all PDF, MS Office & HTML files with added XML content post upload
// There are 2 ways to solve this:
// 1. Download the modified file immediately after upload as per v2.4.x (default)
// 2. Create a new online version of the file, which then contributes to the users 'quota'
boolValues["create_new_file_version"] = false;

// Webhook Feature Options
boolValues["webhook_enabled"] = false;
Expand Down
13 changes: 7 additions & 6 deletions src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,15 @@ class OneDriveApi {
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession
//JSONValue createUploadSession(string parentDriveId, string parentId, string filename, string eTag = null, JSONValue item = null) {
JSONValue createUploadSession(string parentDriveId, string parentId, string filename, const(char)[] eTag = null, JSONValue item = null) {
// string[string] requestHeaders;
string[string] requestHeaders;
string url = driveByIdUrl ~ parentDriveId ~ "/items/" ~ parentId ~ ":/" ~ encodeComponent(filename) ~ ":/createUploadSession";
// eTag If-Match header addition commented out for the moment
// At some point, post the creation of this upload session the eTag is being 'updated' by OneDrive, thus when uploadFragment() is used
// this generates a 412 Precondition Failed and then a 416 Requested Range Not Satisfiable
// This needs to be investigated further as to why this occurs
// if (eTag) requestHeaders["If-Match"] = eTag;
return post(url, item.toString());

if (eTag) requestHeaders["If-Match"] = to!string(eTag);
return post(url, item.toString(), requestHeaders);
}

// https://dev.onedrive.com/items/upload_large_files.htm
Expand Down Expand Up @@ -823,7 +824,7 @@ class OneDriveApi {
JSONValue response;

try {
response = post(tokenUrl, postData, true, "application/x-www-form-urlencoded");
response = post(tokenUrl, postData, null, true, "application/x-www-form-urlencoded");
} catch (OneDriveException exception) {
// an error was generated
if ((exception.httpStatusCode == 400) || (exception.httpStatusCode == 401)) {
Expand Down Expand Up @@ -1141,10 +1142,10 @@ class OneDriveApi {
}, validateJSONResponse, callingFunction, lineno);
}

private JSONValue post(const(char)[] url, const(char)[] postData, bool skipToken = false, const(char)[] contentType = "application/json", string callingFunction=__FUNCTION__, int lineno=__LINE__) {
private JSONValue post(const(char)[] url, const(char)[] postData, string[string] requestHeaders=null, bool skipToken = false, const(char)[] contentType = "application/json", string callingFunction=__FUNCTION__, int lineno=__LINE__) {
bool validateJSONResponse = true;
return oneDriveErrorHandlerWrapper((CurlResponse response) {
connect(HTTP.Method.post, url, skipToken, response);
connect(HTTP.Method.post, url, skipToken, response, requestHeaders);
curlEngine.setContent(contentType, postData);
return curlEngine.execute();
}, validateJSONResponse, callingFunction, lineno);
Expand Down
Loading
Loading