From 7a5c35166c61a809ca641c6def0c5986c21bff0a Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Mon, 12 Feb 2024 08:07:59 -0800 Subject: [PATCH] Add data directory config --- cmd/hostd/config.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/cmd/hostd/config.go b/cmd/hostd/config.go index 955a7fda..5c9e8216 100644 --- a/cmd/hostd/config.go +++ b/cmd/hostd/config.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "os" + "path/filepath" "strconv" "strings" @@ -238,6 +239,33 @@ func setAdvancedConfig() { setListenAddress("RHP3 TCP Address", &cfg.RHP3.TCPAddress) } +func setDataDirectory() { + if len(cfg.Directory) == 0 { + cfg.Directory = "." + } + + dir, err := filepath.Abs(cfg.Directory) + if err != nil { + stdoutFatalError("Could not get absolute path of data directory: " + err.Error()) + } + + fmt.Println("The data directory is where hostd will store its metadata and consensus data.") + fmt.Println("This directory should be on a fast, reliable storage device, preferably an SSD.") + fmt.Println("") + + _, existsErr := os.Stat(filepath.Join(cfg.Directory, "hostd.db")) + dataExists := existsErr == nil + if dataExists { + fmt.Println(wrapANSI("\033[33m", "There is existing data in the data directory.", "\033[0m")) + fmt.Println(wrapANSI("\033[33m", "If you change your data directory, you will need to manually move consensus, gateway, tpool, and hostd.db to the new directory.", "\033[0m")) + } + + if !promptYesNo("Would you like to change the data directory? (Current: " + dir + ")") { + return + } + cfg.Directory = readInput("Enter data directory") +} + func buildConfig() { if _, err := os.Stat("hostd.yml"); err == nil { if !promptYesNo("hostd.yml already exists. Would you like to overwrite it?") { @@ -245,6 +273,9 @@ func buildConfig() { } } + fmt.Println("") + setDataDirectory() + fmt.Println("") if cfg.RecoveryPhrase != "" { fmt.Println(wrapANSI("\033[33m", "A wallet seed phrase is already set.", "\033[0m")) @@ -268,7 +299,6 @@ func buildConfig() { setAPIPassword() } - fmt.Println("") setAdvancedConfig() // write the config file