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: clean up some windows error cases #3255

Merged
merged 2 commits into from
Nov 28, 2024
Merged
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
22 changes: 18 additions & 4 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,13 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();
if !path.exists() {
trace!("mkdir -p {}", display_path(path));
fs::create_dir_all(path)
.wrap_err_with(|| format!("failed create_dir_all: {}", display_path(path)))?;
if let Err(err) = fs::create_dir_all(path) {
// if not exists error
if err.kind() != std::io::ErrorKind::AlreadyExists {
return Err(err)
.wrap_err_with(|| format!("failed create_dir_all: {}", display_path(path)));
}
}
}
Ok(())
}
Expand Down Expand Up @@ -310,8 +315,17 @@ pub fn make_symlink(target: &Path, link: &Path) -> Result<(PathBuf, PathBuf)> {
#[cfg(windows)]
//#[deprecated]
pub fn make_symlink(target: &Path, link: &Path) -> Result<(PathBuf, PathBuf)> {
junction::create(target, link)
.wrap_err_with(|| format!("failed to ln -sf {} {}", target.display(), link.display()))?;
if let Err(err) = junction::create(target, link) {
if err.kind() == std::io::ErrorKind::AlreadyExists {
let _ = fs::remove_file(link);
junction::create(target, link)
} else {
Err(err)
}
} else {
Ok(())
}
.wrap_err_with(|| format!("failed to ln -sf {} {}", target.display(), link.display()))?;
Ok((target.to_path_buf(), link.to_path_buf()))
}

Expand Down