mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-23 08:02:16 +02:00
* Deal with disappearing items during upload (Issue: #258)
This commit is contained in:
parent
06aa42f6d1
commit
87cd18379d
|
@ -66,6 +66,12 @@ final class Monitor
|
||||||
|
|
||||||
private void addRecursive(string dirname)
|
private void addRecursive(string dirname)
|
||||||
{
|
{
|
||||||
|
// skip non existing/disappeared items
|
||||||
|
if (!exists(dirname)) {
|
||||||
|
log.vlog("Not adding non-existing/disappeared directory: ", dirname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// skip filtered items
|
// skip filtered items
|
||||||
if (dirname != ".") {
|
if (dirname != ".") {
|
||||||
if (selectiveSync.isNameExcluded(baseName(dirname))) {
|
if (selectiveSync.isNameExcluded(baseName(dirname))) {
|
||||||
|
|
50
src/sync.d
50
src/sync.d
|
@ -1238,6 +1238,12 @@ final class SyncEngine
|
||||||
uploadCreateDir(path);
|
uploadCreateDir(path);
|
||||||
}
|
}
|
||||||
// recursively traverse children
|
// recursively traverse children
|
||||||
|
// the above operation takes time and the directory might have
|
||||||
|
// disappeared in the meantime
|
||||||
|
if (!exists(path)) {
|
||||||
|
log.vlog("Directory disappeared during upload: ", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto entries = dirEntries(path, SpanMode.shallow, false);
|
auto entries = dirEntries(path, SpanMode.shallow, false);
|
||||||
foreach (DirEntry entry; entries) {
|
foreach (DirEntry entry; entries) {
|
||||||
uploadNewItems(entry.name);
|
uploadNewItems(entry.name);
|
||||||
|
@ -1369,7 +1375,6 @@ final class SyncEngine
|
||||||
private void uploadNewFile(string path)
|
private void uploadNewFile(string path)
|
||||||
{
|
{
|
||||||
Item parent;
|
Item parent;
|
||||||
|
|
||||||
// Check the database for the parent
|
// Check the database for the parent
|
||||||
//enforce(itemdb.selectByPath(dirName(path), defaultDriveId, parent), "The parent item is not in the local database");
|
//enforce(itemdb.selectByPath(dirName(path), defaultDriveId, parent), "The parent item is not in the local database");
|
||||||
if (itemdb.selectByPath(dirName(path), defaultDriveId, parent)) {
|
if (itemdb.selectByPath(dirName(path), defaultDriveId, parent)) {
|
||||||
|
@ -1423,23 +1428,23 @@ final class SyncEngine
|
||||||
// check what 'account type' this is as this issue only affects OneDrive Business so we need some extra logic here
|
// check what 'account type' this is as this issue only affects OneDrive Business so we need some extra logic here
|
||||||
if (accountType == "personal"){
|
if (accountType == "personal"){
|
||||||
// Original file upload logic
|
// Original file upload logic
|
||||||
if (getSize(path) <= thresholdFileSize) {
|
if (thisFileSize <= thresholdFileSize) {
|
||||||
try {
|
try {
|
||||||
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
if (e.httpStatusCode == 504) {
|
if (e.httpStatusCode == 504) {
|
||||||
// HTTP request returned status code 504 (Gateway Timeout)
|
// HTTP request returned status code 504 (Gateway Timeout)
|
||||||
// Try upload as a session
|
// Try upload as a session
|
||||||
try {
|
try {
|
||||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
// error uploading file
|
// error uploading file
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else throw e;
|
|
||||||
}
|
}
|
||||||
writeln(" done.");
|
else throw e;
|
||||||
|
}
|
||||||
|
writeln(" done.");
|
||||||
} else {
|
} else {
|
||||||
// File larger than threshold - use a session to upload
|
// File larger than threshold - use a session to upload
|
||||||
writeln("");
|
writeln("");
|
||||||
|
@ -1448,6 +1453,10 @@ final class SyncEngine
|
||||||
writeln(" done.");
|
writeln(" done.");
|
||||||
} catch (OneDriveException e) {
|
} catch (OneDriveException e) {
|
||||||
// error uploading file
|
// error uploading file
|
||||||
|
log.vlog("Upload failed with OneDriveException: ", e.msg);
|
||||||
|
return;
|
||||||
|
} catch (FileException e) {
|
||||||
|
log.vlog("Upload failed with File Exception: ", e.msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1493,9 +1502,14 @@ final class SyncEngine
|
||||||
// Update the item's metadata on OneDrive
|
// Update the item's metadata on OneDrive
|
||||||
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();
|
if (exists(path)) {
|
||||||
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded
|
SysTime mtime = timeLastModified(path).toUTC();
|
||||||
uploadLastModifiedTime(parent.driveId, id, cTag, mtime);
|
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded
|
||||||
|
uploadLastModifiedTime(parent.driveId, id, cTag, mtime);
|
||||||
|
} else {
|
||||||
|
// will be removed in different event!
|
||||||
|
log.log("File disappeared after upload: ", path);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// OneDrive Business Account - always use a session to upload
|
// OneDrive Business Account - always use a session to upload
|
||||||
|
|
Loading…
Reference in a new issue