Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b54a34e

Browse filesBrowse files
[LW-12241] Update index.ts to cater for the cleardown of ledger state if not alr… (#3276)
* Update index.ts to cater for the cleardown of ledger state if not already flagged as done Update index.ts to cater for the cleardown of ledger state if not already flagged as done * Moved node-fs imports to resolve 'common' import for ipc * Update source/main/index.ts Co-authored-by: Szymon Masłowski <szymon.maslowski@iohk.io> * moved from console.log to logger.info + console.error to logger.error as suggested --------- Co-authored-by: Szymon Masłowski <szymon.maslowski@iohk.io>
1 parent f02475f commit b54a34e
Copy full SHA for b54a34e

File tree

Expand file treeCollapse file tree

1 file changed

+44
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+44
-0
lines changed

‎source/main/index.ts

Copy file name to clipboardExpand all lines: source/main/index.ts
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os from 'os';
22
import path from 'path';
3+
import * as fs from 'fs';
34
import { app, dialog, BrowserWindow, screen, shell } from 'electron';
45
import type { Event } from 'electron';
56
import EventEmitter from 'events';
@@ -24,6 +25,7 @@ import {
2425
RTS_FLAGS,
2526
stateDirectoryPath,
2627
} from './config';
28+
2729
import { setupCardanoNode } from './cardano/setup';
2830
import { CardanoNode } from './cardano/CardanoNode';
2931
import { safeExitWithCode } from './utils/safeExitWithCode';
@@ -133,8 +135,50 @@ const handleWindowClose = async (event: Event | null | undefined) => {
133135
await safeExit();
134136
};
135137

138+
const clearLedger = async () => {
139+
const flagFileShortName = 'has_upgraded_to_pv_10';
140+
const chainLedgerDir = 'chain/ledger';
141+
142+
const flagFileLongName = path.join(
143+
launcherConfig.stateDir,
144+
flagFileShortName
145+
);
146+
147+
// Check if the flag file exists
148+
if (fs.existsSync(flagFileLongName)) {
149+
logger.info(`${flagFileLongName} found. NoHskpg.`);
150+
} else {
151+
try {
152+
const chainLedgerLongName = path.join(
153+
launcherConfig.stateDir,
154+
chainLedgerDir
155+
);
156+
157+
const files = fs.readdirSync(chainLedgerLongName);
158+
159+
for (const file of files) {
160+
// DelIterator
161+
const filePath = path.join(chainLedgerLongName, file);
162+
if (fs.lstatSync(filePath).isFile()) {
163+
// ?it's a file
164+
fs.unlinkSync(filePath);
165+
logger.info(`HskpgDone: ${filePath}`);
166+
}
167+
}
168+
169+
// Create v10-upgraded completed marker
170+
fs.writeFileSync(flagFileLongName, 'HskpgNwFlag');
171+
} catch (err) {
172+
logger.error(`Error removing files: ${err}`);
173+
}
174+
}
175+
};
176+
136177
const onAppReady = async () => {
137178
setupLogging();
179+
180+
await clearLedger();
181+
138182
await logUsedVersion(
139183
environment.version,
140184
path.join(pubLogsFolderPath, 'Daedalus-versions.json')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.