From dea09b590f6c89d9c339fee73e654d31e51c8a13 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 30 Jul 2019 14:04:34 +0200 Subject: [PATCH] LogDir: Compress last logfile on restart For #7353 --- src/libsync/logger.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index e62ca517682..27e056f676b 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -266,7 +266,7 @@ void Logger::enterNextLogFile() // Expire old log files and deal with conflicts QStringList files = dir.entryList(QStringList("*owncloud.log.*"), - QDir::Files); + QDir::Files, QDir::Name); QRegExp rx(R"(.*owncloud\.log\.(\d+).*)"); int maxNumber = -1; foreach (const QString &s, files) { @@ -286,10 +286,15 @@ void Logger::enterNextLogFile() auto previousLog = _logFile.fileName(); setLogFile(dir.filePath(newLogName)); - if (!previousLog.isEmpty()) { - QString compressedName = previousLog + ".gz"; - if (compressLog(previousLog, compressedName)) { - QFile::remove(previousLog); + // Compress the previous log file. On a restart this can be the most recent + // log file. + auto logToCompress = previousLog; + if (logToCompress.isEmpty() && files.size() > 0 && !files.last().endsWith(".gz")) + logToCompress = dir.absoluteFilePath(files.last()); + if (!logToCompress.isEmpty()) { + QString compressedName = logToCompress + ".gz"; + if (compressLog(logToCompress, compressedName)) { + QFile::remove(logToCompress); } else { QFile::remove(compressedName); }