Persist successful watched-file uploads in a dedicated fsync-backed ledger before exposing completion to the renderer. Match entries by normalized full path, hoster, size, and modification time so restart reconciliation skips unchanged completed files while changed files and explicit manual retries remain available. Remove restored queue ghosts from the ledger even when history and user upload logging are unavailable. Preserve per-hoster partial completion, capture missing file metadata asynchronously, fail closed on corrupted or unwritable evidence, and keep local persistence failures outside automatic upload retries. Stream managed upload logs with bounded lines, bytes, files, directories, and result counts. Include numbered rotations, reject unconfirmed rows, share concurrent scans through a generation-safe cache, invalidate after successful appends, avoid synchronous configuration and directory reads, and close streams on every path.
This commit is contained in:
@@ -2,6 +2,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const secretStore = require('./secret-store');
|
||||
const { normalizeLogMode } = require('./log-mode');
|
||||
const { mergeAutomationCompletions, normalizeAutomationCompletion, removeAutomationCompletions } = require('./automation-control');
|
||||
|
||||
const HOSTER_SETTINGS_DEFAULTS = {
|
||||
retries: 3,
|
||||
@@ -196,8 +197,11 @@ class ConfigStore {
|
||||
: path.join(__dirname, '..');
|
||||
this.filePath = path.join(dir, 'electron-config.json');
|
||||
this.historyPath = path.join(dir, 'electron-history.json');
|
||||
this.automationCompletionPath = path.join(dir, 'automation-completions.json');
|
||||
this._writeQueue = Promise.resolve(); // Serializes all writes to prevent race conditions
|
||||
this._historyWriteQueue = Promise.resolve();
|
||||
this._automationCompletionWriteQueue = Promise.resolve();
|
||||
this._automationCompletionCache = null;
|
||||
this._pendingWriteOperations = new Set();
|
||||
this._writesQuiesced = false;
|
||||
this._historyMigrated = false;
|
||||
@@ -622,6 +626,71 @@ class ConfigStore {
|
||||
}, options);
|
||||
}
|
||||
|
||||
async _readAutomationCompletionFile() {
|
||||
try {
|
||||
const raw = await fs.promises.readFile(this.automationCompletionPath, 'utf8');
|
||||
const parsed = JSON.parse(raw);
|
||||
if (!parsed || parsed.version !== 1 || !Array.isArray(parsed.entries)) throw new Error('Automatik-Abschlussdatei ist ungültig');
|
||||
if (parsed.entries.some(entry => !normalizeAutomationCompletion(entry))) throw new Error('Automatik-Abschlussdatei ist ungültig');
|
||||
return mergeAutomationCompletions([], parsed.entries);
|
||||
} catch (error) {
|
||||
if (error?.code === 'ENOENT') return [];
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async _writeAutomationCompletionFile(entries) {
|
||||
const target = this.automationCompletionPath;
|
||||
const temporary = `${target}.tmp`;
|
||||
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
||||
const handle = await fs.promises.open(temporary, 'w');
|
||||
try {
|
||||
await handle.writeFile(JSON.stringify({ version: 1, entries }), 'utf8');
|
||||
await handle.sync();
|
||||
} finally {
|
||||
await handle.close();
|
||||
}
|
||||
await fs.promises.rename(temporary, target);
|
||||
}
|
||||
|
||||
_enqueueAutomationCompletionWrite(operation) {
|
||||
const result = this._automationCompletionWriteQueue.then(operation);
|
||||
this._automationCompletionWriteQueue = result.catch(() => {});
|
||||
return result;
|
||||
}
|
||||
|
||||
async loadAutomationCompletions() {
|
||||
await this._automationCompletionWriteQueue;
|
||||
if (!this._automationCompletionCache) this._automationCompletionCache = await this._readAutomationCompletionFile();
|
||||
return this._clone(this._automationCompletionCache);
|
||||
}
|
||||
|
||||
saveAutomationCompletions(entries) {
|
||||
const incoming = this._clone(Array.isArray(entries) ? entries : []);
|
||||
return this._enqueueAutomationCompletionWrite(async () => {
|
||||
const current = this._automationCompletionCache || await this._readAutomationCompletionFile();
|
||||
const next = mergeAutomationCompletions(current, incoming);
|
||||
await this._writeAutomationCompletionFile(next);
|
||||
this._automationCompletionCache = next;
|
||||
return this._clone(next);
|
||||
});
|
||||
}
|
||||
|
||||
clearAutomationCompletions(removals) {
|
||||
const requested = this._clone(Array.isArray(removals) ? removals : []);
|
||||
return this._enqueueAutomationCompletionWrite(async () => {
|
||||
const current = this._automationCompletionCache || await this._readAutomationCompletionFile();
|
||||
const next = removeAutomationCompletions(current, requested);
|
||||
await this._writeAutomationCompletionFile(next);
|
||||
this._automationCompletionCache = next;
|
||||
return this._clone(next);
|
||||
});
|
||||
}
|
||||
|
||||
async drainAutomationCompletionWrites() {
|
||||
await this._automationCompletionWriteQueue;
|
||||
}
|
||||
|
||||
saveLastBrowseDirectory(directory) {
|
||||
const snapshot = String(directory || '').trim();
|
||||
return this._enqueueWrite(() => {
|
||||
|
||||
Reference in New Issue
Block a user