Correcting 'get cwd' logic
use crate::app_entry::*;
use crate::error::*;
+use failure::format_err;
use fs_extra;
use kubos_app::RunLevel;
use log::*;
@@ -572,9 +573,13 @@ impl AppRegistry {
// Change our current directory to the app's directory so that it can access any
// auxiliary files with relative file paths
- let cwd = ::std::env::current_dir()?;
- let parent_dir = app_path.parent().unwrap_or(&cwd);
- if let Err(err) = ::std::env::set_current_dir(parent_dir) {
+ if let Err(err) = app_path
+ .parent()
+ .ok_or_else(|| format_err!("Failed to get parent dir"))
+ .and_then(|parent_dir| {
+ ::std::env::set_current_dir(parent_dir).map_err(|err| err.into())
+ })
+ {
// If we can't change the current directory, we'll log an error and then just
// continue trying to execute the application
warn!("Failed to set cwd before executing {}: {:?}", app_name, err);
