io: move common function and add unit tests for it

This commit is contained in:
Vsevolod Brekelov 2019-11-06 17:12:33 +03:00
parent 11ce73af28
commit d799c98cfe
4 changed files with 61 additions and 17 deletions

View file

@ -5,7 +5,6 @@ import (
"fmt"
"os"
"os/signal"
"path"
"github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core"
@ -117,7 +116,7 @@ func handleLoggingParams(ctx *cli.Context, cfg config.ApplicationConfiguration)
}
if logPath := cfg.LogPath; logPath != "" {
if err := makeDir(logPath); err != nil {
if err := io.MakeDirForFile(logPath, "logger"); err != nil {
return err
}
f, err := os.Create(logPath)
@ -129,16 +128,6 @@ func handleLoggingParams(ctx *cli.Context, cfg config.ApplicationConfiguration)
return nil
}
func makeDir(filePath string) error {
fileName := filePath
dir := path.Dir(fileName)
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
return fmt.Errorf("could not create dir for logger: %v", err)
}
return nil
}
func getCountAndSkipFromContext(ctx *cli.Context) (uint32, uint32) {
count := uint32(ctx.Uint("count"))
skip := uint32(ctx.Uint("skip"))