summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-04-08 01:32:14 +0530
committerAndinus <andinus@nand.sh>2020-04-08 01:32:14 +0530
commit0dfcf8cb81daa80aa751a5a40c243e64ee030929 (patch)
treed82c73e6153eb8c73ea2abedc430d3cc8b4f41e9
parentadf721a079bb3f37576e47280eb7ae82a6567d7b (diff)
downloadlynx-0dfcf8cb81daa80aa751a5a40c243e64ee030929.tar.gz
Add wrapper around single path Unveil command v0.2.0
-rw-r--r--path.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/path.go b/path.go
new file mode 100644
index 0000000..8f3dcc2
--- /dev/null
+++ b/path.go
@@ -0,0 +1,26 @@
+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)
+}