fileutil: start working on symlink checking

This commit is contained in:
Kyle Isom 2023-05-04 22:52:16 -07:00
parent 29630c55a9
commit 770100b688
1 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package fileutil
import (
"os"
"path/filepath"
"strings"
"golang.org/x/sys/unix"
)
@ -45,3 +47,10 @@ const (
func Access(path string, mode int) error {
return unix.Access(path, uint32(mode))
}
// ValidateSymlink checks to make sure a symlink exists in some top-level
// directory.
func ValidateSymlink(symlink, topLevel string) bool {
target, err := filepath.EvalSymlinks(symlink)
return strings.HasPrefix(target, topLevel)
}