Browse Source

Allow setting permission on CopyFile helper

Shelikhoo 1 year ago
parent
commit
353326b432
2 changed files with 3 additions and 3 deletions
  1. 2 2
      common/platform/filesystem/file.go
  2. 1 1
      infra/conf/rule/rule_test.go

+ 2 - 2
common/platform/filesystem/file.go

@@ -45,12 +45,12 @@ func ReadAsset(file string) ([]byte, error) {
 	return ReadFile(platform.GetAssetLocation(file))
 	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)
 	bytes, err := ReadFile(src)
 	if err != nil {
 	if err != nil {
 		return err
 		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 {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 1
infra/conf/rule/rule_test.go

@@ -39,7 +39,7 @@ func init() {
 func TestToCidrList(t *testing.T) {
 func TestToCidrList(t *testing.T) {
 	t.Log(os.Getenv("v2ray.location.asset"))
 	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{
 	ips := cfgcommon.StringList([]string{
 		"geoip:us",
 		"geoip:us",