pathutil

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pathutil provides cross-platform path utilities. All paths returned by this package use forward slashes, matching the normalized format stored in snapshots and indexes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(p string) string

Normalize ensures a path uses forward slashes and is cleaned of . and .. components, matching the internal storage format. Use this for user-provided paths before comparing with stored paths.

On Unix, filepath.ToSlash only converts the OS separator (/) and leaves backslashes intact. Since drift stores paths with forward slashes on all platforms, we explicitly replace backslashes first so Windows-style paths are normalized correctly on every OS.

func Rel

func Rel(basepath, targpath string) (string, error)

Rel returns a normalized relative path (with / separators) from basepath to targpath. It combines filepath.Rel with filepath.ToSlash to ensure cross-platform consistency.

func RelToWorkDir

func RelToWorkDir(workDir, path string) (string, error)

RelToWorkDir converts a user-provided path to a normalized relative path from workDir. If the path is absolute, it is made relative to workDir. If relative, it is normalized. Returns an error if the resulting path would escape workDir (contains ".."). This is the standard entry point for user-facing file paths in CLI commands.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL