Skip to content

Commit

Permalink
fix: windows symlink support
Browse files Browse the repository at this point in the history
  • Loading branch information
ramfox committed Oct 21, 2022
1 parent 7a945ed commit c92dab7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iroh-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ serde = { version = "1.0", features = ["derive"] }
relative-path = "1.7.2"

[dev-dependencies]
tempdir = "0.3.7"
tempdir = "0.3.7"
13 changes: 13 additions & 0 deletions iroh-api/src/api_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,26 @@ async fn save_get_stream(
if let Some(parent) = path.parent() {
tokio::fs::create_dir_all(parent.to_path(root_path)).await?;
}
#[cfg(windows)]
make_windows_symlink(target, full_path).map_err(|e| anyhow::anyhow!(e))?;

#[cfg(unix)]
tokio::fs::symlink(target, full_path).await?;
}
}
}
Ok(())
}

#[cfg(windows)]
fn make_windows_symlink(target: PathBuf, path: PathBuf) -> Result<()> {
if target.is_dir() {
std::os::windows::fs::symlink_dir(target, path).map_err(|e| anyhow::anyhow!(e))
} else {
std::os::windows::fs::symlink_file(target, path).map_err(|e| anyhow::anyhow!(e))
}
}

/// Given an cid and an optional output path, determine root path
fn get_root_path(ipfs_path: &IpfsPath, output_path: Option<&Path>) -> PathBuf {
match output_path {
Expand Down

0 comments on commit c92dab7

Please sign in to comment.