fix: replace all get current path method from "./" to os args
This commit is contained in:
+2
-1
@@ -7,6 +7,7 @@ import (
|
||||
var ConfigPath *string
|
||||
var DBPath_data *string
|
||||
var DBPath_log *string
|
||||
var CurrentPath string
|
||||
|
||||
type SoftwareInfo struct {
|
||||
Name string
|
||||
@@ -22,7 +23,7 @@ var Software = SoftwareInfo{
|
||||
Version: "0.0.1",
|
||||
Developer: "Madobi Nanami",
|
||||
BuildVer: 1,
|
||||
BuildType: "release",
|
||||
BuildType: "pre-release",
|
||||
}
|
||||
|
||||
type StatusFlags struct {
|
||||
|
||||
@@ -21,10 +21,11 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
global.CurrentPath = utils.GetCurrentPath()
|
||||
postLog.Info(fmt.Sprintf("%s %s (Build %d.%s) by %s", global.Software.Name, global.Software.Version, global.Software.BuildVer, global.Software.BuildType, global.Software.Developer))
|
||||
global.ConfigPath = flag.String("config", "./config.json", "path to config file")
|
||||
global.DBPath_data = flag.String("db", "./database.db", "path to database file")
|
||||
global.DBPath_log = flag.String("log", "./logs.db", "path to logs database file")
|
||||
global.ConfigPath = flag.String("config", global.CurrentPath+string(os.PathSeparator)+"config.json", "path to config file")
|
||||
global.DBPath_data = flag.String("db", global.CurrentPath+string(os.PathSeparator)+"database.db", "path to database file")
|
||||
global.DBPath_log = flag.String("log", global.CurrentPath+string(os.PathSeparator)+"logs.db", "path to logs database file")
|
||||
flag.Parse()
|
||||
|
||||
if _, err := os.Stat(*global.ConfigPath); os.IsNotExist(err) {
|
||||
@@ -66,8 +67,6 @@ func main() {
|
||||
frpLogger.SetDatabase(global.ConfigDB, global.FrpcDB)
|
||||
frpLogger.SetDebugMode(global.CurrentConfig.Debug)
|
||||
|
||||
config.GetConfig()
|
||||
|
||||
postLog.InitLogBroadcaster()
|
||||
|
||||
setupRoutes()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"path/filepath"
|
||||
|
||||
"super-frpc/database"
|
||||
"super-frpc/global"
|
||||
@@ -200,3 +201,15 @@ func RestartProcess() error {
|
||||
os.Exit(0)
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetCurrentPath() (string) {
|
||||
filePath, _ := exec.LookPath(os.Args[0])
|
||||
if filePath == "" {
|
||||
return ""
|
||||
}
|
||||
absPath, err := filepath.Abs(filePath)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return filepath.Dir(absPath)
|
||||
}
|
||||
+3
-3
@@ -94,7 +94,7 @@ func syncRunningInstancesToWatchdog() {
|
||||
|
||||
func ensureWatchdogProcess() error {
|
||||
watchdogName, err := getWatchdogBinaryName()
|
||||
exec.Command("chmod", "+x", filepath.Join(".", "watchdog", watchdogName)).Run()
|
||||
exec.Command("chmod", "+x", filepath.Join(global.CurrentPath, "watchdog", watchdogName)).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func ensureWatchdogProcess() error {
|
||||
}
|
||||
postLog.Info(fmt.Sprintf("Watchdog process %s is not running, starting it...", watchdogName))
|
||||
|
||||
watchdogPath := filepath.Join(".", "watchdog", watchdogName)
|
||||
watchdogPath := filepath.Join(global.CurrentPath, "watchdog", watchdogName)
|
||||
if !utils.IsFileExist(watchdogPath) {
|
||||
return fmt.Errorf("watchdog binary not found: %s", watchdogPath)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func getWatchdogBinaryName() (string, error) {
|
||||
case "init.d":
|
||||
return "watchdog_initd", nil
|
||||
case "windows":
|
||||
if utils.IsFileExist(filepath.Join(".", "watchdog", "watchdog_windows.exe")) {
|
||||
if utils.IsFileExist(filepath.Join(global.CurrentPath, "watchdog", "watchdog_windows.exe")) {
|
||||
return "watchdog_windows.exe", nil
|
||||
}
|
||||
return "watchdog_windows", nil
|
||||
|
||||
Reference in New Issue
Block a user