From 74848898361998ba5c164e31107053002dab60a5 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Fri, 11 May 2018 21:02:15 +0300 Subject: [PATCH] Fix deletion of old logs --- src/app/filelogger.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/filelogger.cpp b/src/app/filelogger.cpp index 9504c6297..39b2d68f4 100644 --- a/src/app/filelogger.cpp +++ b/src/app/filelogger.cpp @@ -83,21 +83,21 @@ void FileLogger::changePath(const QString& newPath) void FileLogger::deleteOld(const int age, const FileLogAgeType ageType) { QDateTime date = QDateTime::currentDateTime(); - QDir dir(m_path); - - switch (ageType) { - case DAYS: - date = date.addDays(age); - break; - case MONTHS: - date = date.addMonths(age); - break; - default: - date = date.addYears(age); - } + QDir dir(Utils::Fs::branchPath(m_path)); foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) { - if (file.lastModified() < date) + QDateTime modificationDate = file.lastModified(); + switch (ageType) { + case DAYS: + modificationDate = modificationDate.addDays(age); + break; + case MONTHS: + modificationDate = modificationDate.addMonths(age); + break; + default: + modificationDate = modificationDate.addYears(age); + } + if (modificationDate > date) break; Utils::Fs::forceRemove(file.absoluteFilePath()); }