From f9c1ac5bca2fdac585a3738c59ba58dc75519fd0 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Thu, 30 May 2024 10:13:37 -0400 Subject: [PATCH] path-convert now resolves symlinks --- path-convert/Cargo.lock | 2 +- path-convert/Cargo.toml | 2 +- path-convert/src/main.rs | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/path-convert/Cargo.lock b/path-convert/Cargo.lock index fea3fcb..db8462a 100644 --- a/path-convert/Cargo.lock +++ b/path-convert/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "path-convert" -version = "0.1.0" +version = "0.0.1" dependencies = [ "pico-args", ] diff --git a/path-convert/Cargo.toml b/path-convert/Cargo.toml index 006cefc..87f8583 100644 --- a/path-convert/Cargo.toml +++ b/path-convert/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "path-convert" -version = "0.0.1" +version = "0.0.2" edition = "2021" [dependencies] diff --git a/path-convert/src/main.rs b/path-convert/src/main.rs index 4e124b0..74ed50b 100644 --- a/path-convert/src/main.rs +++ b/path-convert/src/main.rs @@ -1,3 +1,4 @@ +use std::path::Path; use pico_args::Arguments; @@ -8,12 +9,23 @@ pub fn main() { loop { let next = args.subcommand().unwrap(); - if let Some(mut arg) = next { - if arg.starts_with(DRIVE) { - arg = arg.replace(DRIVE, "C:\\"); + if let Some(arg) = next { + let mut output: String; + // resolve symlinks, etc. + let path = Path::new(&arg).canonicalize(); + if let Ok(target) = path { + output = target.to_string_lossy().to_string(); + } else { + output = arg; } - arg = arg.replace("/", "\\"); - println!("{arg}"); + + if output.starts_with(DRIVE) { + output = output.replace(DRIVE, "C:\\"); + } + + output = output.replace("/", "\\"); + + println!("{output}"); } else { break; }