Skip to content

Commit 697bb47

Browse files
committed
fix(release): formalize validation unblockers
1 parent 61c0950 commit 697bb47

3 files changed

Lines changed: 813 additions & 637 deletions

File tree

lib/storage.ts

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const ACCOUNTS_WAL_SUFFIX = ".wal";
4545
const ACCOUNTS_BACKUP_HISTORY_DEPTH = 3;
4646
const BACKUP_COPY_MAX_ATTEMPTS = 5;
4747
const BACKUP_COPY_BASE_DELAY_MS = 10;
48+
const RESET_MARKER_SUFFIX = ".reset-intent";
4849
let storageBackupEnabled = true;
4950
let lastAccountsSaveTimestamp = 0;
5051

@@ -537,6 +538,10 @@ export function getFlaggedAccountsPath(): string {
537538
return join(dirname(getStoragePath()), FLAGGED_ACCOUNTS_FILE_NAME);
538539
}
539540

541+
function getIntentionalResetMarkerPath(path: string): string {
542+
return `${path}${RESET_MARKER_SUFFIX}`;
543+
}
544+
540545
function getLegacyFlaggedAccountsPath(): string {
541546
return join(dirname(getStoragePath()), LEGACY_FLAGGED_ACCOUNTS_FILE_NAME);
542547
}
@@ -1329,7 +1334,8 @@ export async function clearAccounts(): Promise<void> {
13291334
return withStorageLock(async () => {
13301335
const path = getStoragePath();
13311336
const walPath = getAccountsWalPath(path);
1332-
const backupPaths = await getAccountsBackupRecoveryCandidatesWithDiscovery(path);
1337+
const backupPaths =
1338+
await getAccountsBackupRecoveryCandidatesWithDiscovery(path);
13331339
const clearPath = async (targetPath: string): Promise<void> => {
13341340
try {
13351341
await fs.unlink(targetPath);
@@ -1470,12 +1476,17 @@ function normalizeFlaggedStorage(data: unknown): FlaggedAccountStorageV1 {
14701476

14711477
export async function loadFlaggedAccounts(): Promise<FlaggedAccountStorageV1> {
14721478
const path = getFlaggedAccountsPath();
1479+
const resetMarkerPath = getIntentionalResetMarkerPath(path);
14731480
const empty: FlaggedAccountStorageV1 = { version: 1, accounts: [] };
14741481

14751482
try {
14761483
const content = await fs.readFile(path, "utf-8");
14771484
const data = JSON.parse(content) as unknown;
1478-
return normalizeFlaggedStorage(data);
1485+
const loaded = normalizeFlaggedStorage(data);
1486+
if (existsSync(resetMarkerPath)) {
1487+
return empty;
1488+
}
1489+
return loaded;
14791490
} catch (error) {
14801491
const code = (error as NodeJS.ErrnoException).code;
14811492
if (code !== "ENOENT") {
@@ -1550,14 +1561,37 @@ export async function saveFlaggedAccounts(
15501561

15511562
export async function clearFlaggedAccounts(): Promise<void> {
15521563
return withStorageLock(async () => {
1564+
const path = getFlaggedAccountsPath();
1565+
const markerPath = getIntentionalResetMarkerPath(path);
15531566
try {
1554-
await fs.unlink(getFlaggedAccountsPath());
1567+
await fs.writeFile(markerPath, "reset", {
1568+
encoding: "utf-8",
1569+
mode: 0o600,
1570+
});
15551571
} catch (error) {
1556-
const code = (error as NodeJS.ErrnoException).code;
1557-
if (code !== "ENOENT") {
1558-
log.error("Failed to clear flagged account storage", {
1559-
error: String(error),
1560-
});
1572+
log.error("Failed to write flagged reset marker", {
1573+
path,
1574+
markerPath,
1575+
error: String(error),
1576+
});
1577+
throw error;
1578+
}
1579+
const backupPaths =
1580+
await getAccountsBackupRecoveryCandidatesWithDiscovery(path);
1581+
for (const candidate of [path, ...backupPaths, markerPath]) {
1582+
try {
1583+
await fs.unlink(candidate);
1584+
} catch (error) {
1585+
const code = (error as NodeJS.ErrnoException).code;
1586+
if (code !== "ENOENT") {
1587+
log.error("Failed to clear flagged account storage", {
1588+
path: candidate,
1589+
error: String(error),
1590+
});
1591+
if (candidate === path) {
1592+
throw error;
1593+
}
1594+
}
15611595
}
15621596
}
15631597
});

0 commit comments

Comments
 (0)