Skip to content

Commit 6f4bdc5

Browse files
committed
fix: race condition when creating the dist directory
1 parent e52f378 commit 6f4bdc5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/config/rt/build.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::super::{DIST_DIR, STAGE_DIR};
22
use crate::config::{ConfigOptsBuild, ConfigOptsCore, ConfigOptsHook, ConfigOptsTools, RtcCore};
33
use anyhow::{ensure, Context};
44
use std::collections::HashMap;
5+
use std::io::ErrorKind;
56
use std::path::PathBuf;
67
use std::sync::Arc;
78

@@ -108,9 +109,17 @@ impl RtcBuild {
108109
// have a reliable FS path to work with, we make an exception here.
109110
let final_dist = opts.dist.unwrap_or_else(|| target_parent.join(DIST_DIR));
110111
if !final_dist.exists() {
111-
std::fs::create_dir(&final_dist).with_context(|| {
112-
format!("error creating final dist directory {:?}", &final_dist)
113-
})?;
112+
std::fs::create_dir(&final_dist)
113+
.or_else(|err| {
114+
if err.kind() == ErrorKind::AlreadyExists {
115+
Ok(())
116+
} else {
117+
Err(err)
118+
}
119+
})
120+
.with_context(|| {
121+
format!("error creating final dist directory {:?}", &final_dist)
122+
})?;
114123
}
115124
let final_dist = final_dist
116125
.canonicalize()

0 commit comments

Comments
 (0)