fix: ensure log files are zipped before deletion

This commit is contained in:
biersoeckli
2025-02-01 16:27:34 +00:00
parent 8415f6bc01
commit 6ca354e0fc

View File

@@ -10,6 +10,7 @@ import path from "path";
import { create } from 'tar'
import scheduleService from "./schedule.service";
import { DownloadableAppLogsModel } from "../../../shared/model/downloadable-app-logs.model";
import { CommandExecutorUtils } from "../../../server/utils/command-executor.utils";
class AppLogsService {
@@ -124,11 +125,20 @@ class AppLogsService {
// create tar.gz file from all log files
const logFilePath = PathUtils.appLogsFile(app.id, startOfDay);
await FsUtils.deleteFileIfExists(logFilePath); // delete existing log file --> new one will be created
/*
// this doesn't work, because it doesn't wait for the file to be written
await create({
gzip: true,
file: logFilePath,
cwd: PathUtils.appLogsFolder(app.id)
}, logPathsWritten);
*/
await CommandExecutorUtils.runCommand(`tar -czf ${logFilePath} ${logPathsWritten.join(' ')}`);
if (!FsUtils.fileExists(logFilePath)) {
throw new Error(`Error creating tar file for logs of app ${app.id} on path ${logFilePath}`);
}
for (const logPath of logPathsWritten) {
await FsUtils.deleteFileIfExists(logPath);