From 31214bd0449e9a840e571304226f1fbe608f6e32 Mon Sep 17 00:00:00 2001 From: smail Date: Sun, 18 Oct 2026 16:40:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(hooks):=20=E6=B7=BB=E5=8A=A0=E9=9D=9ELinux?= =?UTF-8?q?=E9=9D=9EWindows=E5=B9=B3=E5=8F=B0=E4=B8=8B=E7=9A=84writeBundle?= =?UTF-8?q?dPlugin=E5=AE=9E=E7=8E=B0=E4=BB=A5=E8=A7=A3=E5=86=B3Darwin?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/hooks/bundle_file_unsupported.go | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/hooks/bundle_file_unsupported.go diff --git a/backend/hooks/bundle_file_unsupported.go b/backend/hooks/bundle_file_unsupported.go new file mode 100644 index 00000000..54ca055f --- /dev/null +++ b/backend/hooks/bundle_file_unsupported.go @@ -0,0 +1,39 @@ +//go:build !linux && !windows + +package hooks + +import ( + "bytes" + "io" + "os" +) + +func writeBundledPlugin(path string, data []byte) error { + file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) // #nosec G304 -- the path is an entry under a private temporary bundle root. + if err != nil { + return err + } + remove := true + defer func() { + if remove { + _ = os.Remove(path) + } + }() + if _, err := io.Copy(file, bytes.NewReader(data)); err != nil { + _ = file.Close() + return err + } + if err := file.Sync(); err != nil { + _ = file.Close() + return err + } + if err := file.Chmod(0700); err != nil { + _ = file.Close() + return err + } + if err := file.Close(); err != nil { + return err + } + remove = false + return nil +}