Skip to content

Commit

Permalink
Update sync.d
Browse files Browse the repository at this point in the history
* Change local directory creation to a reusable function
  • Loading branch information
abraunegg committed Feb 25, 2024
1 parent 47bce63 commit e895a11
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -1785,41 +1785,48 @@ class SyncEngine {
break;
case ItemType.dir:
case ItemType.remote:
addLogEntry("Creating local directory: " ~ newItemPath);
if (!dryRun) {
try {
// Create the new directory
addLogEntry("Requested path does not exist, creating directory structure: " ~ newItemPath, ["debug"]);
mkdirRecurse(newItemPath);
// Configure the applicable permissions for the folder
addLogEntry("Setting directory permissions for: " ~ newItemPath, ["debug"]);
newItemPath.setAttributes(appConfig.returnRequiredDirectoryPermisions());
// Update the time of the folder to match the last modified time as is provided by OneDrive
// If there are any files then downloaded into this folder, the last modified time will get
// updated by the local Operating System with the latest timestamp - as this is normal operation
// as the directory has been modified
addLogEntry("Setting directory lastModifiedDateTime for: " ~ newItemPath ~ " to " ~ to!string(newDatabaseItem.mtime), ["debug"]);
addLogEntry("Calling setTimes() for this directory: " ~ newItemPath, ["debug"]);
setTimes(newItemPath, newDatabaseItem.mtime, newDatabaseItem.mtime);
// Save the item to the database
saveItem(onedriveJSONItem);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
} else {
// we dont create the directory, but we need to track that we 'faked it'
idsFaked ~= [newDatabaseItem.driveId, newDatabaseItem.id];
// Save the item to the dry-run database
saveItem(onedriveJSONItem);
}
handleLocalDirectoryCreation(newDatabaseItem, newItemPath, onedriveJSONItem);
break;
case ItemType.unknown:
// Unknown type - we dont action or sync these items
break;
}
}

// Handle create local directory
void handleLocalDirectoryCreation(Item newDatabaseItem, string newItemPath, JSONValue onedriveJSONItem) {

// Update the logging output to be consistent
addLogEntry("Creating local directory: " ~ "./" ~ buildNormalizedPath(newItemPath));
if (!dryRun) {
try {
// Create the new directory
addLogEntry("Requested path does not exist, creating directory structure: " ~ newItemPath, ["debug"]);
mkdirRecurse(newItemPath);
// Configure the applicable permissions for the folder
addLogEntry("Setting directory permissions for: " ~ newItemPath, ["debug"]);
newItemPath.setAttributes(appConfig.returnRequiredDirectoryPermisions());
// Update the time of the folder to match the last modified time as is provided by OneDrive
// If there are any files then downloaded into this folder, the last modified time will get
// updated by the local Operating System with the latest timestamp - as this is normal operation
// as the directory has been modified
addLogEntry("Setting directory lastModifiedDateTime for: " ~ newItemPath ~ " to " ~ to!string(newDatabaseItem.mtime), ["debug"]);
addLogEntry("Calling setTimes() for this directory: " ~ newItemPath, ["debug"]);
setTimes(newItemPath, newDatabaseItem.mtime, newDatabaseItem.mtime);
// Save the item to the database
saveItem(onedriveJSONItem);
} catch (FileException e) {
// display the error message
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
}
} else {
// we dont create the directory, but we need to track that we 'faked it'
idsFaked ~= [newDatabaseItem.driveId, newDatabaseItem.id];
// Save the item to the dry-run database
saveItem(onedriveJSONItem);
}
}

// If the JSON item IS in the database, this will be an update to an existing in-sync item
void applyPotentiallyChangedItem(Item existingDatabaseItem, string existingItemPath, Item changedOneDriveItem, string changedItemPath, JSONValue onedriveJSONItem) {

Expand Down

0 comments on commit e895a11

Please sign in to comment.