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