mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-12 02:36:39 +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)
|
||||
{
|
||||
// skip non existing/disappeared items
|
||||
if (!exists(dirname)) {
|
||||
log.vlog("Not adding non-existing/disappeared directory: ", dirname);
|
||||
return;
|
||||
}
|
||||
|
||||
// skip filtered items
|
||||
if (dirname != ".") {
|
||||
if (selectiveSync.isNameExcluded(baseName(dirname))) {
|
||||
|
|
50
src/sync.d
50
src/sync.d
|
@ -1238,6 +1238,12 @@ final class SyncEngine
|
|||
uploadCreateDir(path);
|
||||
}
|
||||
// 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);
|
||||
foreach (DirEntry entry; entries) {
|
||||
uploadNewItems(entry.name);
|
||||
|
@ -1369,7 +1375,6 @@ final class SyncEngine
|
|||
private void uploadNewFile(string path)
|
||||
{
|
||||
Item parent;
|
||||
|
||||
// Check the database for the parent
|
||||
//enforce(itemdb.selectByPath(dirName(path), defaultDriveId, parent), "The parent item is not in the local database");
|
||||
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
|
||||
if (accountType == "personal"){
|
||||
// Original file upload logic
|
||||
if (getSize(path) <= thresholdFileSize) {
|
||||
if (thisFileSize <= thresholdFileSize) {
|
||||
try {
|
||||
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
||||
} catch (OneDriveException e) {
|
||||
if (e.httpStatusCode == 504) {
|
||||
// HTTP request returned status code 504 (Gateway Timeout)
|
||||
// Try upload as a session
|
||||
try {
|
||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||
} catch (OneDriveException e) {
|
||||
// error uploading file
|
||||
return;
|
||||
}
|
||||
response = onedrive.simpleUpload(path, parent.driveId, parent.id, baseName(path));
|
||||
} catch (OneDriveException e) {
|
||||
if (e.httpStatusCode == 504) {
|
||||
// HTTP request returned status code 504 (Gateway Timeout)
|
||||
// Try upload as a session
|
||||
try {
|
||||
response = session.upload(path, parent.driveId, parent.id, baseName(path));
|
||||
} catch (OneDriveException e) {
|
||||
// error uploading file
|
||||
return;
|
||||
}
|
||||
else throw e;
|
||||
}
|
||||
writeln(" done.");
|
||||
else throw e;
|
||||
}
|
||||
writeln(" done.");
|
||||
} else {
|
||||
// File larger than threshold - use a session to upload
|
||||
writeln("");
|
||||
|
@ -1448,6 +1453,10 @@ final class SyncEngine
|
|||
writeln(" done.");
|
||||
} catch (OneDriveException e) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -1493,9 +1502,14 @@ final class SyncEngine
|
|||
// Update the item's metadata on OneDrive
|
||||
string id = response["id"].str;
|
||||
string cTag = response["cTag"].str;
|
||||
SysTime mtime = timeLastModified(path).toUTC();
|
||||
// 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);
|
||||
if (exists(path)) {
|
||||
SysTime mtime = timeLastModified(path).toUTC();
|
||||
// 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;
|
||||
} else {
|
||||
// OneDrive Business Account - always use a session to upload
|
||||
|
|
Loading…
Reference in a new issue