cap_primitives/rustix/fs/
hard_link_unchecked.rs

1use rustix::fs::{linkat, AtFlags};
2use std::path::Path;
3use std::{fs, io};
4
5/// *Unsandboxed* function similar to `hard_link`, but which does not perform
6/// sandboxing.
7///
8/// Even though POSIX `linkat` has the ability to follow symlinks in
9/// `old_path`, using `AT_SYMLINK_FOLLOW`, Rust's `hard_link` doesn't need
10/// that, so we don't expose it here.
11pub(crate) fn hard_link_unchecked(
12    old_start: &fs::File,
13    old_path: &Path,
14    new_start: &fs::File,
15    new_path: &Path,
16) -> io::Result<()> {
17    Ok(linkat(
18        old_start,
19        old_path,
20        new_start,
21        new_path,
22        AtFlags::empty(),
23    )?)
24}