Fix blocking upload logging and recover DoodStream socket failures; release 2.1.67
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
1 parent
5a0cad0ca5
commit
9b06b4f852
10 files changed
+254
-114
No files matched your search
+26
-1
@@ -55,4 +55,29 @@ function maybeRotateLogFile(filePath, maxBytes, maxBackups = 3, log = () => {})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getRotatedLogPath, maybeRotateLogFile };
|
||||
async function maybeRotateLogFileAsync(filePath, maxBytes, maxBackups = 3, log = () => {}) {
|
||||
if (!filePath || !Number.isFinite(maxBytes) || maxBytes <= 0) return false;
|
||||
let size;
|
||||
try {
|
||||
size = (await fs.promises.stat(filePath)).size;
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') log(`logRotation: stat ${filePath} failed: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
if (size <= maxBytes) return false;
|
||||
try { await fs.promises.unlink(getRotatedLogPath(filePath, maxBackups)); } catch {}
|
||||
for (let i = maxBackups - 1; i >= 1; i--) {
|
||||
try { await fs.promises.rename(getRotatedLogPath(filePath, i), getRotatedLogPath(filePath, i + 1)); } catch {}
|
||||
}
|
||||
try {
|
||||
const backupPath = getRotatedLogPath(filePath, 1);
|
||||
await fs.promises.rename(filePath, backupPath);
|
||||
log(`logRotation: rotated ${filePath} (${(size / 1024 / 1024).toFixed(1)} MB) → ${backupPath}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
log(`logRotation: rename ${filePath} failed: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getRotatedLogPath, maybeRotateLogFile, maybeRotateLogFileAsync };
|
||||
Reference in new issue
Block a user