Skip to content

Commit

Permalink
fix config dir migration on linux
Browse files Browse the repository at this point in the history
Signed-off-by: kaikli <[email protected]>
  • Loading branch information
kaikli committed Dec 16, 2024
1 parent f00f320 commit 0266705
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,30 +529,30 @@ void Application::setupConfigFile()
setApplicationName(_theme->appName());

auto oldDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);

// macOS 10.11.x does not like trailing slash for rename/move.
if (oldDir.endsWith('/')) {
oldDir.chop(1);
}
if (oldDir.endsWith('/')) oldDir.chop(1); // macOS 10.11.x does not like trailing slash for rename/move.

if (!QFileInfo(oldDir).isDir()) {
return;
}

auto confDir = ConfigFile().configPath();
const QStringList filesList =
!Utility::isWindows()
? QDir(oldDir).entryList(QDir::Files).filter(QRegularExpression("^(?!.*\\.log).*$"))
: QDir(oldDir).entryList(QDir::Files);

// macOS 10.11.x does not like trailing slash for rename/move.
if (confDir.endsWith('/')) {
confDir.chop(1);
if (filesList.isEmpty()) {
return;
}

auto confDir = ConfigFile().configPath();
if (confDir.endsWith('/')) confDir.chop(1); // macOS 10.11.x does not like trailing slash for rename/move.

qCInfo(lcApplication) << "Migrating old config from" << oldDir << "to" << confDir;
if (!QFile::rename(oldDir, confDir)) {
qCWarning(lcApplication) << "Failed to move the old config directory to its new location (" << oldDir << "to" << confDir << ")";

// 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

0 comments on commit 0266705

Please sign in to comment.