Skip to content

Commit

Permalink
fix: Fix no such file bug (#81)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <cegao@tensorchord.ai>
  • Loading branch information
gaocegege committed Apr 28, 2022
1 parent 08aa611 commit 44dc07a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/home/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"sync"

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -64,28 +65,33 @@ func (m generalManager) HomeDir() string {
func (m *generalManager) init(homeDir, configFile string) error {
expandedDir, err := expandHome(homeDir)
if err != nil {
return err
return errors.Wrap(err, "failed to expand home dir")
}
if err := os.MkdirAll(expandedDir, 0755); err != nil {
return err
return errors.Wrap(err, "failed to create MIDI home directory")
}
m.homeDir = expandedDir

m.cacheDir = filepath.Join(expandedDir, cacheDirName)
cacheDir := filepath.Join(expandedDir, cacheDirName)
if err := os.MkdirAll(cacheDir, 0755); err != nil {
return errors.Wrap(err, "failed to create MIDI cache directory")
}
m.cacheDir = cacheDir

expandedFilePath, err := expandHome(configFile)
if err != nil {
return err
return errors.Wrap(err, "failed to expand config file path")
}

_, err = os.Stat(expandedFilePath)
if err != nil {
if os.IsNotExist(err) {
if _, err := os.Create(configFile); err != nil {
return err
logrus.WithField("config", expandedFilePath).Info("Creating config file")
if _, err := os.Create(expandedFilePath); err != nil {
return errors.Wrap(err, "failed to create config file")
}
} else {
return err
return errors.Wrap(err, "failed to stat config file")
}
}
m.configFile = expandedFilePath
Expand Down

0 comments on commit 44dc07a

Please sign in to comment.