#[cfg(windows)]
fn main() -> anyhow::Result<()> {
use robosync::windows_symlinks;
use std::fs;
use std::path::Path;
println!("Windows Symlink Example for RoboSync");
println!("====================================");
println!();
let test_dir = Path::new("test_symlinks");
if test_dir.exists() {
fs::remove_dir_all(test_dir)?;
}
let source_dir = test_dir.join("source");
fs::create_dir_all(&source_dir)?;
let file1 = source_dir.join("file1.txt");
fs::write(&file1, "This is file 1")?;
let file2 = source_dir.join("file2.txt");
fs::write(&file2, "This is file 2")?;
let subdir = source_dir.join("subdir");
fs::create_dir(&subdir)?;
let file3 = subdir.join("file3.txt");
fs::write(&file3, "This is file 3 in subdir")?;
println!("Creating symbolic links...");
println!("NOTE: This requires either:");
println!(" 1) Running as Administrator");
println!(" 2) Developer Mode enabled (Windows 10+)");
println!(" 3) SeCreateSymbolicLinkPrivilege granted");
println!();
let link1 = source_dir.join("link_to_file1.txt");
match windows_symlinks::create_symlink(&link1, &file1) {
Ok(_) => println!(
"✓ Created file symlink: {} -> {}",
link1.display(),
file1.display()
),
Err(e) => println!("✗ Failed to create file symlink: {}", e),
}
let link2 = source_dir.join("link_to_subdir");
match windows_symlinks::create_symlink(&link2, &subdir) {
Ok(_) => println!(
"✓ Created directory symlink: {} -> {}",
link2.display(),
subdir.display()
),
Err(e) => println!("✗ Failed to create directory symlink: {}", e),
}
let link3 = source_dir.join("relative_link.txt");
match windows_symlinks::create_symlink(&link3, Path::new("file2.txt")) {
Ok(_) => println!(
"✓ Created relative symlink: {} -> file2.txt",
link3.display()
),
Err(e) => println!("✗ Failed to create relative symlink: {}", e),
}
println!();
println!("Now you can use RoboSync to synchronize this directory:");
println!(" robosync {} destination_dir", source_dir.display());
println!();
println!("RoboSync will preserve all symbolic links during synchronization.");
Ok(())
}
#[cfg(not(windows))]
fn main() {
println!("This example is for Windows only.");
println!("On Unix systems, symlink support is already built-in.");
}