mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
Migration from 2.4: fallback to move file by file if directory move failled (#6807)
Migration from 2.4: fallback to move file by file if directory move failed This can happen if the directory already exist because, say, it was created by the ownCloud outlook plugin which save its file in the same directory
This commit is contained in:
parent
e20e1d110f
commit
380d7b8028
1 changed files with 16 additions and 4 deletions
|
@ -202,9 +202,7 @@ Application::Application(int &argc, char **argv)
|
|||
setWindowIcon(_theme->applicationIcon());
|
||||
setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
|
||||
auto confDir = ConfigFile().configPath();
|
||||
if (confDir.endsWith('/')) confDir.chop(1); // macOS 10.11.x does not like trailing slash for rename/move.
|
||||
if (!QFileInfo(confDir).isDir()) {
|
||||
if (!ConfigFile().exists()) {
|
||||
// Migrate from version <= 2.4
|
||||
setApplicationName(_theme->appNameGUI());
|
||||
#ifndef QT_WARNING_DISABLE_DEPRECATED // Was added in Qt 5.9
|
||||
|
@ -219,9 +217,23 @@ Application::Application(int &argc, char **argv)
|
|||
QT_WARNING_POP
|
||||
setApplicationName(_theme->appName());
|
||||
if (QFileInfo(oldDir).isDir()) {
|
||||
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 file to its new location (" << oldDir << "to" << 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)) {
|
||||
qCWarning(lcApplication) << "Fallback move of " << name << "also failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifndef Q_OS_WIN
|
||||
// Create a symbolic link so a downgrade of the client would still find the config.
|
||||
|
|
Loading…
Reference in a new issue