mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-07 16:03:07 +00:00
updates the config menu
This commit is contained in:
parent
280b00802b
commit
c947a71167
@ -29,7 +29,6 @@ import { ConfigMenu } from "./ui/configMenu.js";
|
|||||||
import { PathSelector } from "./utils/pathSelector.js";
|
import { PathSelector } from "./utils/pathSelector.js";
|
||||||
import { NumberSelector } from "./utils/numberSelector.js";
|
import { NumberSelector } from "./utils/numberSelector.js";
|
||||||
import { MenuLoop } from "./utils/menuLoop.js";
|
import { MenuLoop } from "./utils/menuLoop.js";
|
||||||
import { DataDirMover } from "./utils/dataDirMover.js";
|
|
||||||
import { Installer } from "./handlers/installer.js";
|
import { Installer } from "./handlers/installer.js";
|
||||||
import { ShellService } from "./services/shellService.js";
|
import { ShellService } from "./services/shellService.js";
|
||||||
import { OsService } from "./services/osService.js";
|
import { OsService } from "./services/osService.js";
|
||||||
@ -125,9 +124,7 @@ export async function main() {
|
|||||||
uiService,
|
uiService,
|
||||||
new MenuLoop(),
|
new MenuLoop(),
|
||||||
configService,
|
configService,
|
||||||
pathSelector,
|
|
||||||
numberSelector,
|
numberSelector,
|
||||||
new DataDirMover(fsService, uiService),
|
|
||||||
);
|
);
|
||||||
const processControl = new ProcessControl(
|
const processControl = new ProcessControl(
|
||||||
configService,
|
configService,
|
||||||
|
|||||||
@ -1,39 +1,21 @@
|
|||||||
export class ConfigMenu {
|
export class ConfigMenu {
|
||||||
constructor(
|
constructor(uiService, menuLoop, configService, numberSelector) {
|
||||||
uiService,
|
|
||||||
menuLoop,
|
|
||||||
configService,
|
|
||||||
pathSelector,
|
|
||||||
numberSelector,
|
|
||||||
dataDirMover,
|
|
||||||
) {
|
|
||||||
this.ui = uiService;
|
this.ui = uiService;
|
||||||
this.loop = menuLoop;
|
this.loop = menuLoop;
|
||||||
this.configService = configService;
|
this.configService = configService;
|
||||||
this.pathSelector = pathSelector;
|
|
||||||
this.numberSelector = numberSelector;
|
this.numberSelector = numberSelector;
|
||||||
this.dataDirMover = dataDirMover;
|
|
||||||
|
|
||||||
this.loop.initialize(this.showConfigMenu);
|
this.loop.initialize(this.showConfigMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
show = async () => {
|
show = async () => {
|
||||||
this.config = this.configService.get();
|
this.config = this.configService.get();
|
||||||
this.originalDataDir = this.config.dataDir;
|
|
||||||
this.ui.showInfoMessage("Codex Configuration");
|
this.ui.showInfoMessage("Codex Configuration");
|
||||||
await this.loop.showLoop();
|
await this.loop.showLoop();
|
||||||
};
|
};
|
||||||
|
|
||||||
showConfigMenu = async () => {
|
showConfigMenu = async () => {
|
||||||
await this.ui.askMultipleChoice("Select to edit:", [
|
await this.ui.askMultipleChoice("Select to edit:", [
|
||||||
{
|
|
||||||
label: `Data path = "${this.config.dataDir}"`,
|
|
||||||
action: this.editDataDir,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: `Logs path = "${this.config.logsDir}"`,
|
|
||||||
action: this.editLogsDir,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: `Storage quota = ${this.bytesAmountToString(this.config.storageQuota)}`,
|
label: `Storage quota = ${this.bytesAmountToString(this.config.storageQuota)}`,
|
||||||
action: this.editStorageQuota,
|
action: this.editStorageQuota,
|
||||||
@ -78,20 +60,6 @@ export class ConfigMenu {
|
|||||||
return `${numBytes} Bytes (${value} ${units[index]})`;
|
return `${numBytes} Bytes (${value} ${units[index]})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
editDataDir = async () => {
|
|
||||||
this.config.dataDir = await this.pathSelector.show(
|
|
||||||
this.config.dataDir,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
editLogsDir = async () => {
|
|
||||||
this.config.logsDir = await this.pathSelector.show(
|
|
||||||
this.config.logsDir,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
editStorageQuota = async () => {
|
editStorageQuota = async () => {
|
||||||
this.ui.showInfoMessage("You can use: 'GB' or 'gb', etc.");
|
this.ui.showInfoMessage("You can use: 'GB' or 'gb', etc.");
|
||||||
const newQuota = await this.numberSelector.show(
|
const newQuota = await this.numberSelector.show(
|
||||||
@ -148,15 +116,6 @@ export class ConfigMenu {
|
|||||||
};
|
};
|
||||||
|
|
||||||
saveChangesAndExit = async () => {
|
saveChangesAndExit = async () => {
|
||||||
if (this.config.dataDir !== this.originalDataDir) {
|
|
||||||
// The Codex data-dir is a little special.
|
|
||||||
// Use a dedicated module to move it.
|
|
||||||
await this.dataDirMover.moveDataDir(
|
|
||||||
this.originalDataDir,
|
|
||||||
this.config.dataDir,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.configService.saveConfig();
|
this.configService.saveConfig();
|
||||||
this.ui.showInfoMessage("Configuration changes saved.");
|
this.ui.showInfoMessage("Configuration changes saved.");
|
||||||
this.loop.stopLoop();
|
this.loop.stopLoop();
|
||||||
|
|||||||
@ -3,10 +3,8 @@ import { ConfigMenu } from "./configMenu.js";
|
|||||||
import { mockUiService } from "../__mocks__/service.mocks.js";
|
import { mockUiService } from "../__mocks__/service.mocks.js";
|
||||||
import { mockConfigService } from "../__mocks__/service.mocks.js";
|
import { mockConfigService } from "../__mocks__/service.mocks.js";
|
||||||
import {
|
import {
|
||||||
mockPathSelector,
|
|
||||||
mockNumberSelector,
|
mockNumberSelector,
|
||||||
mockMenuLoop,
|
mockMenuLoop,
|
||||||
mockDataDirMover,
|
|
||||||
} from "../__mocks__/utils.mocks.js";
|
} from "../__mocks__/utils.mocks.js";
|
||||||
|
|
||||||
describe("ConfigMenu", () => {
|
describe("ConfigMenu", () => {
|
||||||
@ -30,9 +28,7 @@ describe("ConfigMenu", () => {
|
|||||||
mockUiService,
|
mockUiService,
|
||||||
mockMenuLoop,
|
mockMenuLoop,
|
||||||
mockConfigService,
|
mockConfigService,
|
||||||
mockPathSelector,
|
|
||||||
mockNumberSelector,
|
mockNumberSelector,
|
||||||
mockDataDirMover,
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -59,11 +55,6 @@ describe("ConfigMenu", () => {
|
|||||||
expect(configMenu.config).toEqual(config);
|
expect(configMenu.config).toEqual(config);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets the original datadir field", async () => {
|
|
||||||
await configMenu.show();
|
|
||||||
expect(configMenu.originalDataDir).toEqual(config.dataDir);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("config menu options", () => {
|
describe("config menu options", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
configMenu.config = config;
|
configMenu.config = config;
|
||||||
@ -74,14 +65,6 @@ describe("ConfigMenu", () => {
|
|||||||
expect(mockUiService.askMultipleChoice).toHaveBeenCalledWith(
|
expect(mockUiService.askMultipleChoice).toHaveBeenCalledWith(
|
||||||
"Select to edit:",
|
"Select to edit:",
|
||||||
[
|
[
|
||||||
{
|
|
||||||
label: `Data path = "${mockConfigService.get().dataDir}"`,
|
|
||||||
action: configMenu.editDataDir,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: `Logs path = "${mockConfigService.get().logsDir}"`,
|
|
||||||
action: configMenu.editLogsDir,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: `Storage quota = 1073741824 Bytes (1024 MB)`,
|
label: `Storage quota = 1073741824 Bytes (1024 MB)`,
|
||||||
action: configMenu.editStorageQuota,
|
action: configMenu.editStorageQuota,
|
||||||
@ -110,24 +93,6 @@ describe("ConfigMenu", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("edits the logs directory", async () => {
|
|
||||||
const originalPath = config.dataDir;
|
|
||||||
mockPathSelector.show.mockResolvedValue("/new-data");
|
|
||||||
await configMenu.editDataDir();
|
|
||||||
|
|
||||||
expect(mockPathSelector.show).toHaveBeenCalledWith(originalPath, false);
|
|
||||||
expect(configMenu.config.dataDir).toEqual("/new-data");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("edits the logs directory", async () => {
|
|
||||||
const originalPath = config.logsDir;
|
|
||||||
mockPathSelector.show.mockResolvedValue("/new-logs");
|
|
||||||
await configMenu.editLogsDir();
|
|
||||||
|
|
||||||
expect(mockPathSelector.show).toHaveBeenCalledWith(originalPath, true);
|
|
||||||
expect(configMenu.config.logsDir).toEqual("/new-logs");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("edits the storage quota", async () => {
|
it("edits the storage quota", async () => {
|
||||||
const originalQuota = config.storageQuota;
|
const originalQuota = config.storageQuota;
|
||||||
const newQuota = 200 * 1024 * 1024;
|
const newQuota = 200 * 1024 * 1024;
|
||||||
@ -249,19 +214,6 @@ describe("ConfigMenu", () => {
|
|||||||
expect(mockMenuLoop.stopLoop).toHaveBeenCalled();
|
expect(mockMenuLoop.stopLoop).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls the dataDirMover when the new datadir is not equal to the original dataDir when saving changes", async () => {
|
|
||||||
config.dataDir = "/original-data";
|
|
||||||
await configMenu.show();
|
|
||||||
|
|
||||||
configMenu.config.dataDir = "/new-data";
|
|
||||||
await configMenu.saveChangesAndExit();
|
|
||||||
|
|
||||||
expect(mockDataDirMover.moveDataDir).toHaveBeenCalledWith(
|
|
||||||
configMenu.originalDataDir,
|
|
||||||
configMenu.config.dataDir,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("discards changes and exits", async () => {
|
it("discards changes and exits", async () => {
|
||||||
await configMenu.discardChangesAndExit();
|
await configMenu.discardChangesAndExit();
|
||||||
|
|
||||||
|
|||||||
@ -1,53 +0,0 @@
|
|||||||
export class DataDirMover {
|
|
||||||
constructor(fsService, uiService) {
|
|
||||||
this.fs = fsService;
|
|
||||||
this.ui = uiService;
|
|
||||||
}
|
|
||||||
|
|
||||||
moveDataDir = (oldPath, newPath) => {
|
|
||||||
if (oldPath === newPath) return;
|
|
||||||
|
|
||||||
// The Codex dataDir is a little strange:
|
|
||||||
// If the old one is empty: The new one should not exist, so that codex creates it with the correct security permissions.
|
|
||||||
// If the old one does exist: We move it.
|
|
||||||
|
|
||||||
if (this.fs.isDir(oldPath)) {
|
|
||||||
this.moveDir(oldPath, newPath);
|
|
||||||
} else {
|
|
||||||
this.ensureDoesNotExist(newPath);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
moveDir = (oldPath, newPath) => {
|
|
||||||
this.ui.showInfoMessage(
|
|
||||||
"Moving Codex data folder...\n" +
|
|
||||||
`From: "${oldPath}"\n` +
|
|
||||||
`To: "${newPath}"`,
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.fs.moveDir(oldPath, newPath);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(
|
|
||||||
this.ui.showErrorMessage(
|
|
||||||
"Error while moving dataDir: " + error.message,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ensureDoesNotExist = (path) => {
|
|
||||||
if (this.fs.isDir(path)) {
|
|
||||||
console.log(
|
|
||||||
this.ui.showInfoMessage(
|
|
||||||
"Warning: the selected data path already exists.\n" +
|
|
||||||
`New data path = "${path}"\n` +
|
|
||||||
"Codex may overwrite data in this folder.\n" +
|
|
||||||
"Codex will fail to start if this folder does not have the required\n" +
|
|
||||||
"security permissions.",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user