mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-16 18:15:01 +03:00
Write config.json after a hot apply (#6686)
* Write config.json after a hot apply tryHotApply only updated the in-memory snapshot, so bin/config.json stayed stale until the next cold start and the Telegram/Discord config backups uploaded old rules. Persist the new config once the API calls succeed; a write failure is logged and does not restart the running core. * Test that a hot apply refreshes config.json
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package xray
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
|
||||
)
|
||||
|
||||
func TestPersistConfigWritesCurrentSnapshot(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.json")
|
||||
p := NewTestProcess(&Config{RouterConfig: json_util.RawMessage(`{"rules":[]}`)}, path)
|
||||
|
||||
p.SetConfig(&Config{RouterConfig: json_util.RawMessage(`{"rules":[{"outboundTag":"warp"}]}`)})
|
||||
if err := p.PersistConfig(); err != nil {
|
||||
t.Fatalf("PersistConfig: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(data), `"outboundTag": "warp"`) && !strings.Contains(string(data), `"outboundTag":"warp"`) {
|
||||
t.Fatalf("config file does not hold the new routing:\n%s", data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user