Skip to content

Commit

Permalink
filesystem: add back canonicalizePath()
Browse files Browse the repository at this point in the history
Restore the canonicalizePath() function from before commit
f2eb79f, since it's needed again.

Update #339
  • Loading branch information
ebiggers committed Jan 19, 2022
1 parent bf17c3e commit 65a445d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions filesystem/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"

"golang.org/x/sys/unix"

Expand All @@ -40,6 +41,22 @@ func OpenFileOverridingUmask(name string, flag int, perm os.FileMode) (*os.File,
// We only check the unix permissions and the sticky bit
const permMask = os.ModeSticky | os.ModePerm

// canonicalizePath turns path into an absolute path without symlinks.
func canonicalizePath(path string) (string, error) {
path, err := filepath.Abs(path)
if err != nil {
return "", err
}
path, err = filepath.EvalSymlinks(path)

// Get a better error if we have an invalid path
if pathErr, ok := err.(*os.PathError); ok {
err = errors.Wrap(pathErr.Err, pathErr.Path)
}

return path, err
}

// loggedStat runs os.Stat, but it logs the error if stat returns any error
// other than nil or IsNotExist.
func loggedStat(name string) (os.FileInfo, error) {
Expand Down

0 comments on commit 65a445d

Please sign in to comment.