Browse code

Move sqlite conn to graph db for cross compile support

Michael Crosby authored on 2013/12/19 14:14:16
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+package graphdb
1
+
2
+func NewSqliteConn(root string) (*Database, error) {
3
+	panic("Not implemented")
4
+}
0 5
new file mode 100644
... ...
@@ -0,0 +1,23 @@
0
+package graphdb
1
+
2
+import (
3
+	_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
4
+	"database/sql"
5
+	"os"
6
+)
7
+
8
+func NewSqliteConn(root string) (*Database, error) {
9
+	initDatabase := false
10
+	if _, err := os.Stat(root); err != nil {
11
+		if os.IsNotExist(err) {
12
+			initDatabase = true
13
+		} else {
14
+			return nil, err
15
+		}
16
+	}
17
+	conn, err := sql.Open("sqlite3", root)
18
+	if err != nil {
19
+		return nil, err
20
+	}
21
+	return NewDatabase(conn, initDatabase)
22
+}
... ...
@@ -1,9 +1,7 @@
1 1
 package docker
2 2
 
3 3
 import (
4
-	_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
5 4
 	"container/list"
6
-	"database/sql"
7 5
 	"fmt"
8 6
 	"github.com/dotcloud/docker/archive"
9 7
 	"github.com/dotcloud/docker/graphdb"
... ...
@@ -718,19 +716,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
718 718
 	}
719 719
 
720 720
 	graphdbPath := path.Join(config.Root, "linkgraph.db")
721
-	initDatabase := false
722
-	if _, err := os.Stat(graphdbPath); err != nil {
723
-		if os.IsNotExist(err) {
724
-			initDatabase = true
725
-		} else {
726
-			return nil, err
727
-		}
728
-	}
729
-	conn, err := sql.Open("sqlite3", graphdbPath)
730
-	if err != nil {
731
-		return nil, err
732
-	}
733
-	graph, err := graphdb.NewDatabase(conn, initDatabase)
721
+	graph, err := graphdb.NewSqliteConn(graphdbPath)
734 722
 	if err != nil {
735 723
 		return nil, err
736 724
 	}