mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-01 13:32:16 +02:00
Fix Business Shared Folder handling to process only Business Shared Folders (#1104)
* Update Business Shared Folder handling to process only Shared Folders, not individually shared files
This commit is contained in:
parent
9ca2f6ae26
commit
fe86dd1809
211
src/sync.d
211
src/sync.d
|
@ -598,111 +598,134 @@ final class SyncEngine
|
||||||
if (graphQuery.type() == JSONType.object) {
|
if (graphQuery.type() == JSONType.object) {
|
||||||
string sharedFolderName;
|
string sharedFolderName;
|
||||||
foreach (searchResult; graphQuery["value"].array) {
|
foreach (searchResult; graphQuery["value"].array) {
|
||||||
sharedFolderName = searchResult["name"].str;
|
// Configure additional logging items for this array element
|
||||||
// Compare this to values in business_shared_folders
|
string sharedByName;
|
||||||
if(selectiveSync.isSharedFolderMatched(sharedFolderName)){
|
string sharedByEmail;
|
||||||
// Folder name matches what we are looking for
|
// Extra details for verbose logging
|
||||||
// Flags for matching
|
if ("sharedBy" in searchResult["remoteItem"]["shared"]) {
|
||||||
bool itemInDatabase = false;
|
if ("displayName" in searchResult["remoteItem"]["shared"]["sharedBy"]["user"]) {
|
||||||
bool itemLocalDirExists = false;
|
sharedByName = searchResult["remoteItem"]["shared"]["sharedBy"]["user"]["displayName"].str;
|
||||||
bool itemPathIsLocal = false;
|
}
|
||||||
|
if ("email" in searchResult["remoteItem"]["shared"]["sharedBy"]["user"]) {
|
||||||
// "what if" there are 2 or more folders shared with me have the "same" name?
|
sharedByEmail = searchResult["remoteItem"]["shared"]["sharedBy"]["user"]["email"].str;
|
||||||
// The folder name will be the same, but driveId will be different
|
}
|
||||||
// This will then cause these 'shared folders' to cross populate data, which may not be desirable
|
}
|
||||||
log.vdebug("Shared Folder Name: ", sharedFolderName);
|
|
||||||
log.vdebug("Parent Drive Id: ", searchResult["remoteItem"]["parentReference"]["driveId"].str);
|
// is the shared item with us a 'folder' ?
|
||||||
log.vdebug("Shared Item Id: ", searchResult["remoteItem"]["id"].str);
|
if (isItemFolder(searchResult)) {
|
||||||
Item databaseItem;
|
// item returned is a shared folder, not a shared file
|
||||||
|
sharedFolderName = searchResult["name"].str;
|
||||||
// for each driveid in the existing driveIDsArray
|
// Compare this to values in business_shared_folders
|
||||||
foreach (searchDriveId; driveIDsArray) {
|
if(selectiveSync.isSharedFolderMatched(sharedFolderName)){
|
||||||
log.vdebug("searching database for: ", searchDriveId, " ", sharedFolderName);
|
// Folder name matches what we are looking for
|
||||||
if (itemdb.selectByPath(sharedFolderName, searchDriveId, databaseItem)) {
|
// Flags for matching
|
||||||
log.vdebug("Found shared folder name in database");
|
bool itemInDatabase = false;
|
||||||
itemInDatabase = true;
|
bool itemLocalDirExists = false;
|
||||||
log.vdebug("databaseItem: ", databaseItem);
|
bool itemPathIsLocal = false;
|
||||||
// Does the databaseItem.driveId == defaultDriveId?
|
|
||||||
if (databaseItem.driveId == defaultDriveId) {
|
// "what if" there are 2 or more folders shared with me have the "same" name?
|
||||||
itemPathIsLocal = true;
|
// The folder name will be the same, but driveId will be different
|
||||||
}
|
// This will then cause these 'shared folders' to cross populate data, which may not be desirable
|
||||||
} else {
|
log.vdebug("Shared Folder Name: ", sharedFolderName);
|
||||||
log.vdebug("Shared folder name not found in database");
|
log.vdebug("Parent Drive Id: ", searchResult["remoteItem"]["parentReference"]["driveId"].str);
|
||||||
// "what if" there is 'already' a local folder with this name
|
log.vdebug("Shared Item Id: ", searchResult["remoteItem"]["id"].str);
|
||||||
// Check if in the database
|
Item databaseItem;
|
||||||
// If NOT in the database, but resides on disk, this could be a new local folder created after last sync but before this one
|
|
||||||
// However we sync 'shared folders' before checking for local changes
|
// for each driveid in the existing driveIDsArray
|
||||||
string localpath = expandTilde(cfg.getValueString("sync_dir")) ~ "/" ~ sharedFolderName;
|
foreach (searchDriveId; driveIDsArray) {
|
||||||
if (exists(localpath)) {
|
log.vdebug("searching database for: ", searchDriveId, " ", sharedFolderName);
|
||||||
// local path exists
|
if (itemdb.selectByPath(sharedFolderName, searchDriveId, databaseItem)) {
|
||||||
log.vdebug("Found shared folder name in local OneDrive sync_dir");
|
log.vdebug("Found shared folder name in database");
|
||||||
itemLocalDirExists = true;
|
itemInDatabase = true;
|
||||||
|
log.vdebug("databaseItem: ", databaseItem);
|
||||||
|
// Does the databaseItem.driveId == defaultDriveId?
|
||||||
|
if (databaseItem.driveId == defaultDriveId) {
|
||||||
|
itemPathIsLocal = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.vdebug("Shared folder name not found in database");
|
||||||
|
// "what if" there is 'already' a local folder with this name
|
||||||
|
// Check if in the database
|
||||||
|
// If NOT in the database, but resides on disk, this could be a new local folder created after last sync but before this one
|
||||||
|
// However we sync 'shared folders' before checking for local changes
|
||||||
|
string localpath = expandTilde(cfg.getValueString("sync_dir")) ~ "/" ~ sharedFolderName;
|
||||||
|
if (exists(localpath)) {
|
||||||
|
// local path exists
|
||||||
|
log.vdebug("Found shared folder name in local OneDrive sync_dir");
|
||||||
|
itemLocalDirExists = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Shared Folder Evaluation Debugging
|
||||||
// Shared Folder Evaluation Debugging
|
log.vdebug("item in database: ", itemInDatabase);
|
||||||
log.vdebug("item in database: ", itemInDatabase);
|
log.vdebug("path exists on disk: ", itemLocalDirExists);
|
||||||
log.vdebug("path exists on disk: ", itemLocalDirExists);
|
log.vdebug("database drive id matches defaultDriveId: ", itemPathIsLocal);
|
||||||
log.vdebug("database drive id matches defaultDriveId: ", itemPathIsLocal);
|
log.vdebug("database data matches search data: ", ((databaseItem.driveId == searchResult["remoteItem"]["parentReference"]["driveId"].str) && (databaseItem.id == searchResult["remoteItem"]["id"].str)));
|
||||||
log.vdebug("database data matches search data: ", ((databaseItem.driveId == searchResult["remoteItem"]["parentReference"]["driveId"].str) && (databaseItem.id == searchResult["remoteItem"]["id"].str)));
|
|
||||||
|
if ( ((!itemInDatabase) || (!itemLocalDirExists)) || (((databaseItem.driveId == searchResult["remoteItem"]["parentReference"]["driveId"].str) && (databaseItem.id == searchResult["remoteItem"]["id"].str)) && (!itemPathIsLocal)) ) {
|
||||||
// Additional logging
|
// This shared folder does not exist in the database
|
||||||
string sharedByName;
|
if (!cfg.getValueBool("monitor")) {
|
||||||
string sharedByEmail;
|
log.log("Syncing this OneDrive Business Shared Folder: ", sharedFolderName);
|
||||||
|
} else {
|
||||||
// Extra details for verbose logging
|
log.vlog("Syncing this OneDrive Business Shared Folder: ", sharedFolderName);
|
||||||
if ("sharedBy" in searchResult["remoteItem"]["shared"]) {
|
}
|
||||||
if ("displayName" in searchResult["remoteItem"]["shared"]["sharedBy"]["user"]) {
|
Item businessSharedFolder = makeItem(searchResult);
|
||||||
sharedByName = searchResult["remoteItem"]["shared"]["sharedBy"]["user"]["displayName"].str;
|
|
||||||
}
|
// Log who shared this to assist with sync data correlation
|
||||||
if ("email" in searchResult["remoteItem"]["shared"]["sharedBy"]["user"]) {
|
if ((sharedByName != "") && (sharedByEmail != "")) {
|
||||||
sharedByEmail = searchResult["remoteItem"]["shared"]["sharedBy"]["user"]["email"].str;
|
log.vlog("OneDrive Business Shared Folder - Shared By: ", sharedByName, " (", sharedByEmail, ")");
|
||||||
}
|
} else {
|
||||||
}
|
if (sharedByName != "") {
|
||||||
|
log.vlog("OneDrive Business Shared Folder - Shared By: ", sharedByName);
|
||||||
if ( ((!itemInDatabase) || (!itemLocalDirExists)) || (((databaseItem.driveId == searchResult["remoteItem"]["parentReference"]["driveId"].str) && (databaseItem.id == searchResult["remoteItem"]["id"].str)) && (!itemPathIsLocal)) ) {
|
}
|
||||||
// This shared folder does not exist in the database
|
}
|
||||||
if (!cfg.getValueBool("monitor")) {
|
|
||||||
log.log("Syncing this OneDrive Business Shared Folder: ", sharedFolderName);
|
// Do the actual sync
|
||||||
|
applyDifferences(businessSharedFolder.remoteDriveId, businessSharedFolder.remoteId, performFullItemScan);
|
||||||
|
// add this parent drive id to the array to search for, ready for next use
|
||||||
|
string newDriveID = searchResult["remoteItem"]["parentReference"]["driveId"].str;
|
||||||
|
// Keep the driveIDsArray with unique entries only
|
||||||
|
if (!canFind(driveIDsArray, newDriveID)) {
|
||||||
|
// Add this drive id to the array to search with
|
||||||
|
driveIDsArray ~= newDriveID;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.vlog("Syncing this OneDrive Business Shared Folder: ", sharedFolderName);
|
// Shared Folder Name Conflict ...
|
||||||
}
|
log.log("WARNING: Skipping shared folder due to existing name conflict: ", sharedFolderName);
|
||||||
Item businessSharedFolder = makeItem(searchResult);
|
log.log("WARNING: Skipping changes of Path ID: ", searchResult["remoteItem"]["id"].str);
|
||||||
|
log.log("WARNING: To sync this shared folder, this shared folder needs to be renamed");
|
||||||
|
|
||||||
|
// Log who shared this to assist with conflict resolution
|
||||||
|
if ((sharedByName != "") && (sharedByEmail != "")) {
|
||||||
|
log.vlog("WARNING: Conflict Shared By: ", sharedByName, " (", sharedByEmail, ")");
|
||||||
|
} else {
|
||||||
|
if (sharedByName != "") {
|
||||||
|
log.vlog("WARNING: Conflict Shared By: ", sharedByName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// not a folder, is this a file?
|
||||||
|
if (isItemFile(searchResult)) {
|
||||||
|
// shared item is a file
|
||||||
|
string sharedFileName = searchResult["name"].str;
|
||||||
|
// log that this is not supported
|
||||||
|
log.vlog("WARNING: Not syncing this OneDrive Business Shared File: ", sharedFileName);
|
||||||
|
|
||||||
// Log who shared this to assist with sync data correlation
|
// Log who shared this to assist with sync data correlation
|
||||||
if ((sharedByName != "") && (sharedByEmail != "")) {
|
if ((sharedByName != "") && (sharedByEmail != "")) {
|
||||||
log.vlog("OneDrive Business Shared Folder - Shared By: ", sharedByName, " (", sharedByEmail, ")");
|
log.vlog("OneDrive Business Shared File - Shared By: ", sharedByName, " (", sharedByEmail, ")");
|
||||||
} else {
|
} else {
|
||||||
if (sharedByName != "") {
|
if (sharedByName != "") {
|
||||||
log.vlog("OneDrive Business Shared Folder - Shared By: ", sharedByName);
|
log.vlog("OneDrive Business Shared File - Shared By: ", sharedByName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the actual sync
|
|
||||||
applyDifferences(businessSharedFolder.remoteDriveId, businessSharedFolder.remoteId, performFullItemScan);
|
|
||||||
// add this parent drive id to the array to search for, ready for next use
|
|
||||||
string newDriveID = searchResult["remoteItem"]["parentReference"]["driveId"].str;
|
|
||||||
// Keep the driveIDsArray with unique entries only
|
|
||||||
if (!canFind(driveIDsArray, newDriveID)) {
|
|
||||||
// Add this drive id to the array to search with
|
|
||||||
driveIDsArray ~= newDriveID;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Shared Folder Name Conflict ...
|
// something else entirely
|
||||||
log.log("WARNING: Skipping shared folder due to existing name conflict: ", sharedFolderName);
|
log.log("WARNING: Not syncing this OneDrive Business Shared item: ", searchResult["name"].str);
|
||||||
log.log("WARNING: Skipping changes of Path ID: ", searchResult["remoteItem"]["id"].str);
|
}
|
||||||
log.log("WARNING: To sync this shared folder, this shared folder needs to be renamed");
|
|
||||||
|
|
||||||
// Log who shared this to assist with conflict resolution
|
|
||||||
if ((sharedByName != "") && (sharedByEmail != "")) {
|
|
||||||
log.vlog("WARNING: Conflict Shared By: ", sharedByName, " (", sharedByEmail, ")");
|
|
||||||
} else {
|
|
||||||
if (sharedByName != "") {
|
|
||||||
log.vlog("WARNING: Conflict Shared By: ", sharedByName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue