Skip to content

Commit 795eb63

Browse files
Merge pull request #576 from dolthub/eric/fix-local-dolt-issues
Fix local dolt server issues
2 parents 50f1ed7 + b52e8fc commit 795eb63

File tree

8 files changed

+34
-37
lines changed

8 files changed

+34
-37
lines changed

web/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ yalc.lock
5151
/build/appx/dolt.exe
5252
/build/linux/dolt-x64
5353
/build/linux/dolt-arm64
54-
/build/databases
54+
/build/connections
5555

5656
# electron app build
5757
/app
58-
dist
58+
dist

web/main/background.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,17 @@ ipcMain.handle(
256256
_,
257257
connectionName: string,
258258
port: string,
259-
databaseName: string,
260259
init?: boolean,
260+
dbName?: string,
261261
) => {
262262
try {
263-
console.log(
264-
"start-dolt-server",
265-
connectionName,
266-
port,
267-
databaseName,
268-
init,
269-
);
263+
console.log("start-dolt-server", connectionName, port, init, dbName);
270264
doltServerProcess = await startServer(
271265
mainWindow,
272266
connectionName,
273267
port,
274-
databaseName,
275268
init,
269+
dbName,
276270
);
277271
if (!doltServerProcess) {
278272
throw new Error("Failed to start Dolt server");

web/main/doltClone.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "path";
44
import { startServerProcess } from "./doltServer";
55
import {
66
createFolder,
7-
getDatabasesPath,
7+
getConnectionsPath,
88
getDoltPaths,
99
} from "./helpers/filePath";
1010

@@ -16,11 +16,9 @@ export async function cloneAndStartDatabase(
1616
port: string,
1717
mainWindow: BrowserWindow,
1818
): Promise<ChildProcess | null> {
19-
const dbsFolderPath = getDatabasesPath();
19+
const dbsFolderPath = getConnectionsPath();
2020
const doltPath = getDoltPaths();
2121
const connectionFolderPath = path.join(dbsFolderPath, connectionName);
22-
const dbFolderPath = path.join(connectionFolderPath, newDbName);
23-
2422
try {
2523
const { errorMsg } = createFolder(path.join(connectionFolderPath));
2624
if (errorMsg) {
@@ -34,7 +32,12 @@ export async function cloneAndStartDatabase(
3432
connectionFolderPath,
3533
mainWindow,
3634
);
37-
return await startServerProcess(doltPath, dbFolderPath, port, mainWindow);
35+
return await startServerProcess(
36+
doltPath,
37+
connectionFolderPath,
38+
port,
39+
mainWindow,
40+
);
3841
} catch (error) {
3942
console.error("Failed to clone database:", error);
4043
throw error;

web/main/doltLogin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from "path";
22
import { BrowserWindow, IpcMainInvokeEvent } from "electron";
33
import { ChildProcess, execFile } from "child_process";
44
import { v4 as randomUUID } from "uuid";
5-
import { getDatabasesPath, getDoltPaths } from "./helpers/filePath";
5+
import { getConnectionsPath, getDoltPaths } from "./helpers/filePath";
66

77
export async function doltLogin(
88
event: IpcMainInvokeEvent,
@@ -12,7 +12,7 @@ export async function doltLogin(
1212
): Promise<{ email: string; username: string }> {
1313
const requestId = randomUUID();
1414
return new Promise((resolve, reject) => {
15-
const dbFolderPath = path.join(getDatabasesPath(), connectionName);
15+
const dbFolderPath = path.join(getConnectionsPath(), connectionName);
1616
const doltPath = getDoltPaths();
1717

1818
// Return the cancellation ID immediately

web/main/doltServer.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from "fs";
44
import path from "path";
55
import {
66
createFolder,
7-
getDatabasesPath,
7+
getConnectionsPath,
88
getDoltPaths,
99
getSocketPath,
1010
} from "./helpers/filePath";
@@ -13,33 +13,33 @@ export async function startServer(
1313
mainWindow: BrowserWindow,
1414
connectionName: string,
1515
port: string,
16-
databaseName: string,
1716
init?: boolean,
17+
dbName?: string,
1818
): Promise<ChildProcess | null> {
1919
// Set the path for the database folder
2020
// In production, it's in the userData directory
2121
// 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);
2723
const doltPath = getDoltPaths();
28-
2924
try {
3025
if (init) {
3126
// 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);
3335
if (errorMsg) {
3436
mainWindow.webContents.send("server-error", errorMsg);
3537
throw new Error(errorMsg);
3638
}
37-
3839
// Initialize and start the server without checking if it's already running
39-
await initializeDoltRepository(doltPath, dbFolderPath, mainWindow);
40+
await initializeDoltRepository(doltPath, dbConnectionPath, mainWindow);
4041
}
41-
42-
return await startServerProcess(doltPath, dbFolderPath, port, mainWindow);
42+
return await startServerProcess(doltPath, connectionPath, port, mainWindow);
4343
} catch (error) {
4444
console.error("Failed to set up Dolt server:", error);
4545
throw error;

web/main/helpers/filePath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { app } from "electron";
44

55
const isProd = process.env.NODE_ENV === "production";
66

7-
export function getDatabasesPath() {
7+
export function getConnectionsPath() {
88
if (isProd) {
99
// Use ~/.local/share for Linux (more persistent than user data folder, which is ~/.config)
1010
const linuxDbRoot =
1111
process.platform === "linux"
1212
? path.join(app.getPath("home"), ".local", "share", app.getName())
1313
: app.getPath("userData");
1414

15-
return path.join(linuxDbRoot, "databases");
15+
return path.join(linuxDbRoot, "connections");
1616
}
17-
return path.join(__dirname, "..", "build", "databases");
17+
return path.join(__dirname, "..", "build", "connections");
1818
}
1919

2020
// Returns the path to the Dolt binary based on the platform and environment.

web/main/helpers/removeDoltServerFolder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import path from "path";
33
import { BrowserWindow } from "electron";
44
import { rimraf } from "rimraf";
5-
import { getDatabasesPath } from "./filePath";
5+
import { getConnectionsPath } from "./filePath";
66

77
export function getErrorMessage(error: unknown): string {
88
if (error instanceof Error) {
@@ -23,7 +23,7 @@ export async function removeDoltServerFolder(
2323
mainWindow: BrowserWindow,
2424
retries = 3,
2525
): Promise<ErrorReturnType> {
26-
const dbFolderPath = path.join(getDatabasesPath(), connectionName);
26+
const dbFolderPath = path.join(getConnectionsPath(), connectionName);
2727
for (let i = 0; i < retries; i++) {
2828
try {
2929
if (process.platform === "darwin") {

web/renderer/components/pageComponents/ConnectionsPage/NewConnection/context/config.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export function ConfigProvider({ children }: Props) {
104104
"start-dolt-server",
105105
state.name.trim(),
106106
state.port,
107-
state.database,
108107
!state.cloneDolt,
108+
state.database,
109109
);
110110

111111
if (result !== "success") {

0 commit comments

Comments
 (0)