mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-24 22:15:57 +03:00
Migrate legacy user defined exclude file.
- Refactor ConfigFile::setupDefaultExcludeFilePaths. - Refactor ConfigFile::excludeFile. - Fix code style. Signed-off-by: Camila <hello@camila.codes>
This commit is contained in:
parent
6f38545e09
commit
9dbb072858
4 changed files with 39 additions and 38 deletions
|
@ -184,7 +184,7 @@ int FolderMan::setupFolders()
|
|||
|
||||
qCInfo(lcFolderMan) << "Setup folders from settings file";
|
||||
|
||||
// this is done in Application::configVersionMigration
|
||||
// this is done in Application::configVersionMigration
|
||||
QStringList skipSettingsKeys;
|
||||
backwardMigrationSettingsKeys(&skipSettingsKeys, &skipSettingsKeys);
|
||||
const auto accounts = AccountManager::instance()->accounts();
|
||||
|
@ -353,10 +353,10 @@ int FolderMan::setupFoldersMigration()
|
|||
qCInfo(lcFolderMan) << "Setup folders from " << configPath << "(migration)";
|
||||
|
||||
QDir dir(configPath);
|
||||
//We need to include hidden files just in case the alias starts with '.'
|
||||
// We need to include hidden files just in case the alias starts with '.'
|
||||
dir.setFilter(QDir::Files | QDir::Hidden);
|
||||
//Exclude previous backed up configs e.g. oc.cfg.backup_20230831_133749_4.0.0
|
||||
//only need the current config in use by the legacy application
|
||||
// Exclude previous backed up configs e.g. oc.cfg.backup_20230831_133749_4.0.0
|
||||
// only need the current config in use by the legacy application
|
||||
const auto dirFiles = dir.entryList({"*.cfg"});
|
||||
|
||||
// Normally there should be only one account when migrating. TODO: Should assume only one legacy config file
|
||||
|
@ -565,10 +565,10 @@ void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Accoun
|
|||
if (const auto folder = addFolderInternal(folderDefinition, accountState, std::make_unique<VfsOff>())) {
|
||||
auto ok = true;
|
||||
if (const auto legacyBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
|
||||
&ok);ok && !legacyBlacklist.isEmpty()) {
|
||||
&ok); ok && !legacyBlacklist.isEmpty()) {
|
||||
qCInfo(lcFolderMan) << "Legacy selective sync list found:" << legacyBlacklist;
|
||||
for(const auto &legacyFolder : legacyBlacklist) {
|
||||
folder->migrateBlackListPath(legacyFolder);
|
||||
for (const auto &legacyFolder : legacyBlacklist) {
|
||||
folder->migrateBlackListPath(legacyFolder);
|
||||
}
|
||||
} else {
|
||||
qCInfo(lcFolderMan) << "There was a problem retriving the database selective sync for " << folder;
|
||||
|
@ -576,7 +576,7 @@ void FolderMan::setupFolderFromOldConfigFile(const QString &fileNamePath, Accoun
|
|||
|
||||
const auto settingLegacyBlacklist = settings.value(QLatin1String("blackList")).toStringList();
|
||||
if (!settingLegacyBlacklist.empty()) {
|
||||
//migrate settings
|
||||
// migrate settings
|
||||
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, settingLegacyBlacklist);
|
||||
settings.remove(QLatin1String("blackList"));
|
||||
// FIXME: If you remove this codepath, you need to provide another way to do
|
||||
|
|
|
@ -110,10 +110,10 @@ void UserInfo::slotUpdateLastInfo(const QJsonDocument &json)
|
|||
|
||||
AccountPtr account = _accountState->account();
|
||||
|
||||
if (const auto newUserId = objData.value("id").toString();!newUserId.isEmpty()) {
|
||||
if (const auto newUserId = objData.value("id").toString(); !newUserId.isEmpty()) {
|
||||
if (QString::compare(account->davUser(), newUserId, Qt::CaseInsensitive) != 0) {
|
||||
// TODO: the error message should be in the UI
|
||||
qInfo() << "Authed with the wrong user! Please login with the account:" << account->prettyName();
|
||||
qInfo() << "Authenticated with the wrong user! Please login with the account:" << account->prettyName();
|
||||
if (const auto cred = account->credentials()) {
|
||||
account->credentials()->askFromUser();
|
||||
}
|
||||
|
|
|
@ -368,32 +368,27 @@ QString ConfigFile::configPath() const
|
|||
return Utility::trailingSlashPath(_confDir);
|
||||
}
|
||||
|
||||
static const QLatin1String exclFile("sync-exclude.lst");
|
||||
static const QLatin1String syncExclFile("sync-exclude.lst");
|
||||
static const QLatin1String exclFile("exclude.lst");
|
||||
|
||||
QString ConfigFile::excludeFile(Scope scope) const
|
||||
{
|
||||
// prefer sync-exclude.lst, but if it does not exist, check for
|
||||
// exclude.lst for compatibility reasons in the user writeable
|
||||
// directories.
|
||||
QFileInfo fi;
|
||||
|
||||
switch (scope) {
|
||||
case UserScope:
|
||||
fi.setFile(configPath(), exclFile);
|
||||
|
||||
if (!fi.isReadable()) {
|
||||
fi.setFile(configPath(), QLatin1String("exclude.lst"));
|
||||
}
|
||||
if (!fi.isReadable()) {
|
||||
fi.setFile(configPath(), exclFile);
|
||||
}
|
||||
return fi.absoluteFilePath();
|
||||
case SystemScope:
|
||||
if (scope == SystemScope) {
|
||||
return ConfigFile::excludeFileFromSystem();
|
||||
}
|
||||
|
||||
ASSERT(false);
|
||||
return QString();
|
||||
const auto excludeFilePath = scope == LegacyScope ? discoveredLegacyConfigPath() : configPath();
|
||||
|
||||
// prefer sync-exclude.lst, but if it does not exist, check for exclude.lst
|
||||
QFileInfo exclFileInfo(excludeFilePath, syncExclFile);
|
||||
if (!exclFileInfo.isReadable()) {
|
||||
exclFileInfo.setFile(excludeFilePath, exclFile);
|
||||
}
|
||||
if (!exclFileInfo.isReadable()) {
|
||||
exclFileInfo.setFile(excludeFilePath, syncExclFile);
|
||||
}
|
||||
|
||||
return exclFileInfo.absoluteFilePath();
|
||||
}
|
||||
|
||||
QString ConfigFile::excludeFileFromSystem()
|
||||
|
@ -1162,23 +1157,29 @@ std::unique_ptr<QSettings> ConfigFile::settingsWithGroup(const QString &group, Q
|
|||
void ConfigFile::setupDefaultExcludeFilePaths(ExcludedFiles &excludedFiles)
|
||||
{
|
||||
ConfigFile cfg;
|
||||
QString systemList = cfg.excludeFile(ConfigFile::SystemScope);
|
||||
QString userList = cfg.excludeFile(ConfigFile::UserScope);
|
||||
const auto systemList = cfg.excludeFile(ConfigFile::SystemScope);
|
||||
const auto userList = cfg.excludeFile(ConfigFile::UserScope);
|
||||
const auto legacyList = cfg.excludeFile(ConfigFile::LegacyScope);
|
||||
|
||||
if (!QFile::exists(userList)) {
|
||||
qCInfo(lcConfigFile) << "User defined ignore list does not exist:" << userList;
|
||||
if (!QFile::copy(systemList, userList)) {
|
||||
qCInfo(lcConfigFile) << "Could not copy over default list to:" << userList;
|
||||
|
||||
if (QFile::exists(legacyList) && QFile::copy(legacyList, userList)) {
|
||||
qCInfo(lcConfigFile) << "Migrating legacy list" << legacyList << "to user list" << userList;
|
||||
|
||||
} else if (QFile::copy(systemList, userList)) {
|
||||
qCInfo(lcConfigFile) << "Migrating system list" << legacyList << "to user list" << userList;
|
||||
}
|
||||
}
|
||||
|
||||
if (!QFile::exists(userList)) {
|
||||
qCInfo(lcConfigFile) << "Adding system ignore list to csync:" << systemList;
|
||||
excludedFiles.addExcludeFilePath(systemList);
|
||||
} else {
|
||||
qCInfo(lcConfigFile) << "Adding user defined ignore list to csync:" << userList;
|
||||
excludedFiles.addExcludeFilePath(userList);
|
||||
return;
|
||||
}
|
||||
|
||||
qCInfo(lcConfigFile) << "Adding user defined ignore list to csync:" << userList;
|
||||
excludedFiles.addExcludeFilePath(userList);
|
||||
}
|
||||
|
||||
QString ConfigFile::discoveredLegacyConfigPath()
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
ConfigFile();
|
||||
|
||||
enum Scope { UserScope,
|
||||
SystemScope };
|
||||
SystemScope, LegacyScope };
|
||||
|
||||
[[nodiscard]] QString configPath() const;
|
||||
[[nodiscard]] QString configFile() const;
|
||||
|
|
Loading…
Reference in a new issue