Skip to content

Commit

Permalink
fixed init and unsafe-reset-all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
avendauz committed Dec 22, 2023
1 parent 79dc467 commit 70af308
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion curium/cmd/curiumd/main.go
@@ -1,6 +1,7 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -39,10 +40,40 @@ func main() {
storageDir := filepath.Join(config.RootDir, "storage")
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
if err := os.RemoveAll(storageDir); err == nil {
logger.Info("Removed all storage history", "dir", storageDir)
logger.Debug("Removed all storage history", "dir", storageDir)
} else {
logger.Error("Error removing all storage history", "dir", storageDir, "err", err)
}
}

if len(os.Args) > 1 && os.Args[1] == "init" {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
rootDir := app.DefaultNodeHome

for i, arg := range os.Args {
if arg == "--home" && i+1 < len(os.Args) {
rootDir = os.Args[i+1]
break
}
}

storageDir := filepath.Join(rootDir, "storage")

newContent := "storage-dir = " + "\"" + storageDir + "\"\n" + "filter = \"server\"\n"
appFilePath := filepath.Join(rootDir, "config/app.toml")
existingContent, err := ioutil.ReadFile(appFilePath)
if err != nil {
logger.Error("Error reading file:", err)
return
}
fullContent := newContent + string(existingContent)
err = ioutil.WriteFile(appFilePath, []byte(fullContent), 0644)
if err != nil {
logger.Error("Error writing to file:", err)
return
}
//logger.Debug("Storage Config successfully added into app.toml")

}
}
}

0 comments on commit 70af308

Please sign in to comment.