Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix consistent log directory and config dir migration for linux #7665

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ void Application::setupConfigFile()
return;
}

const QStringList filesList =
!Utility::isWindows()
? QDir(oldDir).entryList(QDir::Files).filter(QRegularExpression("^(?!.*\\.log).*$"))
: QDir(oldDir).entryList(QDir::Files);
Comment on lines +542 to +545
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by this change
why do we need to special case windows OS ?

Copy link
Contributor Author

@kaikli kaikli Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the way how the configPath is created in src/libsync/configfile.cpp#L366

For Windows the whole config directory is moved to the data location. On all other platforms only the configuration is moved to the config location ($XDG_CONFIG_DIR) and the log files remain in the data location ($XDG_DATA_DIR).

On all other platforms the sync run logs are moved from this location at startup and then the directory is again used to write the sync run logs into. On the next start of the application the cycle begins again.


if (filesList.isEmpty()) {
return;
}

auto confDir = ConfigFile().configPath();

// macOS 10.11.x does not like trailing slash for rename/move.
Expand All @@ -552,7 +561,6 @@ void Application::setupConfigFile()

// Try to move the files one by one
if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {
const QStringList filesList = QDir(oldDir).entryList(QDir::Files);
qCInfo(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
if (!QFile::rename(oldDir + "/" + name, confDir + "/" + name)) {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <QRegularExpression>

#include "syncrunfilelog.h"
#include "common/utility.h"
#include "libsync/configfile.h"
#include "filesystem.h"
#include <qfileinfo.h>

Expand All @@ -32,7 +32,7 @@ void SyncRunFileLog::start(const QString &folderPath)
{
const qint64 logfileMaxSize = 10 * 1024 * 1024; // 10MiB

const QString logpath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QString logpath = ConfigFile().logDir();
if(!QDir(logpath).exists()) {
QDir().mkdir(logpath);
}
Expand Down
5 changes: 4 additions & 1 deletion src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,10 @@ void ConfigFile::setAutomaticLogDir(bool enabled)

QString ConfigFile::logDir() const
{
const auto defaultLogDir = QString(configPath() + QStringLiteral("/logs"));
const auto defaultLogDir = QString(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+ QStringLiteral("/logs")
);
Comment on lines +1116 to +1119
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would create some behavior changes ?

Copy link
Contributor Author

@kaikli kaikli Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because I find it better to place the log files into the data location ($XDG_DATA_DIR) instead of the config location like the logpath of the sync run logs.

Currently the ./logs directory is located in the config directory, but the sync run logs are written to the data location ($XDG_DATA_DIR). And because this is inconsistent I changed the default log directory to the $XDG_DATA_DIR and use the same directory for the sync run logs logPath.

On Windows the log and config directories are the same because of the way the config path in src/libsync/configfile.cpp#L366 is generated, but on all other platforms it makes more sense to keep them separated.

QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(QLatin1String(logDirC), defaultLogDir).toString();
}
Expand Down