lynx/path.go
Andinus a129334aef
Compile for non OpenBSD systems
Previously the compilation would fail for non OpenBSD systems & the
user had to manage it themselves. Now it compiles on non OpenBSD
systems but returns nil immediately because unveil isn't supported on
those systems.
2020-04-15 00:24:55 +05:30

29 lines
796 B
Go

// +build openbsd
package lynx
import "golang.org/x/sys/unix"
// UnveilPath takes a path, permission & unveils it, returning an
// error if unveil fails. "no such file or directory" error is
// ignored.
func UnveilPath(path string, flags string) (err error) {
err = unix.Unveil(path, flags)
// "no such file or directory" error is ignored.
if err != nil && err.Error() != "no such file or directory" {
// Better error message could be returned like
// one that includes the path on which unveil
// failed.
return err
}
// Returning nil because err can be "no such file or
// directory" which needs to be ignored.
return nil
}
// UnveilPathStrict is just a wrapper around unix.Unveil.
func UnveilPathStrict(path string, flags string) error {
return unix.Unveil(path, flags)
}