Skip to content

Commit

Permalink
Remove unused import and fix directory creation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
funnyzak committed Feb 21, 2024
1 parent 34f8bb4 commit 8a07833
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 2 additions & 4 deletions pkg/utils/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"io"
"os"
"path"
"path/filepath"
)

Expand Down Expand Up @@ -44,10 +43,9 @@ func FileMD5(filePath string) (string, error) {
}

func MkdirAllIfNotExists(pathname string, perm os.FileMode) error {
dir := path.Dir(pathname)
if _, err := os.Stat(dir); err != nil {
if _, err := os.Stat(pathname); err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(dir, perm); err != nil {
if err := os.MkdirAll(pathname, perm); err != nil {
return err
}
}
Expand Down
7 changes: 4 additions & 3 deletions service/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package singleton
import (
"fmt"
"os"
"path"
"time"

_ "github.com/ncruces/go-sqlite3/embed"
Expand Down Expand Up @@ -73,12 +74,12 @@ func InitLog(conf *gconfig.Config) {
}

// InitDBFromPath initialize the database from the given path
func InitDBFromPath(path string) {
func InitDBFromPath(dbpath string) {
var err error
if err = file.MkdirAllIfNotExists(path, os.ModePerm); err != nil {
if err = file.MkdirAllIfNotExists(path.Dir(dbpath), os.ModePerm); err != nil {
panic(err)
}
DB, err = gorm.Open(gormlite.Open(path), &gorm.Config{
DB, err = gorm.Open(gormlite.Open(dbpath), &gorm.Config{
CreateBatchSize: 200,
})
if err != nil {
Expand Down

0 comments on commit 8a07833

Please sign in to comment.