mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-27 05:26:56 +00:00
boxdd: Add insecure mode
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ccm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
|
||||
"github.com/sagernet/sing-box/log"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/service/filemanager"
|
||||
)
|
||||
|
||||
type UsageStats struct {
|
||||
@@ -36,6 +38,7 @@ type AggregatedUsage struct {
|
||||
LastUpdated time.Time `json:"last_updated"`
|
||||
Combinations []CostCombination `json:"combinations"`
|
||||
mutex sync.Mutex
|
||||
ctx context.Context
|
||||
filePath string
|
||||
logger log.ContextLogger
|
||||
lastSaveTime time.Time
|
||||
@@ -567,7 +570,7 @@ func (u *AggregatedUsage) Load() error {
|
||||
u.LastUpdated = time.Time{}
|
||||
u.Combinations = nil
|
||||
|
||||
data, err := os.ReadFile(u.filePath)
|
||||
data, err := filemanager.ReadFile(u.ctx, u.filePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -601,12 +604,12 @@ func (u *AggregatedUsage) Save() error {
|
||||
}
|
||||
|
||||
tmpFile := u.filePath + ".tmp"
|
||||
err = os.WriteFile(tmpFile, data, 0o644)
|
||||
err = filemanager.WriteFile(u.ctx, tmpFile, data, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(tmpFile)
|
||||
err = os.Rename(tmpFile, u.filePath)
|
||||
defer filemanager.Remove(u.ctx, tmpFile)
|
||||
err = filemanager.Rename(u.ctx, tmpFile, u.filePath)
|
||||
if err == nil {
|
||||
u.saveMutex.Lock()
|
||||
u.lastSaveTime = time.Now()
|
||||
|
||||
Reference in New Issue
Block a user