Skip to content

Commit

Permalink
Create working dir if it does not exist
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
  • Loading branch information
rylev committed Aug 14, 2023
1 parent 5d2d037 commit eedbe8d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/commands/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ impl UpCommand {
}
}

let working_dir_holder = match &self.tmp {
None => WorkingDirectory::Temporary(tempfile::tempdir()?),
Some(d) => WorkingDirectory::Given(d.to_owned()),
};
let working_dir = working_dir_holder.path().canonicalize()?;
let working_dir = self.get_canonical_working_dir()?;

let mut locked_app = match &app_source {
AppSource::None => bail!("Internal error - should have shown help"),
Expand Down Expand Up @@ -157,6 +153,22 @@ impl UpCommand {
self.run_trigger(trigger_cmd, Some(run_opts)).await
}

fn get_canonical_working_dir(&self) -> Result<PathBuf, anyhow::Error> {
let working_dir_holder = match &self.tmp {
None => WorkingDirectory::Temporary(tempfile::tempdir()?),
Some(d) => WorkingDirectory::Given(d.to_owned()),
};
if !working_dir_holder.path().exists() {
std::fs::create_dir_all(working_dir_holder.path())
.context("Could not create working directory")?;
}
let working_dir = working_dir_holder
.path()
.canonicalize()
.context("Could not canonicalize working directory")?;
Ok(working_dir)
}

async fn run_trigger(
self,
trigger_cmd: Vec<String>,
Expand Down

0 comments on commit eedbe8d

Please sign in to comment.