Skip to content

Commit

Permalink
Merge branch 'master' into install-doc-openbsd-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
abraunegg authored Dec 16, 2024
2 parents cf9102b + 71a71da commit 4660476
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ int main(string[] cliArgs) {
filesystemMonitor.onDelete = delegate(string path) {
if (verboseLogging) {addLogEntry("[M] Local item deleted: " ~ path, ["verbose"]);}
try {
addLogEntry("The operating system sent a deletion notification. Trying to delete the item as requested");
// The path has been deleted .. we cannot use isDir or isFile to advise what was deleted. This is the best we can Do
addLogEntry("The operating system sent a deletion notification. Trying to delete this item as requested: " ~ path);
// perform the delete action
syncEngineInstance.deleteByPath(path);
} catch (CurlException e) {
if (verboseLogging) {addLogEntry("Offline, cannot delete item: " ~ path, ["verbose"]);}
Expand Down
14 changes: 14 additions & 0 deletions src/monitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ final class Monitor {
} else if (event.mask & IN_CREATE) {
if (debugLogging) {addLogEntry("event IN_CREATE: " ~ path, ["debug"]);}
if (event.mask & IN_ISDIR) {
// fix from #2586
auto cookieToPath1 = cookieToPath.dup();
foreach (cookie, path1; cookieToPath1) {
if (path1 == path) {
cookieToPath.remove(cookie);
}
}
addRecursive(path);
if (useCallbacks) actionHolder.append(ActionType.createDir, path);
}
Expand All @@ -622,6 +629,13 @@ final class Monitor {
}
} else if ((event.mask & IN_CLOSE_WRITE) && !(event.mask & IN_ISDIR)) {
if (debugLogging) {addLogEntry("event IN_CLOSE_WRITE and not IN_ISDIR: " ~ path, ["debug"]);}
// fix from #2586
auto cookieToPath1 = cookieToPath.dup();
foreach (cookie, path1; cookieToPath1) {
if (path1 == path) {
cookieToPath.remove(cookie);
}
}
if (useCallbacks) actionHolder.append(ActionType.changed, path);
} else {
addLogEntry("inotify event unhandled: " ~ path);
Expand Down
51 changes: 36 additions & 15 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,7 @@ class SyncEngine {
// Personal Account Handling
if (debugLogging) {addLogEntry("Handling a Personal Shared Item JSON object", ["debug"]);}

// Does the JSON have a shared element structure
if (hasSharedElement(onedriveJSONItem)) {
// Has the Shared JSON structure
if (debugLogging) {addLogEntry("Personal Shared Item JSON object has the 'shared' JSON structure", ["debug"]);}
Expand All @@ -1699,11 +1700,13 @@ class SyncEngine {
}

// Ensure that this item has no parent
if (debugLogging) {addLogEntry("Setting remoteItem.parentId to be null", ["debug"]);}
if (debugLogging) {addLogEntry("Setting remoteItem.parentId of Personal Shared Item JSON object to be null", ["debug"]);}
remoteItem.parentId = null;
// Add this record to the local database
if (debugLogging) {addLogEntry("Update/Insert local database with remoteItem details with remoteItem.parentId as null: " ~ to!string(remoteItem), ["debug"]);}
if (debugLogging) {addLogEntry("Update/Insert local database with Personal Shared Item JSON object with remoteItem.parentId as null: " ~ to!string(remoteItem), ["debug"]);}
itemDB.upsert(remoteItem);
// Due to OneDrive API inconsistency, again with European Data Centres, as we have handled this JSON - flag as unwanted as processing is complete for this JSON item
unwanted = true;
} else {
// Business or SharePoint Account Handling
if (debugLogging) {addLogEntry("Handling a Business or SharePoint Shared Item JSON object", ["debug"]);}
Expand Down Expand Up @@ -2041,7 +2044,7 @@ class SyncEngine {
// We know if this JSON item is unwanted or not
if (unwanted) {
// This JSON item is NOT wanted - it is excluded
if (debugLogging) {addLogEntry("Skipping OneDrive change as this is determined to be unwanted", ["debug"]);}
if (debugLogging) {addLogEntry("Skipping OneDrive change as this is determined to be unwanted either through Client Side Filtering Rules or prior processing to this point", ["debug"]);}

// Add to the skippedItems array, but only if it is a directory ... pointless adding 'files' here, as it is the 'id' we check as the parent path which can only be a directory
if (!isItemFile(onedriveJSONItem)) {
Expand Down Expand Up @@ -3967,7 +3970,7 @@ class SyncEngine {
// - skip_size
// Return a true|false response

// Use the JSON elements rather can computing a DB struct via makeItem()
// Use the JSON elements rather than computing a DB struct via makeItem()
string thisItemId = onedriveJSONItem["id"].str;
string thisItemDriveId = onedriveJSONItem["parentReference"]["driveId"].str;
string thisItemParentId = onedriveJSONItem["parentReference"]["id"].str;
Expand Down Expand Up @@ -4315,9 +4318,11 @@ class SyncEngine {
// Is the parent item in the database?
if (!parentInDatabase) {
// Parental database structure needs to be created
if (verboseLogging) {addLogEntry("Parental Path structure needs to be created to support included file: " ~ dirName(newItemPath), ["verbose"]);}
// Recursively, stepping backward from 'thisItemParentId', query online, save entry to DB
createLocalPathStructure(onedriveJSONItem);
string newParentalPath = dirName(newItemPath);
// Log that this parental structure needs to be created
if (verboseLogging) {addLogEntry("Parental Path structure needs to be created to support included file: " ~ newParentalPath, ["verbose"]);}
// Recursively, stepping backward from 'thisItemParentId', query online, save entry to DB and create the local path structure
createLocalPathStructure(onedriveJSONItem, newParentalPath);

// If this is --dry-run
if (dryRun) {
Expand Down Expand Up @@ -4349,8 +4354,8 @@ class SyncEngine {
return clientSideRuleExcludesPath;
}

// When using 'sync_list' if a file is to be included, ensure that the path that the file resides in, is available locally and in the database
void createLocalPathStructure(JSONValue onedriveJSONItem) {
// When using 'sync_list' if a file is to be included, ensure that the path that the file resides in, is available locally and in the database, and the path exists locally
void createLocalPathStructure(JSONValue onedriveJSONItem, string newLocalParentalPath) {

// Function variables
bool parentInDatabase;
Expand All @@ -4362,7 +4367,10 @@ class SyncEngine {
string thisItemParentId;

// Log what we received to analyse
if (debugLogging) {addLogEntry("createLocalPathStructure input onedriveJSONItem: " ~ to!string(onedriveJSONItem), ["debug"]);}
if (debugLogging) {
addLogEntry("createLocalPathStructure input onedriveJSONItem: " ~ to!string(onedriveJSONItem), ["debug"]);
addLogEntry("createLocalPathStructure input newLocalParentalPath: " ~ newLocalParentalPath, ["debug"]);
}

// Configure these variables based on the JSON input
thisItemDriveId = onedriveJSONItem["parentReference"]["driveId"].str;
Expand All @@ -4380,7 +4388,8 @@ class SyncEngine {

// Is the parent in the database?
if (!parentInDatabase) {
// Get data from online for this driveId and itemId
// Get data from online for this driveId and JSON item parent .. so we have the parent details
if (debugLogging) {addLogEntry("createLocalPathStructure parent is not in database, fetching parental details from online", ["debug"]);}
try {
onlinePathData = onlinePathOneDriveApiInstance.getPathDetailsById(thisItemDriveId, thisItemParentId);
} catch (OneDriveException exception) {
Expand All @@ -4392,6 +4401,7 @@ class SyncEngine {
// Does this JSON match the root name of a shared folder we may be trying to match?
if (sharedFolderDeltaGeneration) {
if (currentSharedFolderName == onlinePathData["name"].str) {
if (debugLogging) {addLogEntry("createLocalPathStructure parent matches a shared folder, creating database root tie record", ["debug"]);}
createDatabaseRootTieRecordForOnlineSharedFolder(onlinePathData);
}
}
Expand All @@ -4413,7 +4423,7 @@ class SyncEngine {
// Is this item's grandparent data in the database?
if (!itemDB.idInLocalDatabase(grandparentItemDriveId, grandparentItemParentId)) {
// grandparent needs to be added
createLocalPathStructure(onlinePathData);
createLocalPathStructure(onlinePathData, dirName(newLocalParentalPath));
}

// If this is --dry-run
Expand All @@ -4422,9 +4432,20 @@ class SyncEngine {
idsFaked ~= [onlinePathData["parentReference"]["driveId"].str, onlinePathData["parentReference"]["id"].str];
}

// Save JSON to database
saveItem(onlinePathData);
}
// Does the parental path exist locally?
if (!exists(newLocalParentalPath)) {
// the required path does not exist locally - logging is done in handleLocalDirectoryCreation
// create a db item record for the online data
Item newDatabaseItem = makeItem(onlinePathData);
// create the path locally, save the data to the database post path creation
handleLocalDirectoryCreation(newDatabaseItem, newLocalParentalPath, onlinePathData);
} else {
// parent path exists locally, save the data to the database
saveItem(onlinePathData);
}
} else {
if (debugLogging) {addLogEntry("createLocalPathStructure parent is in the database", ["debug"]);}
}
}

// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
Expand Down

0 comments on commit 4660476

Please sign in to comment.