Skip to content

Commit 71cddf3

Browse files
authored
Fix Bug #3567: Ensure mkdirRecurse() is correctly wrapped in try block (#3566)
* Based on an application crash output from OMV, if the client is unable to create the required path, the application crashes. Harden all calls to mkdirRecurse() by wrapping in a try block.
1 parent 0b65d07 commit 71cddf3

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

src/config.d

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,18 @@ class ApplicationConfig {
569569

570570
// Configuration directory should now have been correctly identified
571571
if (!exists(configDirName)) {
572-
// create the directory
573-
mkdirRecurse(configDirName);
574-
// Configure the applicable permissions for the folder
575-
configDirName.setAttributes(returnRequiredDirectoryPermissions());
572+
// Attempt path creation
573+
try {
574+
// create the configuration directory
575+
mkdirRecurse(configDirName);
576+
// Configure the applicable permissions for the folder
577+
configDirName.setAttributes(returnRequiredDirectoryPermissions());
578+
} catch (std.file.FileException e) {
579+
// Creating the configuration directory failed
580+
addLogEntry("ERROR: Unable to create the required application configuration directory: " ~ e.msg, ["info", "notify"]);
581+
// Use exit scopes to shutdown API
582+
return EXIT_FAILURE;
583+
}
576584
} else {
577585
// The config path exists
578586
// The path that exists must be a directory, not a file
@@ -2991,7 +2999,14 @@ class ApplicationConfig {
29912999
string bookmarksPath = buildPath(expandTilde(environment.get("HOME", "")), ".config", "gtk-3.0", "bookmarks");
29923000

29933001
// Ensure the bookmarks path exists
2994-
mkdirRecurse(dirName(bookmarksPath));
3002+
try {
3003+
// Attempt bookmarks path creation
3004+
mkdirRecurse(dirName(bookmarksPath));
3005+
} catch (std.file.FileException e) {
3006+
// Creating the bookmarks path failed
3007+
addLogEntry("ERROR: Unable to create the GNOME bookmark directory: " ~ e.msg, ["info", "notify"]);
3008+
return;
3009+
}
29953010

29963011
// Does the bookmark already exist?
29973012
string content = exists(bookmarksPath) ? readText(bookmarksPath) : "";
@@ -3118,7 +3133,14 @@ class ApplicationConfig {
31183133
string content;
31193134

31203135
// Ensure the xbelPath path exists
3121-
mkdirRecurse(dirName(xbelPath));
3136+
try {
3137+
// Attempt xbelPath creation
3138+
mkdirRecurse(dirName(xbelPath));
3139+
} catch (std.file.FileException e) {
3140+
// Creating the xbelPath path failed
3141+
addLogEntry("ERROR: Unable to create the KDE Places directory: " ~ e.msg, ["info", "notify"]);
3142+
return;
3143+
}
31223144

31233145
// Does the xbel file exist?
31243146
if (exists(xbelPath)) {

src/main.d

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,19 @@ int main(string[] cliArgs) {
910910
if (!exists(singleDirectoryPath)) {
911911
// The requested path to use with --single-directory does not exist locally within the configured 'sync_dir'
912912
addLogEntry("WARNING: The requested path for --single-directory does not exist locally. Creating requested path within " ~ runtimeSyncDirectory, ["info", "notify"]);
913-
// Make the required --single-directory path locally
914-
mkdirRecurse(singleDirectoryPath);
915-
// Configure the applicable permissions for the folder
916-
if (debugLogging) {addLogEntry("Setting directory permissions for: " ~ singleDirectoryPath, ["debug"]);}
917-
singleDirectoryPath.setAttributes(appConfig.returnRequiredDirectoryPermissions());
913+
// Attempt path creation
914+
try {
915+
// Attempt to create the required --single-directory path locally
916+
mkdirRecurse(singleDirectoryPath);
917+
// Configure the applicable permissions for the folder
918+
if (debugLogging) {addLogEntry("Setting directory permissions for: " ~ singleDirectoryPath, ["debug"]);}
919+
singleDirectoryPath.setAttributes(appConfig.returnRequiredDirectoryPermissions());
920+
} catch (std.file.FileException e) {
921+
// Creating the sync directory failed
922+
addLogEntry("ERROR: Unable to create the required --single-directory path: " ~ e.msg, ["info", "notify"]);
923+
// Use exit scopes to shutdown API
924+
return EXIT_FAILURE;
925+
}
918926
}
919927

920928
// Update the paths that we use to perform the sync actions

src/sync.d

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,17 @@ class SyncEngine {
959959
// Folder does not exist locally and needs to be created
960960
addLogEntry("Creating the OneDrive Business Shared Files Local Directory: " ~ appConfig.configuredBusinessSharedFilesDirectoryName);
961961

962-
// Local folder does not exist, thus needs to be created
963-
mkdirRecurse(appConfig.configuredBusinessSharedFilesDirectoryName);
962+
if (!dryRun) {
963+
// Local folder does not exist, thus needs to be created
964+
try {
965+
// Attempt path creation
966+
mkdirRecurse(appConfig.configuredBusinessSharedFilesDirectoryName);
967+
} catch (std.file.FileException e) {
968+
// Creating the path failed
969+
addLogEntry("ERROR: Unable to create the OneDrive Business Shared Files Local Directory: " ~ e.msg, ["info", "notify"]);
970+
}
971+
}
972+
964973
// As this will not be created online, generate a response so it can be saved to the database
965974
Item sharedFilesPath = makeItem(createFakeResponse(baseName(appConfig.configuredBusinessSharedFilesDirectoryName)));
966975

@@ -14347,8 +14356,16 @@ class SyncEngine {
1434714356
// Folder does not exist locally and needs to be created
1434814357
addLogEntry("Creating the OneDrive Business Shared File Users Local Directory: " ~ newLocalSharedFilePath);
1434914358

14350-
// Local folder does not exist, thus needs to be created
14351-
mkdirRecurse(newLocalSharedFilePath);
14359+
if (!dryRun) {
14360+
// Local folder does not exist, thus needs to be created
14361+
try {
14362+
// Attempt path creation
14363+
mkdirRecurse(newLocalSharedFilePath);
14364+
} catch (std.file.FileException e) {
14365+
// Creating the path failed
14366+
addLogEntry("ERROR: Unable to create the OneDrive Business Shared File Users Local Directory: " ~ e.msg, ["info", "notify"]);
14367+
}
14368+
}
1435214369

1435314370
// As this will not be created online, generate a response so it can be saved to the database
1435414371
sharedFilesPath = makeItem(createFakeResponse(baseName(newLocalSharedFilePath)));

0 commit comments

Comments
 (0)