mod tracker;
pub use tracker::{HardLinkInfo, HardLinkTracker};
use crate::ArchivePath;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HardLinkEntry {
pub path: ArchivePath,
pub target_index: usize,
}
impl HardLinkEntry {
pub fn new(path: ArchivePath, target_index: usize) -> Self {
Self { path, target_index }
}
}
#[cfg(unix)]
pub fn create_hard_link(
target_path: impl AsRef<std::path::Path>,
link_path: impl AsRef<std::path::Path>,
) -> std::io::Result<()> {
std::fs::hard_link(target_path, link_path)
}
#[cfg(windows)]
pub fn create_hard_link(
target_path: impl AsRef<std::path::Path>,
link_path: impl AsRef<std::path::Path>,
) -> std::io::Result<()> {
std::fs::hard_link(target_path, link_path)
}
#[cfg(not(any(unix, windows)))]
pub fn create_hard_link(
_target_path: impl AsRef<std::path::Path>,
_link_path: impl AsRef<std::path::Path>,
) -> std::io::Result<()> {
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"Hard links are not supported on this platform",
))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_hard_link_entry() {
let entry = HardLinkEntry::new(ArchivePath::new("link.txt").unwrap(), 5);
assert_eq!(entry.path.as_str(), "link.txt");
assert_eq!(entry.target_index, 5);
}
}