1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-02 12:47:41 +02:00

Chore: Desktop: Fixes #8598 - Recent logs appear to be deleted (#8605)

This commit is contained in:
Hubert 2023-08-08 07:18:59 -03:00 committed by GitHub
parent ce8470ee7c
commit ae8f32e6b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -12,7 +12,7 @@ describe('RotatingLogs', () => {
try {
dir = await createTempDir();
await createTestLogFile(dir);
let files: string[] = await readdir(dir);
let files = await readdir(dir);
expect(files.find(file => file.match(/^log.txt$/gi))).toBeTruthy();
expect(files.length).toBe(1);
const rotatingLogs: RotatingLogs = new RotatingLogs(dir, 1, 1);
@ -26,7 +26,7 @@ describe('RotatingLogs', () => {
}
});
test('should delete inative log file after 1ms', async () => {
test('should delete inactive log file after 1ms', async () => {
let dir: string;
try {
dir = await createTempDir();
@ -42,4 +42,21 @@ describe('RotatingLogs', () => {
await remove(dir);
}
});
test('should not delete the log-timestamp.txt right after its be created', async () => {
let dir: string;
try {
dir = await createTempDir();
await createTestLogFile(dir);
await msleep(100);
const rotatingLogs: RotatingLogs = new RotatingLogs(dir, 1, 100);
await rotatingLogs.cleanActiveLogFile();
await rotatingLogs.deleteNonActiveLogFiles();
const files = await readdir(dir);
expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeTruthy();
expect(files.length).toBe(1);
} finally {
await remove(dir);
}
});
});

View File

@ -29,7 +29,8 @@ export default class RotatingLogs {
const files: Stat[] = await this.fsDriver().readDirStats(this.logFilesDir);
for (const file of files) {
if (!file.path.match(/^log-[0-9]+.txt$/gi)) continue;
const ageOfTheFile: number = Date.now() - file.birthtime;
const timestamp: number = parseInt(file.path.match(/[0-9]+/g)[0], 10);
const ageOfTheFile: number = Date.now() - timestamp;
if (ageOfTheFile >= this.inactiveMaxAge) {
await this.fsDriver().remove(this.logFileFullpath(file.path));
}