|
@ -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) |
|
|
} |
|
|
} |
|
|