Skip to content

Commit

Permalink
fix: create parent dirs for dist folder if don't exist (#845)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ZibanPirate authored Aug 8, 2024
1 parent b090088 commit fff0072
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
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

0 comments on commit fff0072

Please sign in to comment.