|
@@ -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)...)
|