Skip to content

Commit 74c0527

Browse files
committed
refactor(migration): rename functions.
Signed-off-by: Camila Ayres <[email protected]>
1 parent 7b69fc6 commit 74c0527

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

src/gui/application.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,21 @@ Application::Application(int &argc, char **argv)
264264
parseOptions(arguments());
265265

266266
ConfigFile configFile;
267-
268267
// First check if there is an existing config from a previous version
269-
if (configFile.exists() && configVersionMigration()) {
268+
if (const auto configExists = configFile.exists(); configExists && configVersionMigration()) {
270269
qCWarning(lcApplication) << "Config version migration was not possible.";
271-
} else {
272-
// check legacy location for existing config files
273-
// if (const auto genericConfigLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + APPLICATION_CONFIG_NAME;
274-
// !configFile.setupConfigFolderFromLegacyLocation(genericConfigLocation)) {
275-
// qCWarning(lcApplication) << "Setup of config folder and files from legacy location" << genericConfigLocation << "failed.";
276-
// } else
277-
278-
if (const auto appDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
279-
!configFile.setupConfigFolderFromLegacyLocation(appDataLocation)) {
280-
qCWarning(lcApplication) << "Setup of config folder and files from legacy location" << appDataLocation << "failed.";
270+
} else if (!configExists) {
271+
// look for previous used application name for config folder.
272+
if (const auto genericConfigLocation = QString(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + APPLICATION_CONFIG_NAME);
273+
configFile.copyConfigFolderFromLegacyLocation(genericConfigLocation)) {
274+
qCWarning(lcApplication) << "Copy of config folder and files from legacy location" << genericConfigLocation << "suceeded.";
275+
276+
// app data folder
277+
} else if (const auto appDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
278+
configFile.copyConfigFolderFromLegacyLocation(genericConfigLocation)) {
279+
qCWarning(lcApplication) << "Copy of config folder and files from legacy location" << appDataLocation << "suceeded.";
280+
} else {
281+
configFile.findLegacyClientConfigFile();
281282
}
282283
}
283284

src/libsync/configfile.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ static constexpr int deleteFilesThresholdDefaultValue = 100;
115115
constexpr auto accountsC = "Accounts";
116116
constexpr auto legacyRelativeConfigLocationC = "/ownCloud/owncloud.cfg";
117117
constexpr auto legacyCfgFileNameC = "owncloud.cfg";
118-
constexpr auto unbrandedRelativeConfigLocationC = "/copyNextcloud/copyNextcloud.cfg";
119-
constexpr auto unbrandedCfgFileNameC = "copyNextcloud.cfg";
118+
constexpr auto unbrandedRelativeConfigLocationC = "/Nextcloud/nextcloud.cfg";
119+
constexpr auto unbrandedCfgFileNameC = "nextcloud.cfg";
120120
}
121121

122122
namespace OCC {
@@ -1342,7 +1342,7 @@ void ConfigFile::setDiscoveredLegacyConfigFile(const QString &discoveredLegacyCo
13421342
_discoveredLegacyConfigFile = discoveredLegacyConfigFile;
13431343
}
13441344

1345-
bool ConfigFile::setupConfigFolderFromLegacyLocation(const QString &legacyLocation) const
1345+
bool ConfigFile::copyConfigFolderFromLegacyLocation(const QString &legacyLocation) const
13461346
{
13471347
// Migrate from version <= 2.4
13481348
qApp->setApplicationName(Theme::instance()->appNameGUI());
@@ -1395,27 +1395,26 @@ QT_WARNING_POP
13951395
return false;
13961396
}
13971397

1398-
QString ConfigFile::findLegacyClientConfigFile() const
1398+
void ConfigFile::findLegacyClientConfigFile()
13991399
{
14001400
qCInfo(lcConfigFile) << "Migrate: restoreFromLegacySettings, checking settings group"
14011401
<< Theme::instance()->appName();
14021402

14031403
// try to open the correctly themed settings
14041404
auto settings = ConfigFile::settingsWithGroup(Theme::instance()->appName());
14051405

1406-
QString validLegacyConfigFile;
14071406
// if the settings file could not be opened, the childKeys list is empty
14081407
// then try to load settings from a very old place
14091408
if (settings->childKeys().isEmpty()) {
14101409
// Legacy settings used QDesktopServices to get the location for the config folder in 2.4 and before
14111410
const auto legacy2_4CfgSettingsLocation = QString(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/data"));
14121411
const auto legacy2_4CfgFileParentFolder = legacy2_4CfgSettingsLocation.left(legacy2_4CfgSettingsLocation.lastIndexOf('/'));
14131412

1414-
// 2.5+ (rest of 2.x series)
1413+
// 2.5+ (rest of 2.x series)
14151414
const auto legacy2_5CfgSettingsLocation = QStandardPaths::writableLocation(Utility::isWindows() ? QStandardPaths::AppDataLocation : QStandardPaths::AppConfigLocation);
14161415
const auto legacy2_5CfgFileParentFolder = legacy2_5CfgSettingsLocation.left(legacy2_5CfgSettingsLocation.lastIndexOf('/'));
14171416

1418-
// Now try the locations we use today
1417+
// Now try the locations we use today
14191418
const auto fullLegacyCfgFile = QDir::fromNativeSeparators(settings->fileName());
14201419
const auto legacyCfgFileParentFolder = fullLegacyCfgFile.left(fullLegacyCfgFile.lastIndexOf('/'));
14211420
const auto legacyCfgFileGrandParentFolder = legacyCfgFileParentFolder.left(legacyCfgFileParentFolder.lastIndexOf('/'));
@@ -1443,8 +1442,7 @@ QString ConfigFile::findLegacyClientConfigFile() const
14431442

14441443
if (const QFileInfo configFileInfo(configFile);
14451444
configFileInfo.exists() && configFileInfo.isReadable()) {
1446-
qCInfo(lcConfigFile) << "Migrate: checking old config " << configFile;
1447-
validLegacyConfigFile = configFile;
1445+
qCInfo(lcConfigFile) << "Migrate: saving old config file" << configFile;
14481446
setDiscoveredLegacyConfigFile(configFileInfo.filePath());
14491447
setDiscoveredLegacyConfigPath(configFileInfo.canonicalPath());
14501448
break;
@@ -1453,7 +1451,5 @@ QString ConfigFile::findLegacyClientConfigFile() const
14531451
}
14541452
}
14551453
}
1456-
1457-
return validLegacyConfigFile;
14581454
}
14591455
}

src/libsync/configfile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ class OWNCLOUDSYNC_EXPORT ConfigFile
266266
static constexpr char showChatNotificationsC[] = "showChatNotifications";
267267
static constexpr char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane";
268268

269-
bool setupConfigFolderFromLegacyLocation(const QString &legacyLocation) const;
269+
bool copyConfigFolderFromLegacyLocation(const QString &legacyLocation) const;
270270
/**
271271
* Looks for config files with different names from older client versions
272272
* in different locations
273273
*
274274
* Returns the found config file path found.
275275
*/
276-
[[nodiscard]] QString findLegacyClientConfigFile() const;
276+
void findLegacyClientConfigFile();
277277

278278
protected:
279279
[[nodiscard]] QVariant getPolicySetting(const QString &policy, const QVariant &defaultValue = QVariant()) const;

0 commit comments

Comments
 (0)