Skip to content

Commit

Permalink
Fix: ensure boundary exists when ensure_dir_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed May 5, 2024
1 parent f08958e commit 2ea7d59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions support/build/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ pub fn apply_build_plan<'l, 'r, P: AsRef<Path>>(plan: BuildPlan<'l, 'r>,
ensure_dir_exists(&into, target_root)?;
let filename =
source.file_name().ok_or_else(|| {
IoError::new(
IoErrorKind::InvalidFilename,
format!("Filename not found for {}", into.display()),
)
let msg = format!("Filename not found for {}", into.display());
IoError::new(IoErrorKind::InvalidFilename, msg)
})?;
let into = into.join(filename);
soft_link_checked(source, into, overwrite, target_root)
Expand Down
23 changes: 21 additions & 2 deletions support/build/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ pub fn parent_of(path: &Path) -> Result<&Path> {

pub fn ensure_dir_exists<P: AsRef<Path>>(path: P, boundary: impl AsRef<Path>) -> std::io::Result<()> {
trace!("ensure_dir_exists: path: {:?}", path.as_ref());
if cfg!(windows) &&
!boundary.as_ref()
.try_exists()
.map_err(|err| error!("{err}"))
.ok()
.filter(|v| *v)
.unwrap_or_default()
{
trace!("\t boundary not exists: {:?}, creating", boundary.as_ref());
std::fs::create_dir_all(&boundary)?;
}

check_top_boundary_ok(&path.as_ref().join(PathBuf::from("...")), boundary.as_ref())?;
if !path.as_ref().try_exists()? {
trace!("path '{:?}' doesn't exist, creating it", path.as_ref());
Expand Down Expand Up @@ -87,7 +99,7 @@ pub fn hard_link_forced<Po: AsRef<Path>, Pl: AsRef<Path>>(origin: Po,

/// Follows symlinks.
/// Both given paths will be canonicalized.
/// - `boundary` should existing and be directory
/// - `boundary` should exist and be directory
/// - canonicalized `path` should start with canonicalized `boundary`
fn check_top_boundary<B: AsRef<Path>>(path: &Path, boundary: B) -> Result<bool> {
log::debug!(
Expand All @@ -99,7 +111,14 @@ fn check_top_boundary<B: AsRef<Path>>(path: &Path, boundary: B) -> Result<bool>
.canonicalize()
.unwrap_or_else(|_| boundary.as_ref().to_owned());

trace!("\t boundary: {boundary:?}");
{
let exists = boundary.try_exists()
.map_err(|err| error!("{err}"))
.ok()
.filter(|v| *v)
.unwrap_or_default();
trace!("\t boundary: {boundary:?}, existing: {exists}");
}

// Without last component, skip to parent:
// We don't care where to pointing last component, but parents is important.
Expand Down

0 comments on commit 2ea7d59

Please sign in to comment.