Resolve 'The parent item is not in the local database' (Issue #139) (#143)

* Resolve 'The parent item is not in the local database' where data cannot be uploaded / saved to the local database because there are folders in the same path with the same name due to case sensitivity issues
This commit is contained in:
abraunegg 2018-08-27 10:47:01 +10:00 committed by GitHub
parent b9faa5cd1f
commit b2c9e041be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -216,7 +216,7 @@ final class SyncEngine
} catch (OneDriveException e) {
if (e.httpStatusCode == 404) {
// The directory was not found
log.vlog("ERROR: The requested single directory to sync was not found on OneDrive");
log.error("ERROR: The requested single directory to sync was not found on OneDrive");
return;
}
}
@ -1087,9 +1087,10 @@ final class SyncEngine
parent.id = onedrivePathDetails["id"].str; // This item's ID. Should give something like 12345ABCDE1234A1!101
}
JSONValue response;
// test if the path we are going to create already exists on OneDrive
try {
onedrive.getPathDetails(path);
response = onedrive.getPathDetails(path);
} catch (OneDriveException e) {
if (e.httpStatusCode == 404) {
// The directory was not found
@ -1103,7 +1104,6 @@ final class SyncEngine
];
// Submit the creation request
JSONValue response;
// Fix for https://github.com/skilion/onedrive/issues/356
try {
response = onedrive.createById(parent.driveId, parent.id, driveItem);
@ -1121,8 +1121,15 @@ final class SyncEngine
return;
}
}
log.vlog("The requested directory to create was found on OneDrive - skipping creating the directory: ", path );
// https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
// Do not assume case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same,
// 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
log.vlog("The requested directory to create was found on OneDrive - skipping creating the directory: ", path );
// Check that this path is in the database
if (!itemdb.selectById(parent.driveId, parent.id, parent)){
// parent for 'path' is NOT in the database
@ -1135,6 +1142,13 @@ final class SyncEngine
auto res = onedrive.getPathDetails(path);
saveItem(res);
}
} else {
// They are the "same" name wise but different in case sensitivity
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));
return;
}
}
}
@ -1143,8 +1157,8 @@ final class SyncEngine
Item 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)) {
// Maximum file size upload
// https://support.microsoft.com/en-au/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders
// 1. OneDrive Business say's 15GB
@ -1300,6 +1314,10 @@ final class SyncEngine
log.log("Skipping uploading this new file as it exceeds the maximum size allowed by OneDrive: ", path);
}
}
} else {
log.log("Skipping uploading this new file as parent path is not in the database: ", path);
return;
}
}
private void uploadDeleteItem(Item item, string path)