[client] Cleanup dns and route states on startup (#2757)

This commit is contained in:
Viktor Liu
2024-10-24 10:53:46 +02:00
committed by GitHub
parent 44f2ce666e
commit 869537c951
42 changed files with 786 additions and 377 deletions

View File

@ -0,0 +1,35 @@
package statemanager
import (
"os"
"path/filepath"
"runtime"
"github.com/sirupsen/logrus"
)
// GetDefaultStatePath returns the path to the state file based on the operating system
// It returns an empty string if the path cannot be determined. It also creates the directory if it does not exist.
func GetDefaultStatePath() string {
var path string
switch runtime.GOOS {
case "windows":
path = filepath.Join(os.Getenv("PROGRAMDATA"), "Netbird", "state.json")
case "darwin", "linux":
path = "/var/lib/netbird/state.json"
case "freebsd", "openbsd", "netbsd", "dragonfly":
path = "/var/db/netbird/state.json"
// ios/android don't need state
default:
return ""
}
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, 0755); err != nil {
logrus.Errorf("Error creating directory %s: %v. Continuing without state support.", dir, err)
return ""
}
return path
}