← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1703833-catch-missing-datadir into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1703833-catch-missing-datadir into lp:widelands.

Commit message:
Exit gracefully if user specifies a datadir that doesn't exist

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1703833 in widelands: "Print console message on illegal --datadir"
  https://bugs.launchpad.net/widelands/+bug/1703833

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1703833-catch-missing-datadir/+merge/349629
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1703833-catch-missing-datadir into lp:widelands.
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc	2018-07-07 19:20:22 +0000
+++ src/wlapplication.cc	2018-07-15 09:26:31 +0000
@@ -157,7 +157,9 @@
 	// http://pubs.opengroup.org/onlinepubs/009695399/functions/realpath.html
 	char* rp = realpath(path.c_str(), buffer);
 	log("Realpath: %s\n", rp);
-	assert(rp);
+	if (!rp); {
+		throw wexception("Unable to get absolute path for %s", path.c_str());
+	}
 	return std::string(rp);
 #else
 	return path;
@@ -936,8 +938,13 @@
 		              get_executable_directory() + FileSystem::file_separator() + INSTALL_DATADIR;
 	}
 	if (!is_absolute_path(datadir_)) {
-		datadir_ = absolute_path_if_not_windows(FileSystem::get_working_directory() +
-		                                        FileSystem::file_separator() + datadir_);
+		try {
+			datadir_ = absolute_path_if_not_windows(FileSystem::get_working_directory() +
+													FileSystem::file_separator() + datadir_);
+		} catch (const WException& e) {
+			log("Error parsing datadir: %s\n", e.what());
+			exit(1);
+		}
 	}
 	if (commandline_.count("datadir_for_testing")) {
 		datadir_for_testing_ = commandline_["datadir_for_testing"];


Follow ups