aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/util/simple.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-09-04 01:20:12 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-09-04 01:20:12 +0900
commitd8f76f3b2594db4687c0203c4f2be8d3e4ef7740 (patch)
treeb1d8bfb5250d71094e397f8afa87710de1f1ca2f /internal/util/simple.go
parent7e6eb82195c650bc34829e5cca2d2296e78c0707 (diff)
rename to fortify and restructure
More sandbox features will be added and this will no longer track ego's features and behaviour. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/util/simple.go')
-rw-r--r--internal/util/simple.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/util/simple.go b/internal/util/simple.go
new file mode 100644
index 00000000..08ce23f6
--- /dev/null
+++ b/internal/util/simple.go
@@ -0,0 +1,39 @@
+package util
+
+import (
+ "io"
+ "os"
+ "os/exec"
+)
+
+func Which(file string) (string, bool) {
+ p, err := exec.LookPath(file)
+ return p, err == nil
+}
+
+func CopyFile(dst, src string) error {
+ srcD, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer func() {
+ if srcD.Close() != nil {
+ // unreachable
+ panic("src file closed prematurely")
+ }
+ }()
+
+ dstD, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
+ if err != nil {
+ return err
+ }
+ defer func() {
+ if dstD.Close() != nil {
+ // unreachable
+ panic("dst file closed prematurely")
+ }
+ }()
+
+ _, err = io.Copy(dstD, srcD)
+ return err
+}