mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-02 22:12:33 +02:00
Improve upload handling of files for SharePoint sites (#1250)
* After a file has been uploaded to SharePoint, use the response JSON and compare the quickXorHash to that of the local file before the upload. If there is a difference, Microsoft has modified the file post upload, thus we now need to download this 'updated' file. If there is no hash difference, we do not need to download the file.
This commit is contained in:
parent
2babba5b6c
commit
2c253362bf
16
src/sync.d
16
src/sync.d
|
@ -4831,6 +4831,9 @@ final class SyncEngine
|
||||||
// HTTP request returned status code 413 (Request Entity Too Large)
|
// HTTP request returned status code 413 (Request Entity Too Large)
|
||||||
// We also cant use a session to upload the file, we have to use simpleUploadReplace
|
// We also cant use a session to upload the file, we have to use simpleUploadReplace
|
||||||
|
|
||||||
|
// Calculate existing hash for this file
|
||||||
|
string existingFileHash = computeQuickXorHash(path);
|
||||||
|
|
||||||
if (getSize(path) <= thresholdFileSize) {
|
if (getSize(path) <= thresholdFileSize) {
|
||||||
// Upload file via simpleUploadReplace as below threshold size
|
// Upload file via simpleUploadReplace as below threshold size
|
||||||
try {
|
try {
|
||||||
|
@ -4889,8 +4892,20 @@ final class SyncEngine
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
// Is the response a valid JSON object - validation checking done in saveItem
|
// Is the response a valid JSON object - validation checking done in saveItem
|
||||||
saveItem(response);
|
saveItem(response);
|
||||||
|
|
||||||
// Due to https://github.com/OneDrive/onedrive-api-docs/issues/935 Microsoft modifies all PDF, MS Office & HTML files with added XML content. It is a 'feature' of SharePoint.
|
// Due to https://github.com/OneDrive/onedrive-api-docs/issues/935 Microsoft modifies all PDF, MS Office & HTML files with added XML content. It is a 'feature' of SharePoint.
|
||||||
// So - now the 'local' and 'remote' file is technically DIFFERENT ... thanks Microsoft .. NO way to disable this stupidity
|
// So - now the 'local' and 'remote' file is technically DIFFERENT ... thanks Microsoft .. NO way to disable this stupidity
|
||||||
|
string uploadNewFileHash;
|
||||||
|
if (hasQuickXorHash(response)) {
|
||||||
|
// use the response json hash detail to compare
|
||||||
|
uploadNewFileHash = response["file"]["hashes"]["quickXorHash"].str;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingFileHash != uploadNewFileHash) {
|
||||||
|
// file was modified by Microsoft post upload to SharePoint site
|
||||||
|
log.vdebug("Existing Local File Hash: ", existingFileHash);
|
||||||
|
log.vdebug("New Remote File Hash: ", uploadNewFileHash);
|
||||||
|
|
||||||
if(!uploadOnly){
|
if(!uploadOnly){
|
||||||
// Download the Microsoft 'modified' file so 'local' is now in sync
|
// Download the Microsoft 'modified' file so 'local' is now in sync
|
||||||
log.vlog("Due to Microsoft Sharepoint 'enrichment' of files, downloading 'enriched' file to ensure local file is in-sync");
|
log.vlog("Due to Microsoft Sharepoint 'enrichment' of files, downloading 'enriched' file to ensure local file is in-sync");
|
||||||
|
@ -4904,6 +4919,7 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Log action to log file
|
// Log action to log file
|
||||||
log.fileOnly("Uploading modified file ", path, " ... done.");
|
log.fileOnly("Uploading modified file ", path, " ... done.");
|
||||||
|
|
Loading…
Reference in a new issue