feat: add compatible Trojan manager image
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/tidwall/pretty"
|
||||
"github.com/tidwall/sjson"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var configPath = "/usr/local/etc/trojan/config.json"
|
||||
@@ -53,10 +54,13 @@ func Save(data []byte, path string) bool {
|
||||
if path == "" {
|
||||
path = configPath
|
||||
}
|
||||
if err := os.WriteFile(path, pretty.Pretty(data), 0644); err != nil {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { fmt.Println(err); return false }
|
||||
tmp := path + ".tmp"
|
||||
if err := os.WriteFile(tmp, pretty.Pretty(data), 0644); err != nil {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
if err := os.Rename(tmp, path); err != nil { fmt.Println(err); return false }
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user