fix: preserve rotation logs during quit fallback
Route synchronous account-rotation shutdown flushes through the internal log writer so failures under userData/logs retry userData/internal-logs in the same order as runtime writes. Keep buffered lines until a target accepts the full chunk, report the successful fallback as the active path, and retain the buffer when every internal target fails. Cover the real EISDIR primary-path case, complete fallback failure, and main-process quit delegation without launching Electron.
This commit is contained in:
+29
-1
@@ -42,7 +42,7 @@ function createInternalLogWriter(options) {
|
||||
const maxBackups = Number.isFinite(source.maxBackups) ? source.maxBackups : 2;
|
||||
let activePath = null;
|
||||
|
||||
if (!fs || !fs.promises || typeof fs.promises.appendFile !== 'function' || typeof resolveInternalLogPath !== 'function' || typeof fileName !== 'string') {
|
||||
if (!fs || !fs.promises || typeof fs.promises.appendFile !== 'function' || typeof fs.appendFileSync !== 'function' || typeof resolveInternalLogPath !== 'function' || typeof fileName !== 'string') {
|
||||
throw new TypeError('createInternalLogWriter requires fs, fileName and resolveInternalLogPath');
|
||||
}
|
||||
|
||||
@@ -66,8 +66,36 @@ function createInternalLogWriter(options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function appendSync(line, label) {
|
||||
const excludedPaths = new Set();
|
||||
for (let attempt = 0; attempt < retryDelays.length; attempt++) {
|
||||
const targetPath = resolveInternalLogPath(fileName, excludedPaths);
|
||||
if (!targetPath) break;
|
||||
excludedPaths.add(targetPath);
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
||||
rotateLogFile(targetPath, maxBytes, maxBackups);
|
||||
fs.appendFileSync(targetPath, line, 'utf-8');
|
||||
activePath = targetPath;
|
||||
return true;
|
||||
} catch (error) {
|
||||
reportError(label, error);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function flushSync(buffer, label) {
|
||||
if (!Array.isArray(buffer) || buffer.length === 0) return true;
|
||||
if (!appendSync(buffer.join(''), label)) return false;
|
||||
buffer.length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
append,
|
||||
appendSync,
|
||||
flushSync,
|
||||
getActivePath: () => activePath,
|
||||
getPath: () => activePath || resolveInternalLogPath(fileName)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user