codex_git/
platform.rs

1use std::path::Path;
2
3use crate::GitToolingError;
4
5#[cfg(unix)]
6pub fn create_symlink(
7    _source: &Path,
8    link_target: &Path,
9    destination: &Path,
10) -> Result<(), GitToolingError> {
11    use std::os::unix::fs::symlink;
12
13    symlink(link_target, destination)?;
14    Ok(())
15}
16
17#[cfg(windows)]
18pub fn create_symlink(
19    source: &Path,
20    link_target: &Path,
21    destination: &Path,
22) -> Result<(), GitToolingError> {
23    use std::os::windows::fs::FileTypeExt;
24    use std::os::windows::fs::symlink_dir;
25    use std::os::windows::fs::symlink_file;
26
27    let metadata = std::fs::symlink_metadata(source)?;
28    if metadata.file_type().is_symlink_dir() {
29        symlink_dir(link_target, destination)?;
30    } else {
31        symlink_file(link_target, destination)?;
32    }
33    Ok(())
34}
35
36#[cfg(not(any(unix, windows)))]
37compile_error!("codex-git symlink support is only implemented for Unix and Windows");