From eecd11a51b915641313148d12d16e53fd24551c0 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 16 Apr 2020 11:55:47 +0200 Subject: [PATCH] Move log folder when request it by copying log files in the new folder --- .../src/components/settings/SettingsModel.cpp | 18 ++++++++++++++---- .../ui/views/App/Settings/SettingsAdvanced.js | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/linphone-app/src/components/settings/SettingsModel.cpp b/linphone-app/src/components/settings/SettingsModel.cpp index 6025ad9ba..69bcb3291 100644 --- a/linphone-app/src/components/settings/SettingsModel.cpp +++ b/linphone-app/src/components/settings/SettingsModel.cpp @@ -1169,10 +1169,20 @@ QString SettingsModel::getLogsFolder () const { } void SettingsModel::setLogsFolder (const QString &folder) { - // Do not update path in linphone core. - // Just update the config file. - mConfig->setString(UiSection, "logs_folder", Utils::appStringToCoreString(folder)); - +// Copy all logs files in the new folder path to keep trace of old logs + std::string logPath = Utils::appStringToCoreString(folder); + QDir oldDirectory(Utils::coreStringToAppString(CoreManager::getInstance()->getCore()->getLogCollectionPath())); + QFileInfoList logsFiles = oldDirectory.entryInfoList(QStringList("*.log"));// Get all log files + for(int i = 0 ; i < logsFiles.size() ; ++i){ + int count = 0; + QString fileName = logsFiles[i].fileName(); + while( QFile::exists(folder+QDir::separator()+fileName))// assure unicity of backup files + fileName = logsFiles[i].baseName()+"_"+QString::number(++count)+logsFiles[i].completeSuffix(); + if(QFile::copy(logsFiles[i].filePath(), folder+QDir::separator()+fileName)) + QFile::remove(logsFiles[i].filePath()); + } + mConfig->setString(UiSection, "logs_folder", logPath); // Update configuration file + CoreManager::getInstance()->getCore()->setLogCollectionPath(logPath); // Update Core to the new path. Liblinphone should update it. emit logsFolderChanged(folder); } diff --git a/linphone-app/ui/views/App/Settings/SettingsAdvanced.js b/linphone-app/ui/views/App/Settings/SettingsAdvanced.js index cfd48d423..a13e07ac9 100644 --- a/linphone-app/ui/views/App/Settings/SettingsAdvanced.js +++ b/linphone-app/ui/views/App/Settings/SettingsAdvanced.js @@ -45,9 +45,9 @@ function handleLogsUploaded (url) { '?subject=' + encodeURIComponent('Desktop Linphone Log') + '&body=' + encodeURIComponent(url) )) - sendLogsBlock.stop(qsTr('logsMailerSuccess').replace('%1', encodeURIComponent(url))) + sendLogsBlock.stop(qsTr('logsMailerSuccess').replace('%1', url)) else - sendLogsBlock.stop(qsTr('logsMailerFailed').replace('%1', encodeURIComponent(url))) + sendLogsBlock.stop(qsTr('logsMailerFailed').replace('%1', url)) } else { sendLogsBlock.stop(qsTr('logsUploadFailed')) }