@@ -4,7 +4,7 @@ import fs from "fs";
4
4
import path from "path" ;
5
5
import {
6
6
createFolder ,
7
- getDatabasesPath ,
7
+ getConnectionsPath ,
8
8
getDoltPaths ,
9
9
getSocketPath ,
10
10
} from "./helpers/filePath" ;
@@ -13,33 +13,33 @@ export async function startServer(
13
13
mainWindow : BrowserWindow ,
14
14
connectionName : string ,
15
15
port : string ,
16
- databaseName : string ,
17
16
init ?: boolean ,
17
+ dbName ?: string ,
18
18
) : Promise < ChildProcess | null > {
19
19
// Set the path for the database folder
20
20
// In production, it's in the userData directory
21
21
// In development, it's in the build directory since the development userData directory clears its contents every time the app is rerun in dev mode
22
- const dbFolderPath = path . join (
23
- getDatabasesPath ( ) ,
24
- connectionName ,
25
- databaseName ,
26
- ) ;
22
+ const connectionPath = path . join ( getConnectionsPath ( ) , connectionName ) ;
27
23
const doltPath = getDoltPaths ( ) ;
28
-
29
24
try {
30
25
if ( init ) {
31
26
// Create the folder for the connection
32
- const { errorMsg } = createFolder ( path . join ( dbFolderPath ) ) ;
27
+ if ( ! dbName ) {
28
+ const errorMsg =
29
+ "Cannot initialize dolt repository without database name" ;
30
+ mainWindow . webContents . send ( "server-error" , errorMsg ) ;
31
+ throw new Error ( errorMsg ) ;
32
+ }
33
+ const dbConnectionPath = path . join ( connectionPath , dbName ) ;
34
+ const { errorMsg } = createFolder ( dbConnectionPath ) ;
33
35
if ( errorMsg ) {
34
36
mainWindow . webContents . send ( "server-error" , errorMsg ) ;
35
37
throw new Error ( errorMsg ) ;
36
38
}
37
-
38
39
// Initialize and start the server without checking if it's already running
39
- await initializeDoltRepository ( doltPath , dbFolderPath , mainWindow ) ;
40
+ await initializeDoltRepository ( doltPath , dbConnectionPath , mainWindow ) ;
40
41
}
41
-
42
- return await startServerProcess ( doltPath , dbFolderPath , port , mainWindow ) ;
42
+ return await startServerProcess ( doltPath , connectionPath , port , mainWindow ) ;
43
43
} catch ( error ) {
44
44
console . error ( "Failed to set up Dolt server:" , error ) ;
45
45
throw error ;
0 commit comments