Skip to content

Commit 682de09

Browse files
authored
Merge pull request #303 from SiaFoundation/nate/update-data-dir-config
Add data directory config
2 parents 3a0247a + 7a5c351 commit 682de09

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

cmd/hostd/config.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"os"
8+
"path/filepath"
89
"strconv"
910
"strings"
1011

@@ -238,13 +239,43 @@ func setAdvancedConfig() {
238239
setListenAddress("RHP3 TCP Address", &cfg.RHP3.TCPAddress)
239240
}
240241

242+
func setDataDirectory() {
243+
if len(cfg.Directory) == 0 {
244+
cfg.Directory = "."
245+
}
246+
247+
dir, err := filepath.Abs(cfg.Directory)
248+
if err != nil {
249+
stdoutFatalError("Could not get absolute path of data directory: " + err.Error())
250+
}
251+
252+
fmt.Println("The data directory is where hostd will store its metadata and consensus data.")
253+
fmt.Println("This directory should be on a fast, reliable storage device, preferably an SSD.")
254+
fmt.Println("")
255+
256+
_, existsErr := os.Stat(filepath.Join(cfg.Directory, "hostd.db"))
257+
dataExists := existsErr == nil
258+
if dataExists {
259+
fmt.Println(wrapANSI("\033[33m", "There is existing data in the data directory.", "\033[0m"))
260+
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"))
261+
}
262+
263+
if !promptYesNo("Would you like to change the data directory? (Current: " + dir + ")") {
264+
return
265+
}
266+
cfg.Directory = readInput("Enter data directory")
267+
}
268+
241269
func buildConfig() {
242270
if _, err := os.Stat("hostd.yml"); err == nil {
243271
if !promptYesNo("hostd.yml already exists. Would you like to overwrite it?") {
244272
return
245273
}
246274
}
247275

276+
fmt.Println("")
277+
setDataDirectory()
278+
248279
fmt.Println("")
249280
if cfg.RecoveryPhrase != "" {
250281
fmt.Println(wrapANSI("\033[33m", "A wallet seed phrase is already set.", "\033[0m"))
@@ -268,7 +299,6 @@ func buildConfig() {
268299
setAPIPassword()
269300
}
270301

271-
fmt.Println("")
272302
setAdvancedConfig()
273303

274304
// write the config file

0 commit comments

Comments
 (0)