mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6128 from crosbymichael/empty-sqlite
Init database if empty file
This commit is contained in:
commit
05cf3498a6
1 changed files with 11 additions and 2 deletions
|
@ -3,23 +3,32 @@
|
|||
package graphdb
|
||||
|
||||
import (
|
||||
_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
|
||||
"database/sql"
|
||||
"os"
|
||||
|
||||
_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
|
||||
)
|
||||
|
||||
func NewSqliteConn(root string) (*Database, error) {
|
||||
initDatabase := false
|
||||
if _, err := os.Stat(root); err != nil {
|
||||
|
||||
stat, err := os.Stat(root)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
initDatabase = true
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if stat != nil && stat.Size() == 0 {
|
||||
initDatabase = true
|
||||
}
|
||||
|
||||
conn, err := sql.Open("sqlite3", root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewDatabase(conn, initDatabase)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue