Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create parent dirs for dist folder if don't exist #845

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/config/rt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::config::{
Hooks,
};
use anyhow::{ensure, Context};
use std::{collections::HashMap, io::ErrorKind, ops::Deref, path::PathBuf};
use std::{collections::HashMap, ops::Deref, path::PathBuf};

/// Config options for the cargo build command
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -136,14 +136,10 @@ impl RtcBuild {
// we would want to avoid such an action at this layer, however to ensure that other layers
// have a reliable FS path to work with, we make an exception here.
let final_dist = core.working_directory.join(&build.dist);
if !final_dist.exists() {
std::fs::create_dir(&final_dist)
.or_else(|err| match err.kind() {
ErrorKind::AlreadyExists => Ok(()),
_ => Err(err),
})
.with_context(|| format!("error creating final dist directory {final_dist:?}"))?;
}

std::fs::create_dir_all(&final_dist)
.with_context(|| format!("error creating final dist directory {final_dist:?}"))?;

let final_dist = final_dist
.canonicalize()
.context("error taking canonical path to dist dir")?;
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines/copy_dir_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn setup_test_config() -> Result<(tempfile::TempDir, Arc<RtcBuild>, PathBu
let tmpdir = tempfile::tempdir().context("error building tempdir for test")?;
let cfg = Arc::new(RtcBuild::new_test(tmpdir.path()).await?);
let asset_dir = tmpdir.path().join("test_dir");
tokio::fs::create_dir(&asset_dir)
tokio::fs::create_dir_all(&asset_dir)
.await
.context("error creating test dir")?;
let asset_file = asset_dir.join("test_file");
Expand Down
7 changes: 1 addition & 6 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,7 @@ mod archive {
}
}
Self::None(in_file) => {
let create_dir_result = std::fs::create_dir(target_directory);
if let Err(e) = &create_dir_result {
if e.kind() != std::io::ErrorKind::AlreadyExists {
create_dir_result.context("failed to open file for")?;
}
}
std::fs::create_dir_all(target_directory).context("failed to open file for")?;

let mut out_file_path = target_directory.to_path_buf();
out_file_path.push(file);
Expand Down