mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-02 14:02:21 +02:00
* Add explicit check for hashes to be returned in cases where OneDrive API fails to provide them despite requested to do so * Add comparison with sha1 if OneDrive provides that rather than quickXor
This commit is contained in:
parent
170198c557
commit
66764f279d
42
src/sync.d
42
src/sync.d
|
@ -79,11 +79,21 @@ private bool hasId(const ref JSONValue item)
|
||||||
return ("id" in item) != null;
|
return ("id" in item) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool hasHashes(const ref JSONValue item)
|
||||||
|
{
|
||||||
|
return ("hashes" in item["file"]) != null;
|
||||||
|
}
|
||||||
|
|
||||||
private bool hasQuickXorHash(const ref JSONValue item)
|
private bool hasQuickXorHash(const ref JSONValue item)
|
||||||
{
|
{
|
||||||
return ("quickXorHash" in item["file"]["hashes"]) != null;
|
return ("quickXorHash" in item["file"]["hashes"]) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool hasSha1Hash(const ref JSONValue item)
|
||||||
|
{
|
||||||
|
return ("sha1Hash" in item["file"]["hashes"]) != null;
|
||||||
|
}
|
||||||
|
|
||||||
private bool isDotFile(string path)
|
private bool isDotFile(string path)
|
||||||
{
|
{
|
||||||
// always allow the root
|
// always allow the root
|
||||||
|
@ -1150,13 +1160,26 @@ final class SyncEngine
|
||||||
// filesize missing
|
// filesize missing
|
||||||
log.vdebug("WARNING: fileDetails['size'] is missing");
|
log.vdebug("WARNING: fileDetails['size'] is missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasQuickXorHash(fileDetails)) {
|
if (hasHashes(fileDetails)) {
|
||||||
// Use the configured quickXorHash as reported by OneDrive
|
// File details returned hash details
|
||||||
OneDriveFileHash = fileDetails["file"]["hashes"]["quickXorHash"].str;
|
// QuickXorHash
|
||||||
|
if (hasQuickXorHash(fileDetails)) {
|
||||||
|
// Use the configured quickXorHash as reported by OneDrive
|
||||||
|
if (fileDetails["file"]["hashes"]["quickXorHash"].str != "") {
|
||||||
|
OneDriveFileHash = fileDetails["file"]["hashes"]["quickXorHash"].str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check for Sha1Hash
|
||||||
|
if (hasSha1Hash(fileDetails)) {
|
||||||
|
// Use the configured sha1Hash as reported by OneDrive
|
||||||
|
if (fileDetails["file"]["hashes"]["sha1Hash"].str != "") {
|
||||||
|
OneDriveFileHash = fileDetails["file"]["hashes"]["sha1Hash"].str;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// filesize missing
|
// file hash data missing
|
||||||
log.vdebug("WARNING: fileDetails['file']['hashes']['quickXorHash'] is missing");
|
log.vdebug("WARNING: fileDetails['file']['hashes'] is missing - unable to compare file hash after download");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1194,8 +1217,11 @@ final class SyncEngine
|
||||||
// A 'file' was downloaded - does what we downloaded = reported fileSize or if there is some sort of funky local disk compression going on
|
// A 'file' was downloaded - does what we downloaded = reported fileSize or if there is some sort of funky local disk compression going on
|
||||||
// does the file hash OneDrive reports match what we have locally?
|
// does the file hash OneDrive reports match what we have locally?
|
||||||
string quickXorHash = computeQuickXorHash(path);
|
string quickXorHash = computeQuickXorHash(path);
|
||||||
if ((getSize(path) == fileSize) || (OneDriveFileHash == quickXorHash)) {
|
string sha1Hash = computeSha1Hash(path);
|
||||||
|
|
||||||
|
if ((getSize(path) == fileSize) || (OneDriveFileHash == quickXorHash) || (OneDriveFileHash == sha1Hash)) {
|
||||||
// downloaded matches either size or hash
|
// downloaded matches either size or hash
|
||||||
|
log.vdebug("Downloaded file matches reported size and or reported file hash");
|
||||||
setTimes(path, item.mtime, item.mtime);
|
setTimes(path, item.mtime, item.mtime);
|
||||||
} else {
|
} else {
|
||||||
// size error?
|
// size error?
|
||||||
|
@ -1204,7 +1230,7 @@ final class SyncEngine
|
||||||
log.error("ERROR: File download size mis-match. Increase logging verbosity to determine why.");
|
log.error("ERROR: File download size mis-match. Increase logging verbosity to determine why.");
|
||||||
}
|
}
|
||||||
// hash error?
|
// hash error?
|
||||||
if (OneDriveFileHash != quickXorHash) {
|
if ((OneDriveFileHash != quickXorHash) || (OneDriveFileHash != sha1Hash)) {
|
||||||
// downloaded file hash does not match
|
// downloaded file hash does not match
|
||||||
log.error("ERROR: File download hash mis-match. Increase logging verbosity to determine why.");
|
log.error("ERROR: File download hash mis-match. Increase logging verbosity to determine why.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue