make better way to make relative paths absolute

This commit is contained in:
Elkien3 2019-01-19 12:19:43 -06:00
parent 0786b0823a
commit b930622d51

View File

@ -68,11 +68,15 @@ fn try_main() -> Result<(), String> {
for argument in std::env::args() {
if argument.contains("minetest") && !argument.contains("mumble-wrapper") && std::path::Path::new(&argument).exists() {
minetest_command = std::path::PathBuf::from(argument);
}
}
// Canonicalize the path because relative paths with Command are undefined.
minetest_command = minetest_command.canonicalize().unwrap_or_default();
// Relative paths with Command are undefined.
if minetest_command.is_relative() {
let mut absolute_path = std::env::current_dir().unwrap();
absolute_path.push(minetest_command);
minetest_command = absolute_path;
}
}
}
if !minetest_command.exists() {
// If the program args didn't provide a valid path, try the search paths.
@ -99,9 +103,6 @@ fn try_main() -> Result<(), String> {
}
}
// Canonicalize the path because relative paths with Command are undefined.
minetest_command = minetest_command.canonicalize().unwrap_or_default();
// Whoops we couldn't find it...
if !minetest_command.exists() {
return Err("Unable to find Minetest executable! Try passing its path to the command-line...".to_owned());