Skip to content

Commit b537d6d

Browse files
authored
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
1 parent f02475f commit b537d6d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

source/main/index.ts

+47
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
} from './utils/rtsFlagsSettings';
5555
import { toggleRTSFlagsModeChannel } from './ipc/toggleRTSFlagsModeChannel';
5656
import { containsRTSFlags } from './utils/containsRTSFlags';
57+
import * as fs from 'fs';
5758

5859
/* eslint-disable consistent-return */
5960
// Global references to windows to prevent them from being garbage collected
@@ -133,8 +134,54 @@ const handleWindowClose = async (event: Event | null | undefined) => {
133134
await safeExit();
134135
};
135136

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

0 commit comments

Comments
 (0)