mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-23 08:02:16 +02:00
Revert "Update handling of HTTP 412 - Precondition Failed errors (#issue 325) (#326)"
This reverts commit 388cc1ded5
.
This commit is contained in:
parent
388cc1ded5
commit
46ef8ed376
|
@ -670,7 +670,7 @@ final class OneDriveApi
|
||||||
// 504 - Gateway Timeout (Issue #320)
|
// 504 - Gateway Timeout (Issue #320)
|
||||||
case 500,502,503,504:
|
case 500,502,503,504:
|
||||||
// No actions
|
// No actions
|
||||||
log.vlog("OneDrive returned a 'HTTP ", http.statusLine.code, "Server Side Error' - gracefully handling error");
|
log.vlog("OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// "else"
|
// "else"
|
||||||
|
@ -695,7 +695,7 @@ final class OneDriveApi
|
||||||
// 504 - Gateway Timeout (Issue #320)
|
// 504 - Gateway Timeout (Issue #320)
|
||||||
case 500,502,503,504:
|
case 500,502,503,504:
|
||||||
// No actions
|
// No actions
|
||||||
log.vlog("OneDrive returned a 'HTTP ", http.statusLine.code, "Server Side Error' - gracefully handling error");
|
log.vlog("OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Default - all other errors that are not a 2xx or a 302
|
// Default - all other errors that are not a 2xx or a 302
|
||||||
|
|
84
src/sync.d
84
src/sync.d
|
@ -64,16 +64,6 @@ private bool hasFileSize(const ref JSONValue item)
|
||||||
return ("size" in item) != null;
|
return ("size" in item) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool hasId(const ref JSONValue item)
|
|
||||||
{
|
|
||||||
return ("id" in item) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool hasName(const ref JSONValue item)
|
|
||||||
{
|
|
||||||
return ("name" in item) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// construct an Item struct from a JSON driveItem
|
// construct an Item struct from a JSON driveItem
|
||||||
private Item makeItem(const ref JSONValue driveItem)
|
private Item makeItem(const ref JSONValue driveItem)
|
||||||
{
|
{
|
||||||
|
@ -319,7 +309,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running applyDifferencesSingleDirectory()");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,7 +396,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running deleteDirectoryNoSync()");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,7 +428,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running renameDirectoryNoSync()");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,7 +460,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running applyDifferences()");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -604,7 +590,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running applyDifferences() - oneDriveMovedNotDeleted");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1122,8 +1107,7 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 412) {
|
if (e.httpStatusCode == 412) {
|
||||||
// HTTP request returned status code 412 - ETag does not match current item's value
|
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||||
// Delete record from the local database - file will be uploaded as a new file
|
// Delete record from the local database - file will be uploaded as a new file
|
||||||
log.vlog("Simple Upload Replace Failed - OneDrive eTag / cTag match issue");
|
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
||||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file.");
|
|
||||||
itemdb.deleteById(item.driveId, item.id);
|
itemdb.deleteById(item.driveId, item.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1144,8 +1128,7 @@ final class SyncEngine
|
||||||
if (e.httpStatusCode == 412) {
|
if (e.httpStatusCode == 412) {
|
||||||
// HTTP request returned status code 412 - ETag does not match current item's value
|
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||||
// Delete record from the local database - file will be uploaded as a new file
|
// Delete record from the local database - file will be uploaded as a new file
|
||||||
log.vlog("Session Upload Replace Failed - OneDrive eTag / cTag match issue");
|
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
||||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error. Will upload as new file.");
|
|
||||||
itemdb.deleteById(item.driveId, item.id);
|
itemdb.deleteById(item.driveId, item.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1337,7 +1320,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running uploadCreateDir()");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1383,43 +1365,34 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running uploadCreateDir() - test if path exists");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the response has a name which we can check & validate
|
// https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
|
||||||
if (hasName(response)){
|
// Do not assume case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same,
|
||||||
// https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
|
// even though some file systems (such as a POSIX-compliant file system) may consider them as different.
|
||||||
// Do not assume case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same,
|
// Note that NTFS supports POSIX semantics for case sensitivity but this is not the default behavior.
|
||||||
// even though some file systems (such as a POSIX-compliant file system) may consider them as different.
|
|
||||||
// Note that NTFS supports POSIX semantics for case sensitivity but this is not the default behavior.
|
if (response["name"].str == baseName(path)){
|
||||||
|
// OneDrive 'name' matches local path name
|
||||||
if (response["name"].str == baseName(path)){
|
log.vlog("The requested directory to create was found on OneDrive - skipping creating the directory: ", path );
|
||||||
// OneDrive 'name' matches local path name
|
// Check that this path is in the database
|
||||||
log.vlog("The requested directory to create was found on OneDrive - skipping creating the directory: ", path );
|
if (!itemdb.selectById(parent.driveId, parent.id, parent)){
|
||||||
// Check that this path is in the database
|
// parent for 'path' is NOT in the database
|
||||||
if (!itemdb.selectById(parent.driveId, parent.id, parent)){
|
log.vlog("The parent for this path is not in the local database - need to add parent to local database");
|
||||||
// parent for 'path' is NOT in the database
|
string parentPath = dirName(path);
|
||||||
log.vlog("The parent for this path is not in the local database - need to add parent to local database");
|
uploadCreateDir(parentPath);
|
||||||
string parentPath = dirName(path);
|
|
||||||
uploadCreateDir(parentPath);
|
|
||||||
} else {
|
|
||||||
// parent is in database
|
|
||||||
log.vlog("The parent for this path is in the local database - adding requested path (", path ,") to database");
|
|
||||||
auto res = onedrive.getPathDetails(path);
|
|
||||||
saveItem(res);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// They are the "same" name wise but different in case sensitivity
|
// parent is in database
|
||||||
log.error("ERROR: A local directory has the same name as another local directory.");
|
log.vlog("The parent for this path is in the local database - adding requested path (", path ,") to database");
|
||||||
log.error("ERROR: To resolve, rename this local directory: ", absolutePath(path));
|
auto res = onedrive.getPathDetails(path);
|
||||||
log.log("Skipping: ", absolutePath(path));
|
saveItem(res);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// response json is invalid
|
// They are the "same" name wise but different in case sensitivity
|
||||||
log.error("ERROR: Unable to process request due to an error with getting data from OneDrive");
|
log.error("ERROR: A local directory has the same name as another local directory.");
|
||||||
|
log.error("ERROR: To resolve, rename this local directory: ", absolutePath(path));
|
||||||
log.log("Skipping: ", absolutePath(path));
|
log.log("Skipping: ", absolutePath(path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1576,7 +1549,6 @@ final class SyncEngine
|
||||||
|
|
||||||
if (e.httpStatusCode >= 500) {
|
if (e.httpStatusCode >= 500) {
|
||||||
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
// OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error - error message already logged
|
||||||
log.vdebug("ERROR: OneDrive 'HTTP 5xx Server Side Error' when running uploadNewFile() - test if file exists");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1688,15 +1660,13 @@ final class SyncEngine
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
if (e.httpStatusCode == 412) {
|
if (e.httpStatusCode == 412) {
|
||||||
// OneDrive threw a 412 error, most likely: ETag does not match current item's value
|
// OneDrive threw a 412 error, most likely: ETag does not match current item's value
|
||||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' when attempting file time stamp update - gracefully handling error");
|
// Retry without eTag
|
||||||
|
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
||||||
string nullTag = null;
|
string nullTag = null;
|
||||||
// Retry without eTag so we dont try and match against the etag / ctag
|
|
||||||
response = onedrive.updateById(driveId, id, data, nullTag);
|
response = onedrive.updateById(driveId, id, data, nullTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasId(response)) {
|
saveItem(response);
|
||||||
saveItem(response);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveItem(JSONValue jsonItem)
|
private void saveItem(JSONValue jsonItem)
|
||||||
|
|
Loading…
Reference in a new issue