Browse Source

Merge pull request #8900 from sledgehammer999/fix_delete_logs

Fix deletion of old logs
adaptive-webui-19844
sledgehammer999 7 years ago committed by GitHub
parent
commit
bde736c18a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/app/filelogger.cpp

14
src/app/filelogger.cpp

@ -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));
foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) {
QDateTime modificationDate = file.lastModified();
switch (ageType) { switch (ageType) {
case DAYS: case DAYS:
date = date.addDays(age); modificationDate = modificationDate.addDays(age);
break; break;
case MONTHS: case MONTHS:
date = date.addMonths(age); modificationDate = modificationDate.addMonths(age);
break; break;
default: default:
date = date.addYears(age); modificationDate = modificationDate.addYears(age);
} }
if (modificationDate > date)
foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) {
if (file.lastModified() < date)
break; break;
Utils::Fs::forceRemove(file.absoluteFilePath()); Utils::Fs::forceRemove(file.absoluteFilePath());
} }

Loading…
Cancel
Save