paths_equal

Function paths_equal 

Source
pub fn paths_equal(path1: &Path, path2: &Path) -> bool
Expand description

Compares two paths for equality, respecting platform case sensitivity rules.

This function performs path comparison that follows platform conventions:

  • Windows: Case-insensitive comparison (NTFS/FAT32 behavior)
  • Unix-like: Case-sensitive comparison (ext4/APFS/HFS+ behavior)

§Arguments

  • path1 - First path to compare
  • path2 - Second path to compare

§Returns

true if the paths are considered equal on the current platform

§Examples

use agpm_cli::utils::platform::paths_equal;
use std::path::Path;

let path1 = Path::new("Config.toml");
let path2 = Path::new("config.toml");

#[cfg(windows)]
assert!(paths_equal(path1, path2)); // Case-insensitive on Windows

#[cfg(not(windows))]
assert!(!paths_equal(path1, path2)); // Case-sensitive on Unix

§Platform Behavior

  • Windows: Converts both paths to lowercase before comparison
  • macOS: Case-sensitive by default (but filesystems may vary)
  • Linux: Always case-sensitive

§Use Cases

  • Checking for duplicate file references
  • Path deduplication in collections
  • Validating user input against existing paths
  • Cross-platform file system operations

§Note

This function compares path strings, not filesystem entries. It does not resolve symbolic links or check if the paths actually exist.

§Filesystem Variations

Some filesystems have configurable case sensitivity (like APFS on macOS). This function uses platform defaults and may not match filesystem behavior in all cases.