wowlab_fs/link.rs
1// #t(file: rust_ambient_syscall) This module is the reviewed platform adapter for native symbolic-link creation.
2
3//! Platform-neutral symbolic-link creation.
4
5use crate::{
6 error::{Error, Operation, Result},
7 path::Path,
8};
9
10/// Create a symbolic link whose target is a file.
11///
12/// Windows requires the file-target intent.
13/// The same intent is explicit on every platform.
14/// The target need not exist when the link is created.
15///
16/// # Errors
17///
18/// Returns a contextual error when the platform cannot create the link.
19pub fn file(target: &Path, link: &Path) -> Result<()> {
20 create_file_link(target, link)
21 .map_err(|source| Error::between(Operation::CreateLink, target, link, source))
22}
23
24#[cfg(unix)]
25fn create_file_link(target: &Path, link: &Path) -> std::io::Result<()> {
26 std::os::unix::fs::symlink(target, link)
27}
28
29#[cfg(windows)]
30fn create_file_link(target: &Path, link: &Path) -> std::io::Result<()> {
31 std::os::windows::fs::symlink_file(target, link)
32}