Skip to content

Commit

Permalink
Merge pull request #303 from SiaFoundation/nate/update-data-dir-config
Browse files Browse the repository at this point in the history
Add data directory config
  • Loading branch information
n8maninger authored Feb 12, 2024
2 parents 3a0247a + 7a5c351 commit 682de09
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cmd/hostd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"os"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -238,13 +239,43 @@ 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?") {
return
}
}

fmt.Println("")
setDataDirectory()

fmt.Println("")
if cfg.RecoveryPhrase != "" {
fmt.Println(wrapANSI("\033[33m", "A wallet seed phrase is already set.", "\033[0m"))
Expand All @@ -268,7 +299,6 @@ func buildConfig() {
setAPIPassword()
}

fmt.Println("")
setAdvancedConfig()

// write the config file
Expand Down

0 comments on commit 682de09

Please sign in to comment.