mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-01 13:32:16 +02:00
Update long path handling
* Update long path handling to account for differences between OneDrive Personal and OneDrive Business Accounts * Update logging to be cleaner on fragment uploads
This commit is contained in:
parent
0ca87cb92d
commit
41976ed216
|
@ -487,7 +487,7 @@ final class OneDriveApi
|
||||||
// 204 - Deleted OK
|
// 204 - Deleted OK
|
||||||
case 201,202,204:
|
case 201,202,204:
|
||||||
// No actions, but log if verbose logging
|
// No actions, but log if verbose logging
|
||||||
log.vlog("OneDrive Response: '", http.statusLine.code, " - ", http.statusLine.reason, "'");
|
//log.vlog("OneDrive Response: '", http.statusLine.code, " - ", http.statusLine.reason, "'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 400 - Bad Request
|
// 400 - Bad Request
|
||||||
|
|
36
src/sync.d
36
src/sync.d
|
@ -763,7 +763,7 @@ final class SyncEngine
|
||||||
string eTag = item.eTag;
|
string eTag = item.eTag;
|
||||||
if (!testFileHash(path, item)) {
|
if (!testFileHash(path, item)) {
|
||||||
log.vlog("The file content has changed");
|
log.vlog("The file content has changed");
|
||||||
write("Uploading file ", path, "...");
|
write("Uploading file ", path, " ...");
|
||||||
JSONValue response;
|
JSONValue response;
|
||||||
if (getSize(path) <= thresholdFileSize) {
|
if (getSize(path) <= thresholdFileSize) {
|
||||||
try {
|
try {
|
||||||
|
@ -781,8 +781,9 @@ final class SyncEngine
|
||||||
} else {
|
} else {
|
||||||
writeln("");
|
writeln("");
|
||||||
response = session.upload(path, item.driveId, item.parentId, baseName(path), eTag);
|
response = session.upload(path, item.driveId, item.parentId, baseName(path), eTag);
|
||||||
|
writeln(" done.");
|
||||||
}
|
}
|
||||||
log.fileOnly("Uploading file ", path, "... done.");
|
log.fileOnly("Uploading file ", path, " ... done.");
|
||||||
// saveItem(response); redundant
|
// saveItem(response); redundant
|
||||||
// use the cTag instead of the eTag because Onedrive may update the metadata of files AFTER they have been uploaded
|
// use the cTag instead of the eTag because Onedrive may update the metadata of files AFTER they have been uploaded
|
||||||
eTag = response["cTag"].str;
|
eTag = response["cTag"].str;
|
||||||
|
@ -805,10 +806,21 @@ final class SyncEngine
|
||||||
private void uploadNewItems(string path)
|
private void uploadNewItems(string path)
|
||||||
{
|
{
|
||||||
// https://github.com/OneDrive/onedrive-api-docs/issues/443
|
// https://github.com/OneDrive/onedrive-api-docs/issues/443
|
||||||
// If the path is greater than 430 characters, then one drive will return a '400 - Bad Request'
|
// If the path is greater than allowed characters, then one drive will return a '400 - Bad Request'
|
||||||
// Need to ensure that the URI is encoded before the check is made
|
// Need to ensure that the URI is encoded before the check is made
|
||||||
if(encodeComponent(path).length < 430){
|
// 256 Character Limit for OneDrive Business / Office 365
|
||||||
// path is less than 430 characters
|
// 430 Character Limit for OneDrive Personal
|
||||||
|
auto maxPathLength = 0;
|
||||||
|
if (accountType == "business"){
|
||||||
|
// Business Account
|
||||||
|
maxPathLength = 256;
|
||||||
|
} else {
|
||||||
|
// Personal Account
|
||||||
|
maxPathLength = 430;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(encodeComponent(path).length < maxPathLength){
|
||||||
|
// path is less than maxPathLength
|
||||||
|
|
||||||
// skip unexisting symbolic links
|
// skip unexisting symbolic links
|
||||||
if (isSymlink(path) && !exists(readLink(path))) {
|
if (isSymlink(path) && !exists(readLink(path))) {
|
||||||
|
@ -864,7 +876,7 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This path was skipped - why?
|
// This path was skipped - why?
|
||||||
log.log("Skipping item '", path, "' due to the full path exceeding 430 characters (Microsoft OneDrive limitation)");
|
log.log("Skipping item '", path, "' due to the full path exceeding ", maxPathLength, " characters (Microsoft OneDrive limitation)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -965,7 +977,7 @@ final class SyncEngine
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
if (e.httpStatusCode == 404) {
|
if (e.httpStatusCode == 404) {
|
||||||
// The file was not found on OneDrive, need to upload it
|
// The file was not found on OneDrive, need to upload it
|
||||||
write("Uploading file ", path, "...");
|
write("Uploading file ", path, " ...");
|
||||||
JSONValue response;
|
JSONValue response;
|
||||||
if (getSize(path) <= thresholdFileSize) {
|
if (getSize(path) <= thresholdFileSize) {
|
||||||
try {
|
try {
|
||||||
|
@ -979,12 +991,13 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
else throw e;
|
else throw e;
|
||||||
}
|
}
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
} else {
|
} else {
|
||||||
writeln("");
|
writeln("");
|
||||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||||
|
writeln(" done.");
|
||||||
}
|
}
|
||||||
log.fileOnly("Uploading file ", path, "... done.");
|
log.fileOnly("Uploading file ", path, " ... done.");
|
||||||
|
|
||||||
// Update the item's metadata on OneDrive
|
// Update the item's metadata on OneDrive
|
||||||
string id = response["id"].str;
|
string id = response["id"].str;
|
||||||
|
@ -1006,7 +1019,7 @@ final class SyncEngine
|
||||||
// local file is newer
|
// local file is newer
|
||||||
log.vlog("Requested file to upload is newer than existing file on OneDrive");
|
log.vlog("Requested file to upload is newer than existing file on OneDrive");
|
||||||
|
|
||||||
write("Uploading file ", path, "...");
|
write("Uploading file ", path, " ...");
|
||||||
JSONValue response;
|
JSONValue response;
|
||||||
if (getSize(path) <= thresholdFileSize) {
|
if (getSize(path) <= thresholdFileSize) {
|
||||||
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
||||||
|
@ -1014,8 +1027,9 @@ final class SyncEngine
|
||||||
} else {
|
} else {
|
||||||
writeln("");
|
writeln("");
|
||||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||||
|
writeln(" done.");
|
||||||
}
|
}
|
||||||
log.fileOnly("Uploading file ", path, "... done.");
|
log.fileOnly("Uploading file ", path, " ... done.");
|
||||||
string id = response["id"].str;
|
string id = response["id"].str;
|
||||||
string cTag = response["cTag"].str;
|
string cTag = response["cTag"].str;
|
||||||
SysTime mtime = timeLastModified(path).toUTC();
|
SysTime mtime = timeLastModified(path).toUTC();
|
||||||
|
|
Loading…
Reference in a new issue