From 353326b43284e52313e3281e0ae478b8ec7bc17c Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Mon, 11 Mar 2024 20:57:55 +0000 Subject: [PATCH] Allow setting permission on CopyFile helper --- common/platform/filesystem/file.go | 4 ++-- infra/conf/rule/rule_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/platform/filesystem/file.go b/common/platform/filesystem/file.go index c05f0aa46..f8964968d 100644 --- a/common/platform/filesystem/file.go +++ b/common/platform/filesystem/file.go @@ -45,12 +45,12 @@ func ReadAsset(file string) ([]byte, error) { return ReadFile(platform.GetAssetLocation(file)) } -func CopyFile(dst string, src string) error { +func CopyFile(dst string, src string, perm os.FileMode) error { bytes, err := ReadFile(src) if err != nil { return err } - f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0o644) + f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, perm) if err != nil { return err } diff --git a/infra/conf/rule/rule_test.go b/infra/conf/rule/rule_test.go index 622ce2630..321b17ddd 100644 --- a/infra/conf/rule/rule_test.go +++ b/infra/conf/rule/rule_test.go @@ -39,7 +39,7 @@ func init() { func TestToCidrList(t *testing.T) { t.Log(os.Getenv("v2ray.location.asset")) - common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoiptestrouter.dat"), platform.GetAssetLocation("geoip.dat"))) + common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoiptestrouter.dat"), platform.GetAssetLocation("geoip.dat"), 0o600)) ips := cfgcommon.StringList([]string{ "geoip:us",