From: Olivier Goffart Date: Wed, 24 Oct 2018 13:42:42 +0000 (+0200) Subject: Migration from 2.4: fallback to move file by file if directory move failled (#6807) X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~451 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=380d7b80283ba025c362f151811da89d0646602e;p=nextcloud-desktop.git 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 --- diff --git a/src/gui/application.cpp b/src/gui/application.cpp index b1910be3c..310f055c1 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -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.