Make upload history access asynchronous and release 2.1.70
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe committed 2026-10-18 03:03:58 +02:00
1 parent 1e289ee49b
commit 8f5bcd94bf
5 files changed
+42 -31

No files matched your search

+26 -16
View File
@@ -207,7 +207,7 @@ class ConfigStore {
}
}
_readHistoryFile() {
_readHistoryFileSync() {
try {
const raw = fs.readFileSync(this.historyPath, 'utf-8');
if (!raw || raw.trim().length < 2) return [];
@@ -220,6 +220,24 @@ class ConfigStore {
}
}
async _readHistoryFile() {
let raw;
try {
raw = await fs.promises.readFile(this.historyPath, 'utf-8');
} catch (error) {
if (error.code === 'ENOENT') return [];
throw error;
}
if (!raw || !raw.trim()) return [];
let parsed;
try { parsed = JSON.parse(raw); } catch {}
if (Array.isArray(parsed)) return parsed;
if (parsed && Array.isArray(parsed.history)) return parsed.history;
const error = new Error('Die Verlaufsdatei ist beschädigt und wurde nicht verändert');
error.code = 'HISTORY_CORRUPT';
throw error;
}
_writeHistoryFileDurable(arr) {
const tmp = this.historyPath + '.tmp';
const fd = fs.openSync(tmp, 'w');
@@ -267,14 +285,14 @@ class ConfigStore {
_migrateHistory() {
try {
if (fs.existsSync(this.historyPath)) {
this._historyMigrated = Array.isArray(this._readHistoryFile());
this._historyMigrated = Array.isArray(this._readHistoryFileSync());
return;
}
let cfg = null;
try { cfg = this._readAndParse(this.filePath); } catch {}
const hist = (cfg && Array.isArray(cfg.history)) ? cfg.history : [];
this._writeHistoryFileDurable(hist);
const check = this._readHistoryFile();
const check = this._readHistoryFileSync();
if (Array.isArray(check) && check.length === hist.length) {
if (hist.length > 0) {
try { fs.copyFileSync(this.filePath, this.filePath + '.pre-history-split.bak'); } catch {}
@@ -769,9 +787,9 @@ class ConfigStore {
});
}
loadHistory() {
async loadHistory() {
if (this._historyMigrated) {
return this._readHistoryFile() || [];
return this._readHistoryFile();
}
const config = this.load();
return config.history || [];
@@ -802,12 +820,8 @@ class ConfigStore {
appendHistory(entry) {
if (this._historyMigrated) {
return this._enqueueHistoryWrite(() => {
const cur = this._readHistoryFile();
if (cur === null && fs.existsSync(this.historyPath)) {
throw new Error('Die Verlaufsdatei ist beschädigt und wurde nicht verändert');
}
const arr = cur || [];
return this._enqueueHistoryWrite(async () => {
const arr = await this._readHistoryFile();
arr.push(entry);
const gs = this.load().globalSettings;
const retention = (gs && gs.historyRetention) || 'all';
@@ -828,11 +842,7 @@ class ConfigStore {
const dryRun = !!opts.dryRun;
if (this._historyMigrated) {
return this._enqueueHistoryWrite(async () => {
const storedHistory = this._readHistoryFile();
if (storedHistory === null && fs.existsSync(this.historyPath)) {
throw new Error('Die Verlaufsdatei ist beschädigt und wurde nicht verändert');
}
const current = storedHistory || [];
const current = await this._readHistoryFile();
const beforeBatches = current.length;
const beforeRows = countHistoryRows(current);
const pruned = applyHistoryRetention(current, retention, Date.now());