| 40 | } |
| 41 | |
| 42 | bool shouldClear(const QString& path) |
| 43 | { |
| 44 | QDir dir(path); |
| 45 | |
| 46 | if (!dir.exists()) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | if (getenv("CLEAR_DUCHAIN_DIR")) { |
| 51 | qCDebug(SERIALIZATION) << "clearing duchain directory because CLEAR_DUCHAIN_DIR is set"; |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | if (dir.exists(QStringLiteral("is_writing"))) { |
| 56 | qCWarning(SERIALIZATION) << "repository" << path << "was write-locked, it probably is inconsistent"; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | if (!dir.exists(QStringLiteral("version_%1").arg(staticItemRepositoryVersion()))) { |
| 61 | qCWarning(SERIALIZATION) << "version mismatch or no version hint; expected version:" << |
| 62 | staticItemRepositoryVersion(); |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | QFile crashesFile(dir.filePath(QStringLiteral("crash_counter"))); |
| 67 | if (crashesFile.open(QIODevice::ReadOnly)) { |
| 68 | int count; |
| 69 | QDataStream stream(&crashesFile); |
| 70 | stream >> count; |
| 71 | |
| 72 | qCDebug(SERIALIZATION) << "current count of crashes: " << count; |
| 73 | |
| 74 | if (count >= crashesBeforeCleanup && !getenv("DONT_CLEAR_DUCHAIN_DIR")) { |
| 75 | bool userAnswer = askUser(i18np("The previous session crashed.", "Session crashed %1 times in a row.", |
| 76 | count), |
| 77 | i18nc("tty action", "Clear cache"), |
| 78 | i18nc("@title", "Session Crashed"), |
| 79 | i18n("The crash may be caused by a corruption of cached data.\n\n" |
| 80 | "Press Clear if you want KDevelop to clear the cache, otherwise press Continue if you are sure the crash has another origin."), |
| 81 | i18nc("@action:button", "Clear Cache"), |
| 82 | i18nc("@action:button", "Continue")); |
| 83 | if (userAnswer) { |
| 84 | qCDebug(SERIALIZATION) << "User chose to clean repository"; |
| 85 | return true; |
| 86 | } else { |
| 87 | setCrashCounter(crashesFile, 1); |
| 88 | qCDebug(SERIALIZATION) << "User chose to reset crash counter"; |
| 89 | } |
| 90 | } else { |
| 91 | ///Increase the crash-count. It will be reset if kdevelop is shut down cleanly. |
| 92 | setCrashCounter(crashesFile, ++count); |
| 93 | } |
| 94 | } else { |
| 95 | setCrashCounter(crashesFile, 1); |
| 96 | } |
| 97 | |
| 98 | return false; |
| 99 | } |
no test coverage detected