//go:build !unix package activator import ( "os" ) // openOwnEnvNoFollow is the unix helper's stand-in where there is no // O_NOFOLLOW or O_NONBLOCK (windows). The agent only runs on Linux; this // keeps the cross-compiled builds working and still refuses a link it can // see, by the same Lstat check EnsureAdminToken makes, and a non-file once // it has opened it. It is check-then-open, so it is weaker than the unix // open, which is the one that matters. func openOwnEnvNoFollow(path string, flag int, perm os.FileMode) (*os.File, error) { if fi, err := os.Lstat(path); err == nil && fi.Mode()&os.ModeSymlink != 0 { return nil, errOwnEnvSymlink } f, err := os.OpenFile(path, flag, perm) if err != nil { return nil, err } st, err := f.Stat() if err != nil { f.Close() return nil, err } if !st.Mode().IsRegular() { f.Close() return nil, errOwnEnvNotRegular } return f, nil }