Commit 1f9210a3 authored by suyanlong's avatar suyanlong

Add fileutil function

parent bf12b436
Pipeline #8037 failed with stages
......@@ -6,10 +6,10 @@ import (
"os"
"path/filepath"
"github.com/meshplus/bitxhub-kit/fileutil"
"github.com/urfave/cli"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/tool"
)
var initCMD = cli.Command{
......@@ -21,7 +21,7 @@ var initCMD = cli.Command{
return err
}
if fileutil.Exist(filepath.Join(repoRoot, repo.ConfigName)) {
if tool.Exist(filepath.Join(repoRoot, repo.ConfigName)) {
fmt.Println("sidecar configuration file already exists")
fmt.Println("reinitializing would overwrite your configuration, Y/N?")
input := bufio.NewScanner(os.Stdin)
......
......@@ -5,9 +5,9 @@ import (
"time"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/fileutil"
"github.com/link33/sidecar/pkg/log"
"github.com/link33/sidecar/tool"
)
const (
......@@ -95,7 +95,7 @@ func checkConfig(config *config) error {
// if EnableTLS is set, then tls certs must be provided
for _, nodeInfo := range config.nodesInfo {
if nodeInfo.EnableTLS {
if !fileutil.Exist(nodeInfo.CertPath) {
if !tool.Exist(nodeInfo.CertPath) {
return fmt.Errorf("ca cert file %s is not found while tls is enabled", nodeInfo.CertPath)
}
}
......
......@@ -5,8 +5,9 @@ import (
"path/filepath"
"strings"
"github.com/meshplus/bitxhub-kit/fileutil"
"github.com/spf13/viper"
"github.com/link33/sidecar/tool"
)
const (
......@@ -135,7 +136,7 @@ func DefaultConfig() *Config {
func UnmarshalConfig(repoRoot string) (*Config, error) {
configPath := filepath.Join(repoRoot, ConfigName)
if !fileutil.Exist(configPath) {
if !tool.Exist(configPath) {
return nil, fmt.Errorf("file %s doesn't exist, please initialize sidecar firstly", configPath)
}
......
package tool
import "os"
func Asset(err error) {
if err != nil {
panic(err)
}
}
// Exist check if the file with the given path exits.
func Exist(path string) bool {
fi, err := os.Lstat(path)
if fi != nil || (err != nil && !os.IsNotExist(err)) {
return true
}
return false
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment