You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	| @@ -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); | ||||
| 		} | ||||
| 	}); | ||||
| }); | ||||
|   | ||||
| @@ -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)); | ||||
| 			} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user