1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-23 04:54:18 +00:00

Fix deletion of old logs

This commit is contained in:
sledgehammer999 2018-05-11 21:02:15 +03:00
parent 768262ae64
commit 7484889836
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2

View File

@ -83,21 +83,21 @@ void FileLogger::changePath(const QString& newPath)
void FileLogger::deleteOld(const int age, const FileLogAgeType ageType) void FileLogger::deleteOld(const int age, const FileLogAgeType ageType)
{ {
QDateTime date = QDateTime::currentDateTime(); QDateTime date = QDateTime::currentDateTime();
QDir dir(m_path); QDir dir(Utils::Fs::branchPath(m_path));
switch (ageType) {
case DAYS:
date = date.addDays(age);
break;
case MONTHS:
date = date.addMonths(age);
break;
default:
date = date.addYears(age);
}
foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) { 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; break;
Utils::Fs::forceRemove(file.absoluteFilePath()); Utils::Fs::forceRemove(file.absoluteFilePath());
} }