Skip to main content

Crate logical_path

Crate logical_path 

Source
Expand description

Translate canonical (symlink-resolved) filesystem paths back to their logical (symlink-preserving) equivalents.

When a shell’s current directory traverses a symlink (Unix) or an NTFS junction, directory symlink, or subst drive (Windows), two different paths refer to the same location: the logical path (preserving the indirection) and the canonical path (with all indirections resolved). This crate detects that mapping and provides bidirectional translation.

The primary entry point is LogicalPathContext::detect(), which inspects the process environment and returns a context for translating paths in both directions.

§Quick Start

use logical_path::LogicalPathContext;
use std::path::Path;

let ctx = LogicalPathContext::detect();

if ctx.has_mapping() {
    let canonical = Path::new("/mnt/wsl/workspace/project/src/main.rs");
    let logical = ctx.to_logical(canonical);
    println!("Logical: {}", logical.display());
}

§Platform Behavior

  • Linux/macOS: Compares $PWD against getcwd().
  • Windows: Compares current_dir() against canonicalize() with \\?\ prefix stripped.

See LogicalPathContext for full platform-specific details.

Structs§

LogicalPathContext
A context that holds zero or one active prefix mappings between canonical (symlink-resolved) and logical (symlink-preserving) paths.