Skip to content

Commit fff0072

Browse files
authored
fix: create parent dirs for dist folder if don't exist (#845)
* create parent dirs for dist folder if don't exist * fix: removed redundant path check as create_dir_all handles that * fix: used create_dir_all instead of create_dir for test pipeline * used create_dir_all and removed redundant path check in the installer tool
1 parent b090088 commit fff0072

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

src/config/rt/build.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::config::{
66
Hooks,
77
};
88
use anyhow::{ensure, Context};
9-
use std::{collections::HashMap, io::ErrorKind, ops::Deref, path::PathBuf};
9+
use std::{collections::HashMap, ops::Deref, path::PathBuf};
1010

1111
/// Config options for the cargo build command
1212
#[derive(Clone, Debug)]
@@ -136,14 +136,10 @@ impl RtcBuild {
136136
// we would want to avoid such an action at this layer, however to ensure that other layers
137137
// have a reliable FS path to work with, we make an exception here.
138138
let final_dist = core.working_directory.join(&build.dist);
139-
if !final_dist.exists() {
140-
std::fs::create_dir(&final_dist)
141-
.or_else(|err| match err.kind() {
142-
ErrorKind::AlreadyExists => Ok(()),
143-
_ => Err(err),
144-
})
145-
.with_context(|| format!("error creating final dist directory {final_dist:?}"))?;
146-
}
139+
140+
std::fs::create_dir_all(&final_dist)
141+
.with_context(|| format!("error creating final dist directory {final_dist:?}"))?;
142+
147143
let final_dist = final_dist
148144
.canonicalize()
149145
.context("error taking canonical path to dist dir")?;

src/pipelines/copy_dir_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async fn setup_test_config() -> Result<(tempfile::TempDir, Arc<RtcBuild>, PathBu
1313
let tmpdir = tempfile::tempdir().context("error building tempdir for test")?;
1414
let cfg = Arc::new(RtcBuild::new_test(tmpdir.path()).await?);
1515
let asset_dir = tmpdir.path().join("test_dir");
16-
tokio::fs::create_dir(&asset_dir)
16+
tokio::fs::create_dir_all(&asset_dir)
1717
.await
1818
.context("error creating test dir")?;
1919
let asset_file = asset_dir.join("test_file");

src/tools.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,7 @@ mod archive {
542542
}
543543
}
544544
Self::None(in_file) => {
545-
let create_dir_result = std::fs::create_dir(target_directory);
546-
if let Err(e) = &create_dir_result {
547-
if e.kind() != std::io::ErrorKind::AlreadyExists {
548-
create_dir_result.context("failed to open file for")?;
549-
}
550-
}
545+
std::fs::create_dir_all(target_directory).context("failed to open file for")?;
551546

552547
let mut out_file_path = target_directory.to_path_buf();
553548
out_file_path.push(file);

0 commit comments

Comments
 (0)