cap_primitives/fs/via_parent/
hard_link.rs

1use super::open_parent;
2use crate::fs::{hard_link_unchecked, MaybeOwnedFile};
3use std::path::Path;
4use std::{fs, io};
5
6/// Implement `hard_link` by `open`ing up the parent component of the path and
7/// then calling `hard_link_unchecked` on the last component.
8pub(crate) fn hard_link(
9    old_start: &fs::File,
10    old_path: &Path,
11    new_start: &fs::File,
12    new_path: &Path,
13) -> io::Result<()> {
14    let old_start = MaybeOwnedFile::borrowed(old_start);
15    let new_start = MaybeOwnedFile::borrowed(new_start);
16
17    let (old_dir, old_basename) = open_parent(old_start, old_path)?;
18    let (new_dir, new_basename) = open_parent(new_start, new_path)?;
19
20    hard_link_unchecked(
21        &old_dir,
22        old_basename.as_ref(),
23        &new_dir,
24        new_basename.as_ref(),
25    )
26}