make better way to make relative paths absolute
This commit is contained in:
parent
0786b0823a
commit
b930622d51
15
src/main.rs
15
src/main.rs
@ -68,11 +68,15 @@ fn try_main() -> Result<(), String> {
|
|||||||
for argument in std::env::args() {
|
for argument in std::env::args() {
|
||||||
if argument.contains("minetest") && !argument.contains("mumble-wrapper") && std::path::Path::new(&argument).exists() {
|
if argument.contains("minetest") && !argument.contains("mumble-wrapper") && std::path::Path::new(&argument).exists() {
|
||||||
minetest_command = std::path::PathBuf::from(argument);
|
minetest_command = std::path::PathBuf::from(argument);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Canonicalize the path because relative paths with Command are undefined.
|
// Relative paths with Command are undefined.
|
||||||
minetest_command = minetest_command.canonicalize().unwrap_or_default();
|
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 !minetest_command.exists() {
|
||||||
// If the program args didn't provide a valid path, try the search paths.
|
// 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...
|
// Whoops we couldn't find it...
|
||||||
if !minetest_command.exists() {
|
if !minetest_command.exists() {
|
||||||
return Err("Unable to find Minetest executable! Try passing its path to the command-line...".to_owned());
|
return Err("Unable to find Minetest executable! Try passing its path to the command-line...".to_owned());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user