Skip to content

Commit

Permalink
Update PR
Browse files Browse the repository at this point in the history
* Apply same change for --verbose
  • Loading branch information
abraunegg committed Oct 4, 2024
1 parent e767c2d commit 7f53b70
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 207 deletions.
10 changes: 6 additions & 4 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class ApplicationConfig {
// Is there a system configuration file?
if (!exists(systemConfigFilePath)) {
// 'system' configuration file does not exist
addLogEntry("No user or system config file found, using application defaults", ["verbose"]);
if (verboseLogging) {addLogEntry("No user or system config file found, using application defaults", ["verbose"]);}
applicableConfigFilePath = userConfigFilePath;
configurationInitialised = true;
} else {
Expand Down Expand Up @@ -560,11 +560,13 @@ class ApplicationConfig {

// Advise the user path that we will use for the application state data
if (canFind(applicableConfigFilePath, configDirName)) {
addLogEntry("Using 'user' configuration path for application config and state data: " ~ configDirName, ["verbose"]);
if (verboseLogging) {addLogEntry("Using 'user' configuration path for application config and state data: " ~ configDirName, ["verbose"]);}
} else {
if (canFind(applicableConfigFilePath, systemConfigDirName)) {
addLogEntry("Using 'system' configuration path for application config data: " ~ systemConfigDirName, ["verbose"]);
addLogEntry("Using 'user' configuration path for application state data: " ~ configDirName, ["verbose"]);
if (verboseLogging) {
addLogEntry("Using 'system' configuration path for application config data: " ~ systemConfigDirName, ["verbose"]);
addLogEntry("Using 'user' configuration path for application state data: " ~ configDirName, ["verbose"]);
}
}
}
}
Expand Down
38 changes: 20 additions & 18 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int main(string[] cliArgs) {
string calculatedLogDirPath = appConfig.calculateLogDirectory();
string calculatedLogFilePath;
// Initialise using the configured logging directory
addLogEntry("Using the following path to store the runtime application log: " ~ calculatedLogDirPath, ["verbose"]);
if (verboseLogging) {addLogEntry("Using the following path to store the runtime application log: " ~ calculatedLogDirPath, ["verbose"]);}
// Calculate the logfile name
if (calculatedLogDirPath != appConfig.defaultHomePath) {
// Log file is not going to the home directory
Expand Down Expand Up @@ -438,17 +438,17 @@ int main(string[] cliArgs) {
// This needs to be a separate 'if' statement, as, if this was an 'if-else' from above, if we were originally offline and using --monitor, we would never get to this point
if (online) {
// Check Application Version
addLogEntry("Checking Application Version ...", ["verbose"]);
if (verboseLogging) {addLogEntry("Checking Application Version ...", ["verbose"]);}
checkApplicationVersion();

// Initialise the OneDrive API
addLogEntry("Attempting to initialise the OneDrive API ...", ["verbose"]);
if (verboseLogging) {addLogEntry("Attempting to initialise the OneDrive API ...", ["verbose"]);}
OneDriveApi oneDriveApiInstance = new OneDriveApi(appConfig);
appConfig.apiWasInitialised = oneDriveApiInstance.initialise();

// Did the API initialise successfully?
if (appConfig.apiWasInitialised) {
addLogEntry("The OneDrive API was initialised successfully", ["verbose"]);
if (verboseLogging) {addLogEntry("The OneDrive API was initialised successfully", ["verbose"]);}

// Flag that we were able to initialise the API in the application config
oneDriveApiInstance.debugOutputConfiguredAPIItems();
Expand All @@ -457,7 +457,7 @@ int main(string[] cliArgs) {
oneDriveApiInstance = null;

// Need to configure the itemDB and syncEngineInstance for 'sync' and 'non-sync' operations
addLogEntry("Opening the item database ...", ["verbose"]);
if (verboseLogging) {addLogEntry("Opening the item database ...", ["verbose"]);}

// Configure the Item Database
itemDB = new ItemDatabase(runtimeDatabaseFile);
Expand Down Expand Up @@ -642,7 +642,7 @@ int main(string[] cliArgs) {
}

// Configure the sync directory based on the runtimeSyncDirectory configured directory
addLogEntry("All application operations will be performed in the configured local 'sync_dir' directory: " ~ runtimeSyncDirectory, ["verbose"]);
if (verboseLogging) {addLogEntry("All application operations will be performed in the configured local 'sync_dir' directory: " ~ runtimeSyncDirectory, ["verbose"]);}
// Try and set the 'sync_dir', attempt to create if it does not exist
try {
if (!exists(runtimeSyncDirectory)) {
Expand Down Expand Up @@ -746,7 +746,7 @@ int main(string[] cliArgs) {
remotePath = singleDirectoryPath;

// Display that we are syncing from a specific path due to --single-directory
addLogEntry("Syncing changes from this selected path: " ~ singleDirectoryPath, ["verbose"]);
if (verboseLogging) {addLogEntry("Syncing changes from this selected path: " ~ singleDirectoryPath, ["verbose"]);}
}

// Handle SIGINT and SIGTERM
Expand Down Expand Up @@ -808,8 +808,10 @@ int main(string[] cliArgs) {

// If we are in a --download-only method of operation, the output of these is not required
if (!appConfig.getValueBool("download_only")) {
addLogEntry("Maximum allowed open files: " ~ maxOpenFiles, ["verbose"]);
addLogEntry("Maximum allowed inotify user watches: " ~ maxInotifyWatches, ["verbose"]);
if (verboseLogging) {
addLogEntry("Maximum allowed open files: " ~ maxOpenFiles, ["verbose"]);
addLogEntry("Maximum allowed inotify user watches: " ~ maxInotifyWatches, ["verbose"]);
}
}

// Configure the monitor class
Expand All @@ -819,13 +821,13 @@ int main(string[] cliArgs) {
filesystemMonitor.onDirCreated = delegate(string path) {
// Handle .folder creation if skip_dotfiles is enabled
if ((appConfig.getValueBool("skip_dotfiles")) && (isDotFile(path))) {
addLogEntry("[M] Skipping watching local path - .folder found & --skip-dot-files enabled: " ~ path, ["verbose"]);
if (verboseLogging) {addLogEntry("[M] Skipping watching local path - .folder found & --skip-dot-files enabled: " ~ path, ["verbose"]);}
} else {
addLogEntry("[M] Local directory created: " ~ path, ["verbose"]);
if (verboseLogging) {addLogEntry("[M] Local directory created: " ~ path, ["verbose"]);}
try {
syncEngineInstance.scanLocalFilesystemPathForNewData(path);
} catch (CurlException e) {
addLogEntry("Offline, cannot create remote dir: " ~ path, ["verbose"]);
if (verboseLogging) {addLogEntry("Offline, cannot create remote dir: " ~ path, ["verbose"]);}
} catch (Exception e) {
addLogEntry("Cannot create remote directory: " ~ e.msg, ["info", "notify"]);
}
Expand All @@ -837,20 +839,20 @@ int main(string[] cliArgs) {
// Handle a potentially locally changed file
// Logging for this event moved to handleLocalFileTrigger() due to threading and false triggers from scanLocalFilesystemPathForNewData() above
syncEngineInstance.handleLocalFileTrigger(changedLocalFilesToUploadToOneDrive);
addLogEntry("[M] Total number of local file(s) added or changed: " ~ to!string(changedLocalFilesToUploadToOneDrive.length), ["verbose"]);
if (verboseLogging) {addLogEntry("[M] Total number of local file(s) added or changed: " ~ to!string(changedLocalFilesToUploadToOneDrive.length), ["verbose"]);}
};

// Delegated function for when inotify detects a delete event
filesystemMonitor.onDelete = delegate(string path) {
addLogEntry("[M] Local item deleted: " ~ path, ["verbose"]);
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");
syncEngineInstance.deleteByPath(path);
} catch (CurlException e) {
addLogEntry("Offline, cannot delete item: " ~ path, ["verbose"]);
if (verboseLogging) {addLogEntry("Offline, cannot delete item: " ~ path, ["verbose"]);}
} catch (SyncException e) {
if (e.msg == "The item to delete is not in the local database") {
addLogEntry("Item cannot be deleted from Microsoft OneDrive because it was not found in the local database", ["verbose"]);
if (verboseLogging) {addLogEntry("Item cannot be deleted from Microsoft OneDrive because it was not found in the local database", ["verbose"]);}
} else {
addLogEntry("Cannot delete remote item: " ~ e.msg, ["info", "notify"]);
}
Expand All @@ -861,7 +863,7 @@ int main(string[] cliArgs) {

// Delegated function for when inotify detects a move event
filesystemMonitor.onMove = delegate(string from, string to) {
addLogEntry("[M] Local item moved: " ~ from ~ " -> " ~ to, ["verbose"]);
if (verboseLogging) {addLogEntry("[M] Local item moved: " ~ from ~ " -> " ~ to, ["verbose"]);}
try {
// Handle .folder -> folder if skip_dotfiles is enabled
if ((appConfig.getValueBool("skip_dotfiles")) && (isDotFile(from))) {
Expand All @@ -871,7 +873,7 @@ int main(string[] cliArgs) {
syncEngineInstance.uploadMoveItem(from, to);
}
} catch (CurlException e) {
addLogEntry("Offline, cannot move item !", ["verbose"]);
if (verboseLogging) {addLogEntry("Offline, cannot move item !", ["verbose"]);}
} catch (Exception e) {
addLogEntry("Cannot move item: " ~ e.msg, ["info", "notify"]);
}
Expand Down
12 changes: 6 additions & 6 deletions src/monitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MonitorBackgroundWorker {
addLogEntry("EXAMPLE: sudo sysctl fs.inotify.max_user_watches=" ~ to!string((maxInotifyWatches * 2)));
}
if (errno() == 13) {
addLogEntry("WARNING: inotify_add_watch failed - permission denied: " ~ pathname, ["verbose"]);
if (verboseLogging) {addLogEntry("WARNING: inotify_add_watch failed - permission denied: " ~ pathname, ["verbose"]);}
}
// Flag any other errors
addLogEntry("ERROR: inotify_add_watch failed: " ~ pathname);
Expand All @@ -79,7 +79,7 @@ class MonitorBackgroundWorker {
// Do we log that we are monitoring this directory?
if (isDir(pathname)) {
// Log that this is directory is being monitored
addLogEntry("Monitoring directory: " ~ pathname, ["verbose"]);
if (verboseLogging) {addLogEntry("Monitoring directory: " ~ pathname, ["verbose"]);}
}
return wd;
}
Expand Down Expand Up @@ -339,7 +339,7 @@ final class Monitor {
private void addRecursive(string dirname) {
// skip non existing/disappeared items
if (!exists(dirname)) {
addLogEntry("Not adding non-existing/disappeared directory: " ~ dirname, ["verbose"]);
if (verboseLogging) {addLogEntry("Not adding non-existing/disappeared directory: " ~ dirname, ["verbose"]);}
return;
}

Expand Down Expand Up @@ -385,7 +385,7 @@ final class Monitor {
// Do we need to check for .nosync? Only if check_nosync is true
if (check_nosync) {
if (exists(buildNormalizedPath(dirname) ~ "/.nosync")) {
addLogEntry("Skipping watching path - .nosync found & --check-for-nosync enabled: " ~ buildNormalizedPath(dirname), ["verbose"]);
if (verboseLogging) {addLogEntry("Skipping watching path - .nosync found & --check-for-nosync enabled: " ~ buildNormalizedPath(dirname), ["verbose"]);}
return;
}
}
Expand Down Expand Up @@ -455,7 +455,7 @@ final class Monitor {
assert(wd in wdToDirName);
int ret = worker.removeInotifyWatch(wd);
if (ret < 0) throw new MonitorException("inotify_rm_watch failed");
addLogEntry("Monitored directory removed: " ~ to!string(wdToDirName[wd]), ["verbose"]);
if (verboseLogging) {addLogEntry("Monitored directory removed: " ~ to!string(wdToDirName[wd]), ["verbose"]);}
wdToDirName.remove(wd);
}

Expand All @@ -467,7 +467,7 @@ final class Monitor {
int ret = worker.removeInotifyWatch(wd);
if (ret < 0) throw new MonitorException("inotify_rm_watch failed");
wdToDirName.remove(wd);
addLogEntry("Monitored directory removed: " ~ dirname, ["verbose"]);
if (verboseLogging) {addLogEntry("Monitored directory removed: " ~ dirname, ["verbose"]);}
}
}
}
Expand Down
42 changes: 24 additions & 18 deletions src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ class OneDriveApi {
string effectiveScopes = response["scope"].str();
// Display the effective authentication scopes
addLogEntry();
addLogEntry("Effective API Authentication Scopes: " ~ effectiveScopes, ["verbose"]);
if (verboseLogging) {addLogEntry("Effective API Authentication Scopes: " ~ effectiveScopes, ["verbose"]);}

// if we have any write scopes, we need to tell the user to update an remove online prior authentication and exit application
if (canFind(effectiveScopes, "Write")) {
Expand Down Expand Up @@ -1273,14 +1273,16 @@ class OneDriveApi {
}
if (canFind(errorMessage, "Timeout was reached on handle")) {
// Common cause is libcurl trying IPv6 DNS resolution when there are only IPv4 DNS servers available
addLogEntry("A libcurl timeout has been triggered - data transfer too slow, no DNS resolution response, no server response", ["verbose"]);
// There are 3 common causes for this issue:
// 1. Usually poor DNS resolution where libcurl flip/flops to use IPv6 and is unable to resolve
// 2. A device between the user and Microsoft OneDrive is unable to correctly handle HTTP/2 communication
// 3. No Internet access from this system at this point in time
addLogEntry(" - IPv6 DNS resolution issues may be causing timeouts. Consider setting 'ip_protocol_version' to IPv4 to potentially avoid this", ["verbose"]);
addLogEntry(" - HTTP/2 compatibility issues might also be interfering with your system. Use 'force_http_11' to switch to HTTP/1.1 to potentially avoid this", ["verbose"]);
addLogEntry(" - If these options do not resolve this timeout issue, please use --debug-https to diagnose this issue further.", ["verbose"]);
if (verboseLogging) {
addLogEntry("A libcurl timeout has been triggered - data transfer too slow, no DNS resolution response, no server response", ["verbose"]);
// There are 3 common causes for this issue:
// 1. Usually poor DNS resolution where libcurl flip/flops to use IPv6 and is unable to resolve
// 2. A device between the user and Microsoft OneDrive is unable to correctly handle HTTP/2 communication
// 3. No Internet access from this system at this point in time
addLogEntry(" - IPv6 DNS resolution issues may be causing timeouts. Consider setting 'ip_protocol_version' to IPv4 to potentially avoid this", ["verbose"]);
addLogEntry(" - HTTP/2 compatibility issues might also be interfering with your system. Use 'force_http_11' to switch to HTTP/1.1 to potentially avoid this", ["verbose"]);
addLogEntry(" - If these options do not resolve this timeout issue, please use --debug-https to diagnose this issue further.", ["verbose"]);
}
}
} else {
// Some other 'libcurl' error was returned
Expand Down Expand Up @@ -1450,17 +1452,21 @@ class OneDriveApi {
}
}

// When are we re-trying the API call?
// set the current time for this thread
currentTime = Clock.currTime();
currentTime.fracSecs = Duration.zero;
auto timeString = currentTime.toString();
addLogEntry("Retry attempt: " ~ to!string(retryAttempts) ~ " - Internal Thread ID: " ~ to!string(curlEngine.internalThreadId), ["verbose"]);
addLogEntry(" This attempt timestamp: " ~ timeString, ["verbose"]);
// Detail when the next attempt will be tried
// Factor in the delay for curl to generate the exception - otherwise the next timestamp appears to be 'out' even though technically correct
auto nextRetry = currentTime + dur!"seconds"(thisBackOffInterval) + dur!"seconds"(timestampAlign);
addLogEntry(" Next retry in approx: " ~ to!string((thisBackOffInterval + timestampAlign)) ~ " seconds");
addLogEntry(" Next retry approx: " ~ to!string(nextRetry), ["verbose"]);

// If verbose logging, detail when we are re-trying the call
if (verboseLogging) {
auto timeString = currentTime.toString();
addLogEntry("Retry attempt: " ~ to!string(retryAttempts) ~ " - Internal Thread ID: " ~ to!string(curlEngine.internalThreadId), ["verbose"]);
addLogEntry(" This attempt timestamp: " ~ timeString, ["verbose"]);
// Detail when the next attempt will be tried
// Factor in the delay for curl to generate the exception - otherwise the next timestamp appears to be 'out' even though technically correct
auto nextRetry = currentTime + dur!"seconds"(thisBackOffInterval) + dur!"seconds"(timestampAlign);
addLogEntry(" Next retry in approx: " ~ to!string((thisBackOffInterval + timestampAlign)) ~ " seconds");
addLogEntry(" Next retry approx: " ~ to!string(nextRetry), ["verbose"]);
}

// Thread sleep
Thread.sleep(dur!"seconds"(thisBackOffInterval));
Expand Down
Loading

0 comments on commit 7f53b70

Please sign in to comment.