Skip to content

Commit

Permalink
👔 up(fs): update the Realpath logic, will always return abs path
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 25, 2023
1 parent ea450e9 commit 59575e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions fsutil/info_nonwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ package fsutil

import (
"path"

"github.com/gookit/goutil/internal/comfunc"
"github.com/gookit/goutil/sysutil"
)

// Realpath returns the shortest path name equivalent to path by purely lexical processing.
func Realpath(pathStr string) string {
pathStr = comfunc.ExpandHome(pathStr)

if !IsAbsPath(pathStr) {
pathStr = JoinSubPaths(sysutil.Workdir(), pathStr)
}
return path.Clean(pathStr)
}
10 changes: 9 additions & 1 deletion fsutil/info_windows.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package fsutil

import "path/filepath"
import (
"github.com/gookit/goutil/internal/comfunc"
"github.com/gookit/goutil/sysutil"
)

// Realpath returns the shortest path name equivalent to path by purely lexical processing.
func Realpath(pathStr string) string {
pathStr = comfunc.ExpandHome(pathStr)

if !IsAbsPath(pathStr) {
pathStr = JoinSubPaths(sysutil.Workdir(), pathStr)
}
return filepath.Clean(pathStr)
}

0 comments on commit 59575e6

Please sign in to comment.