Skip to content

Commit 96efa48

Browse files
committed
修改默认创建文件夹的权限, 解决部分系统下文件权限不对的问题
1 parent d230ebb commit 96efa48

File tree

17 files changed

+148
-126
lines changed

17 files changed

+148
-126
lines changed

debug/pprof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func RunDebug(name string) {
2828
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
2929

3030
addr, has := env.GetEnv(fmt.Sprintf("PPROF_%s", name))
31-
log.Debug("pprof addr:", addr, " ", name, fmt.Sprintf("PPROF_%s", name))
31+
log.Debug("pprof addr:", addr, " ", name, ": ", fmt.Sprintf("PPROF_%s", name))
3232
if has {
3333

3434
listen, err := net.Listen("tcp", addr)

env/config.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/eolinker/eosc/log"
14-
1513
"github.com/ghodss/yaml"
1614
)
1715

@@ -169,7 +167,7 @@ func read(path string) (map[string]string, error) {
169167
}
170168

171169
func SocketAddr(name string, pid int) string {
172-
os.MkdirAll(socketSocketDirValue, os.FileMode(0666))
170+
os.MkdirAll(socketSocketDirValue, os.FileMode(PrivateDirMode))
173171

174172
return fmt.Sprintf("%s/%s.%s-%d.sock", socketSocketDirValue, appName, name, pid)
175173
}
@@ -190,12 +188,9 @@ func DataDir() string {
190188
func ErrorName() string {
191189
return strings.TrimSuffix(errorLogName, ".log")
192190
}
193-
func ErrorLevel() log.Level {
194-
l, err := log.ParseLevel(errorLogLevel)
195-
if err != nil {
196-
l = log.InfoLevel
197-
}
198-
return l
191+
func ErrorLevel() string {
192+
return errorLogLevel
193+
199194
}
200195
func ErrorPeriod() string {
201196
if errorLogPeriod != "hour" {

env/dir_unix.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
/*
5+
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
6+
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
7+
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
8+
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
9+
* Vestibulum commodo. Ut rhoncus gravida arcu.
10+
*/
11+
12+
package env
13+
14+
const (
15+
// PrivateDirMode grants owner to make/remove files inside the directory.
16+
PrivateDirMode = 0700
17+
)

env/dir_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build windows
2+
// +build windows
3+
4+
/*
5+
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
6+
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
7+
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
8+
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
9+
* Vestibulum commodo. Ut rhoncus gravida arcu.
10+
*/
11+
package env
12+
13+
const (
14+
// PrivateDirMode grants owner to make/remove files inside the directory.
15+
PrivateDirMode = 0777
16+
)

env/file.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strings"
1111

1212
"github.com/eolinker/eosc"
13-
14-
"github.com/eolinker/eosc/log"
1513
)
1614

1715
type Config struct {
@@ -92,7 +90,6 @@ func (c *Config) Save() error {
9290
if err != nil {
9391
return err
9492
}
95-
log.Info("write args file succeed!")
9693

9794
return nil
9895
}

etcd/config.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ func (s *_Server) resetCluster(InitialCluster string) {
171171
etcdInitPath := filepath.Join(s.config.DataDir, "cluster", "etcd.init")
172172
etcdConfig := env.NewConfig(etcdInitPath)
173173
etcdConfig.ReadFile(etcdInitPath)
174-
defer etcdConfig.Save()
174+
defer func() {
175+
err := etcdConfig.Save()
176+
if err != nil {
177+
log.Warn("write args file fail:", err)
178+
return
179+
}
180+
log.Info("write args file succeed!")
181+
}()
175182
etcdConfig.Set("cluster", InitialCluster)
176183
}
177184
func (s *_Server) updateCluster() {
@@ -185,7 +192,14 @@ func (s *_Server) readCluster(peerUrl types.URLs) (name, InitialCluster string,
185192
etcdInitPath := filepath.Join(s.config.DataDir, "cluster", "etcd.init")
186193
etcdConfig := env.NewConfig(etcdInitPath)
187194
etcdConfig.ReadFile(etcdInitPath)
188-
defer etcdConfig.Save()
195+
defer func() {
196+
err := etcdConfig.Save()
197+
if err != nil {
198+
log.Warn("write args file fail:", err)
199+
return
200+
}
201+
log.Info("write args file succeed!")
202+
}()
189203

190204
var has bool
191205
name, has = etcdConfig.Get("name")

extends/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func DownLoadToRepository(group, project, version string) error {
5959
defer f.Close()
6060
f.Write(data)
6161

62-
return eosc.Decompress(tarPath, dest)
62+
return Decompress(tarPath, dest)
6363
}
6464

6565
// DownLoadToRepositoryById 下载插件, id格式为 {group}:{project}[:{version}]

extends/extender-helper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"github.com/eolinker/eosc"
88
"github.com/eolinker/eosc/common/fileLocker"
9+
"github.com/eolinker/eosc/env"
910
"github.com/eolinker/eosc/process"
1011
"github.com/eolinker/eosc/service"
1112
"google.golang.org/protobuf/proto"
@@ -14,7 +15,7 @@ import (
1415

1516
func DownloadCheck(group string, project string, version string) error {
1617
path := LocalExtenderPath(group, project, version)
17-
err := os.MkdirAll(path, 0666)
18+
err := os.MkdirAll(path, env.PrivateDirMode)
1819
if err != nil {
1920
return errors.New("create extender path " + path + " error: " + err.Error())
2021
}

extends/file.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
3+
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
4+
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
5+
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
6+
* Vestibulum commodo. Ut rhoncus gravida arcu.
7+
*/
8+
9+
package extends
10+
11+
import (
12+
"archive/tar"
13+
"compress/gzip"
14+
"github.com/eolinker/eosc/env"
15+
"io"
16+
"os"
17+
"strings"
18+
)
19+
20+
// Decompress 解压文件
21+
func Decompress(filePath string, dest string) error {
22+
err := os.MkdirAll(dest, env.PrivateDirMode)
23+
if err != nil {
24+
return err
25+
}
26+
srcFile, err := os.Open(filePath)
27+
if err != nil {
28+
return err
29+
}
30+
defer srcFile.Close()
31+
gr, err := gzip.NewReader(srcFile)
32+
if err != nil {
33+
return err
34+
}
35+
defer gr.Close()
36+
tr := tar.NewReader(gr)
37+
if !strings.HasSuffix(dest, "/") {
38+
dest += "/"
39+
}
40+
for {
41+
hdr, err := tr.Next()
42+
if err != nil {
43+
if err == io.EOF {
44+
break
45+
} else {
46+
return err
47+
}
48+
}
49+
filename := dest + hdr.Name
50+
file, err := CreateFile(filename)
51+
if err != nil {
52+
return err
53+
}
54+
_, e := io.Copy(file, tr)
55+
if e != nil {
56+
return e
57+
}
58+
}
59+
return nil
60+
}
61+
62+
func CreateFile(name string) (*os.File, error) {
63+
err := os.MkdirAll(string([]rune(name)[0:strings.LastIndex(name, "/")]), env.PrivateDirMode)
64+
if err != nil {
65+
return nil, err
66+
}
67+
return os.Create(name)
68+
}

extends/local.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package extends
22

33
import (
44
"errors"
5+
"github.com/eolinker/eosc/env"
56
"os"
67

78
"github.com/eolinker/eosc/common/fileLocker"
8-
9-
"github.com/eolinker/eosc"
109
)
1110

1211
const (
@@ -22,7 +21,7 @@ func LoadCheck(group, project, version string) error {
2221

2322
// 当本地不存在当前插件时,从插件市场中下载
2423
path := LocalExtenderPath(group, project, version)
25-
err = os.MkdirAll(path, 0666)
24+
err = os.MkdirAll(path, env.PrivateDirMode)
2625
if err != nil {
2726
return errors.New("create extender path " + path + " error: " + err.Error())
2827
}
@@ -52,7 +51,7 @@ func LocalCheck(group, project, version string) error {
5251
if err != nil {
5352
return ErrorExtenderNotFindLocal
5453
}
55-
return eosc.Decompress(tarPath, dir)
54+
return Decompress(tarPath, dir)
5655
}
5756
return err
5857
}

0 commit comments

Comments
 (0)