Browse Source

Move init config dir to Database namespace

feature/create-install-pkgs
Tovi Jaeschke-Rogers 3 years ago
parent
commit
3d4f5016e0
2 changed files with 25 additions and 19 deletions
  1. +25
    -2
      Client/Database/Init.go
  2. +0
    -17
      Client/main.go

+ 25
- 2
Client/Database/Init.go View File

@ -2,6 +2,7 @@ package Database
import ( import (
"database/sql" "database/sql"
"os"
"path/filepath" "path/filepath"
"time" "time"
@ -16,7 +17,18 @@ var (
FsDB *bolt.DB FsDB *bolt.DB
) )
func init() {
func InitConfigDir() error {
var (
e error
)
_, e = os.Stat(Variables.ConfigDir)
if os.IsNotExist(e) {
os.MkdirAll(Variables.ConfigDir, 0644)
}
return e
}
func InitDatabaseFiles() error {
var e error var e error
// Initialise sqlite3 database for package versioning // Initialise sqlite3 database for package versioning
DB, e = sql.Open( DB, e = sql.Open(
@ -24,7 +36,7 @@ func init() {
filepath.Join(Variables.ConfigDir, Variables.DatabaseName), filepath.Join(Variables.ConfigDir, Variables.DatabaseName),
) )
if e != nil { if e != nil {
panic(e)
return e
} }
// Initialise bolt db for filesystem hashing // Initialise bolt db for filesystem hashing
@ -34,6 +46,17 @@ func init() {
&bolt.Options{ &bolt.Options{
Timeout: 5 * time.Second, Timeout: 5 * time.Second,
}) })
return e
}
func init() {
var e error
e = InitConfigDir()
if e != nil {
panic(e)
}
e = InitDatabaseFiles()
if e != nil { if e != nil {
panic(e) panic(e)
} }


+ 0
- 17
Client/main.go View File

@ -13,17 +13,6 @@ import (
"PackageManager/Variables" "PackageManager/Variables"
) )
func InitConfigDir() error {
var (
e error
)
_, e = os.Stat(Variables.ConfigDir)
if os.IsNotExist(e) {
os.MkdirAll(Variables.ConfigDir, 0644)
}
return e
}
func HelpMsg() { func HelpMsg() {
var helpMsg string var helpMsg string
helpMsg = `Usage of %s: helpMsg = `Usage of %s:
@ -89,12 +78,6 @@ func main() {
return return
} }
e = InitConfigDir()
if e != nil {
fmt.Println(Color.Fatal(e))
return
}
e = Database.InitDB() e = Database.InitDB()
if e != nil { if e != nil {
panic(e) panic(e)


Loading…
Cancel
Save