mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Fix cachefile permission
This commit is contained in:
parent
b08226a850
commit
03663a5093
|
@ -1,6 +1,7 @@
|
|||
package cachefile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/netip"
|
||||
"os"
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/service/filemanager"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -41,7 +43,7 @@ type CacheFile struct {
|
|||
saveMetadataTimer *time.Timer
|
||||
}
|
||||
|
||||
func Open(path string, cacheID string) (*CacheFile, error) {
|
||||
func Open(ctx context.Context, path string, cacheID string) (*CacheFile, error) {
|
||||
const fileMode = 0o666
|
||||
options := bbolt.Options{Timeout: time.Second}
|
||||
var (
|
||||
|
@ -67,6 +69,10 @@ func Open(path string, cacheID string) (*CacheFile, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = filemanager.Chown(ctx, path)
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "platform chown")
|
||||
}
|
||||
var cacheIDBytes []byte
|
||||
if cacheID != "" {
|
||||
cacheIDBytes = append([]byte{0}, []byte(cacheID)...)
|
||||
|
|
|
@ -147,7 +147,7 @@ func NewServer(ctx context.Context, router adapter.Router, logFactory log.Observ
|
|||
|
||||
func (s *Server) PreStart() error {
|
||||
if s.cacheFilePath != "" {
|
||||
cacheFile, err := cachefile.Open(s.cacheFilePath, s.cacheID)
|
||||
cacheFile, err := cachefile.Open(s.ctx, s.cacheFilePath, s.cacheID)
|
||||
if err != nil {
|
||||
return E.Cause(err, "open cache file")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue