Skip to content

Commit

Permalink
fix: failed to run leetgo init #92 (#93)
Browse files Browse the repository at this point in the history
* fix: failed to run leetgo init #92

* move directory creation to createTable

---------

Co-authored-by: j178 <10510431+j178@users.noreply.github.com>
  • Loading branch information
ismdeep and j178 authored Feb 3, 2023
1 parent ba77f55 commit f8a6d67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const (
CmdName = "leetgo"
globalConfigFile = "config.yaml"
projectConfigFilename = CmdName + ".yaml"
leetcodeCacheFileBaseName = "cache/leetcode-questions"
stateFile = "cache/state.json"
leetcodeCacheFileBaseName = "leetcode-questions"
stateFilename = "state.json"
CodeBeginMarker = "@lc code=begin"
CodeEndMarker = "@lc code=end"
GoTestUtilsModPath = "github.com/j178/leetgo/testutils/go"
Expand Down Expand Up @@ -122,6 +122,10 @@ func (c *Config) ConfigDir() string {
return c.dir
}

func (c *Config) CacheDir() string {
return filepath.Join(c.ConfigDir(), "cache")
}

func (c *Config) GlobalConfigFile() string {
return filepath.Join(c.ConfigDir(), globalConfigFile)
}
Expand Down Expand Up @@ -155,11 +159,11 @@ func (c *Config) ProjectConfigFilename() string {
}

func (c *Config) StateFile() string {
return filepath.Join(c.ConfigDir(), stateFile)
return filepath.Join(c.CacheDir(), stateFilename)
}

func (c *Config) LeetCodeCacheBaseName() string {
return filepath.Join(c.ConfigDir(), leetcodeCacheFileBaseName)
return filepath.Join(c.CacheDir(), leetcodeCacheFileBaseName)
}

func (c *Config) Write(w io.Writer, withComments bool) error {
Expand Down
6 changes: 5 additions & 1 deletion leetcode/cache_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ func (c *sqliteCache) GetAllQuestions() []*QuestionData {
}

func (c *sqliteCache) createTable() error {
err := utils.Truncate(c.GetCacheFile())
err := utils.CreateIfNotExists(c.GetCacheFile(), false)
if err != nil {
return err
}
err = utils.Truncate(c.GetCacheFile())
if err != nil {
return err
}
Expand Down

0 comments on commit f8a6d67

Please sign in to comment.