aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/turbopath/anchored_system_path.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
commitfc8c5fdce62fb229202659408798a7b6c98f6e8b (patch)
tree7554f80e50de4af6fd255afa7c21bcdd58a7af34 /cli/internal/turbopath/anchored_system_path.go
parentdd84b9d64fb98746a230cd24233ff50a562c39c9 (diff)
downloadHydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.tar.gz
HydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.zip
Diffstat (limited to 'cli/internal/turbopath/anchored_system_path.go')
-rw-r--r--cli/internal/turbopath/anchored_system_path.go75
1 files changed, 0 insertions, 75 deletions
diff --git a/cli/internal/turbopath/anchored_system_path.go b/cli/internal/turbopath/anchored_system_path.go
deleted file mode 100644
index 0957ead..0000000
--- a/cli/internal/turbopath/anchored_system_path.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package turbopath
-
-import (
- "os"
- "path/filepath"
- "strings"
-)
-
-// AnchoredSystemPath is a path stemming from a specified root using system separators.
-type AnchoredSystemPath string
-
-// ToString returns a string represenation of this Path.
-// Used for interfacing with APIs that require a string.
-func (p AnchoredSystemPath) ToString() string {
- return string(p)
-}
-
-// ToStringDuringMigration returns the string representation of this path, and is for
-// use in situations where we expect a future path migration to remove the need for the
-// string representation
-func (p AnchoredSystemPath) ToStringDuringMigration() string {
- return string(p)
-}
-
-// ToSystemPath returns itself.
-func (p AnchoredSystemPath) ToSystemPath() AnchoredSystemPath {
- return p
-}
-
-// ToUnixPath converts a AnchoredSystemPath to a AnchoredUnixPath.
-func (p AnchoredSystemPath) ToUnixPath() AnchoredUnixPath {
- return AnchoredUnixPath(filepath.ToSlash(p.ToString()))
-}
-
-// RelativeTo calculates the relative path between two AnchoredSystemPath`s.
-func (p AnchoredSystemPath) RelativeTo(basePath AnchoredSystemPath) (AnchoredSystemPath, error) {
- processed, err := filepath.Rel(basePath.ToString(), p.ToString())
- return AnchoredSystemPath(processed), err
-}
-
-// RestoreAnchor prefixes the AnchoredSystemPath with its anchor to return an AbsoluteSystemPath.
-func (p AnchoredSystemPath) RestoreAnchor(anchor AbsoluteSystemPath) AbsoluteSystemPath {
- return AbsoluteSystemPath(filepath.Join(anchor.ToString(), p.ToString()))
-}
-
-// Dir returns filepath.Dir for the path.
-func (p AnchoredSystemPath) Dir() AnchoredSystemPath {
- return AnchoredSystemPath(filepath.Dir(p.ToString()))
-}
-
-// Join appends relative path segments to this AnchoredSystemPath.
-func (p AnchoredSystemPath) Join(additional ...RelativeSystemPath) AnchoredSystemPath {
- cast := RelativeSystemPathArray(additional)
- return AnchoredSystemPath(filepath.Join(p.ToString(), filepath.Join(cast.ToStringArray()...)))
-}
-
-// HasPrefix is strings.HasPrefix for paths, ensuring that it matches on separator boundaries.
-// This does NOT perform Clean in advance.
-func (p AnchoredSystemPath) HasPrefix(prefix AnchoredSystemPath) bool {
- prefixLen := len(prefix)
- pathLen := len(p)
-
- if prefixLen > pathLen {
- // Can't be a prefix if longer.
- return false
- } else if prefixLen == pathLen {
- // Can be a prefix if they're equal, but otherwise no.
- return p == prefix
- }
-
- // otherPath is definitely shorter than p.
- // We need to confirm that p[len(otherPath)] is a system separator.
-
- return strings.HasPrefix(p.ToString(), prefix.ToString()) && os.IsPathSeparator(p[prefixLen])
-}