File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change
1
+ use std:: path:: { PathBuf } ;
1
2
use std:: io:: { Error , ErrorKind } ;
3
+ use std:: fs:: File ;
2
4
use rusqlite:: { Connection , Row } ;
3
5
use crate :: database:: { Database , DBRawToStruct } ;
4
6
use crate :: results:: TelemetryData ;
@@ -13,7 +15,25 @@ pub fn init (database_file : &Option<String>) -> std::io::Result<Connection> {
13
15
Err ( Error :: new ( ErrorKind :: Other , "Error setup sqlite invalid database file." ) )
14
16
}
15
17
Some ( database_file) => {
16
- let connection = Connection :: open ( database_file) ;
18
+ let mut database_path = PathBuf :: from ( database_file) ;
19
+ if !database_path. is_absolute ( ) {
20
+ database_path = PathBuf :: from ( std:: env:: current_dir ( ) . unwrap ( ) . join ( database_file) ) ;
21
+ }
22
+
23
+ println ! ( "Using sqlite database file: {}" , database_path. display( ) ) ;
24
+
25
+ if !database_path. exists ( ) {
26
+ let create_file = File :: create ( & database_path) ;
27
+ match create_file {
28
+ Ok ( _) => {
29
+ println ! ( "Created sqlite database file: {}" , database_path. display( ) ) ;
30
+ }
31
+ Err ( e) => {
32
+ return Err ( Error :: new ( ErrorKind :: Other , format ! ( "Error setup sqlite {:?}" , e) ) ) ;
33
+ }
34
+ }
35
+ }
36
+ let connection = Connection :: open ( database_path) ;
17
37
match connection {
18
38
Ok ( connection) => {
19
39
let create_table = connection. execute (
You can’t perform that action at this time.
0 commit comments