fix: harden automation reconciliation and pause lifecycle
Keep full folder scans recoverable under duplicate protection and classify every discovered file once before automatic admission. Separate manual previews from automatic capacity limits, serialize renderer intake, normalize automation counters and intervals, and make Main authoritative for runtime timestamps. Enforce persistent pause across startup, import, close recovery, resume failures, and reconciliation while preserving read-only paused scans and exactly one activation reconciliation. Restore failed asynchronous rotation chunks, complete automation localization and unlimited queue accessibility, and tighten hidden integration cleanup coverage.
This commit is contained in:
+54
-1
@@ -105,8 +105,61 @@ function createUploadAuditWriter(options) {
|
||||
return createInternalLogWriter({ ...options, fileName: 'upload-audit.log' });
|
||||
}
|
||||
|
||||
function createBufferedInternalLogFlusher(options) {
|
||||
const source = options && typeof options === 'object' ? options : {};
|
||||
const buffer = source.buffer;
|
||||
const writer = source.writer;
|
||||
const schedule = typeof source.schedule === 'function' ? source.schedule : setImmediate;
|
||||
const reportError = typeof source.reportError === 'function' ? source.reportError : () => {};
|
||||
let writing = false;
|
||||
|
||||
if (!Array.isArray(buffer) || !writer || typeof writer.append !== 'function' || typeof writer.flushSync !== 'function') {
|
||||
throw new TypeError('createBufferedInternalLogFlusher requires buffer and writer');
|
||||
}
|
||||
|
||||
function restoreChunk(chunk) {
|
||||
for (let end = chunk.length; end > 0;) {
|
||||
const start = Math.max(0, end - 1024);
|
||||
buffer.splice(0, 0, ...chunk.slice(start, end));
|
||||
end = start;
|
||||
}
|
||||
}
|
||||
|
||||
async function flush(label) {
|
||||
if (writing || buffer.length === 0) return null;
|
||||
const chunk = buffer.splice(0);
|
||||
writing = true;
|
||||
let written = false;
|
||||
try {
|
||||
written = await writer.append(chunk.join(''), label);
|
||||
} catch (error) {
|
||||
reportError(label, error);
|
||||
} finally {
|
||||
writing = false;
|
||||
}
|
||||
if (!written) {
|
||||
restoreChunk(chunk);
|
||||
return false;
|
||||
}
|
||||
if (buffer.length > 0) {
|
||||
try {
|
||||
schedule(() => { void flush(label); });
|
||||
} catch (error) {
|
||||
reportError(label, error);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
flush,
|
||||
flushSync: label => writer.flushSync(buffer, label),
|
||||
isWriting: () => writing
|
||||
};
|
||||
}
|
||||
|
||||
function getLogOpenDirectory(targetPath, fallbackDirectory, pathApi = nodePath) {
|
||||
return typeof targetPath === 'string' && targetPath ? pathApi.dirname(targetPath) : fallbackDirectory;
|
||||
}
|
||||
|
||||
module.exports = { createInternalLogPathResolver, createInternalLogWriter, createUploadAuditWriter, getLogOpenDirectory };
|
||||
module.exports = { createInternalLogPathResolver, createInternalLogWriter, createUploadAuditWriter, createBufferedInternalLogFlusher, getLogOpenDirectory };
|
||||
|
||||
Reference in New Issue
Block a user