Skip to content

Conversation

@Buckram123
Copy link
Contributor

@Buckram123 Buckram123 commented Feb 21, 2024

Fixes ORC-79.
Default state_file have absolute path, instead of relative. But we only create ~/.cw-orchestrator dir if path is relative:

pub fn state_file_path() -> Result<String, DaemonError> {
// check if STATE_FILE en var is configured, default to state.json
let env_file_path = CwOrchEnvVars::load()?.state_file;
let state_file_path = if env_file_path.is_relative() {
// If it's relative, we check if it start with "."
let first_path_component = env_file_path
.components()
.map(|comp| comp.as_os_str().to_owned().into_string().unwrap())
.next();
if first_path_component == Some(".".to_string()) {
let current_dir = std::env::current_dir()?;
let actual_relative_path = env_file_path.strip_prefix("./")?;
current_dir.join(actual_relative_path)
} else if first_path_component == Some("..".to_string()) {
let current_dir = std::env::current_dir()?;
current_dir.join(env_file_path)
} else {
let state_folder = default_state_folder()?;
// We need to create the default state folder if it doesn't exist
std::fs::create_dir_all(state_folder.clone())?;
state_folder.join(env_file_path)
}
} else {
env_file_path
}
.into_os_string()
.into_string()
.unwrap();
Ok(state_file_path)
}

This was tested with on AbstractSDK/carrot-app#19

@codecov
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0f57bf0) 66.1% compared to head (55b26d2) 66.1%.

Additional details and impacted files
Files Coverage Δ
packages/cw-orch-core/src/env.rs 84.0% <100.0%> (ø)

@CyberHoward CyberHoward merged commit 82d9c57 into main Feb 21, 2024
@CyberHoward CyberHoward deleted the misha/orc-79-fix-cw-orch-crashing-when-theres-no-state-file branch February 21, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants