Skip to content

Commit

Permalink
Migrate old conf file to new location on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Aug 18, 2023
1 parent b8bcf23 commit c5ca0bb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ void Config::init(const QString& configFileName, const QString& localConfigFileN
QDir().rmdir(QFileInfo(localConfigFileName).absolutePath());
}

#if defined(Q_OS_LINUX)
// Upgrade from previous KeePassXC version which stores its config
// in ~/.cache on Linux instead of ~/.local/state.
// Move file to correct location before continuing.
QString oldLocalConfigPath;
oldLocalConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/keepassxc";
QString suffix;
#ifdef QT_DEBUG
suffix = "_debug";
#endif
oldLocalConfigPath += QString("/keepassxc%1.ini").arg(suffix);
oldLocalConfigPath = QDir::toNativeSeparators(oldLocalConfigPath);
if (!localConfigFileName.isEmpty() && !QFile::exists(localConfigFileName) && QFile::exists(oldLocalConfigPath)) {
QDir().mkpath(QFileInfo(localConfigFileName).absolutePath());
QFile::copy(oldLocalConfigPath, localConfigFileName);
QFile::remove(oldLocalConfigPath);
QDir().rmdir(QFileInfo(oldLocalConfigPath).absolutePath());
}
#endif

m_settings.reset(new QSettings(configFileName, QSettings::IniFormat));
if (!localConfigFileName.isEmpty() && configFileName != localConfigFileName) {
m_localSettings.reset(new QSettings(localConfigFileName, QSettings::IniFormat));
Expand Down

0 comments on commit c5ca0bb

Please sign in to comment.