From b3eebb19b6a0657de5ec1c8f647326dd81cf74a5 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 17 Jul 2024 14:21:14 +0700 Subject: [PATCH] internal/router: change default config directory on EdgeOS So ctrld's own files will survive firmware upgrades. --- internal/router/router.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/router/router.go b/internal/router/router.go index bf65e6e..4b335a6 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "sync/atomic" "github.com/kardianos/service" @@ -164,6 +165,16 @@ func HomeDir() (string, error) { return "", err } return filepath.Dir(exe), nil + case edgeos.Name: + exe, err := os.Executable() + if err != nil { + return "", err + } + // Using binary directory as home dir if it is located in /config. + // Otherwise, fallback to old behavior for compatibility. + if strings.HasPrefix(exe, "/config/") { + return filepath.Dir(exe), nil + } } return "", nil }