|
1 | 1 | #include "mark_helper.h"
|
2 | 2 |
|
3 | 3 | #include <sys/user.h>
|
4 |
| - |
| 4 | +#include <QHash> |
| 5 | +#include <QVersionNumber> |
5 | 6 |
|
6 | 7 | #include "app.h"
|
7 | 8 | #include "shournalk_ctrl.h"
|
8 | 9 | #include "stdiocpp.h"
|
9 | 10 | #include "translation.h"
|
10 | 11 | #include "os.h"
|
11 | 12 |
|
| 13 | +using std::unordered_map; |
| 14 | +using std::string; |
| 15 | + |
| 16 | +// To avoid unnecessary unloading of the kernel module shournalk |
| 17 | +// when a new version is installed, |
| 18 | +// define a compatibility map, where the key corresponds |
| 19 | +// to the "current" version and the value determines the *minimum* |
| 20 | +// required version. |
| 21 | +static const QHash<QVersionNumber, QVersionNumber> KVERSION_COMPATIBILITY_MAP = { |
| 22 | + {QVersionNumber{2,9}, QVersionNumber{2,8}} |
| 23 | +}; |
12 | 24 |
|
13 | 25 | ExcShournalk::ExcShournalk(const QString &text) :
|
14 | 26 | QExcCommon(text, false)
|
@@ -58,11 +70,16 @@ ShournalkControl::ShournalkControl()
|
58 | 70 | .arg(translation::strerror_l(errno)));
|
59 | 71 | }
|
60 | 72 | if(strcmp(SHOURNAL_VERSION, kversion.ver_str) != 0){
|
61 |
| - throw ExcShournalk(qtr("Version mismatch - %1 version is %2, but " |
62 |
| - "%3 version is %4") |
63 |
| - .arg(app::SHOURNAL_RUN).arg(SHOURNAL_VERSION) |
64 |
| - .arg("kernel-module").arg(kversion.ver_str) |
65 |
| - ); |
| 73 | + auto kver = QVersionNumber::fromString(kversion.ver_str); |
| 74 | + const auto & compatible_ver = KVERSION_COMPATIBILITY_MAP.find(app::version()); |
| 75 | + if(compatible_ver == KVERSION_COMPATIBILITY_MAP.end() || |
| 76 | + kver < compatible_ver.value()){ |
| 77 | + throw ExcShournalk(qtr("Version mismatch - %1 version is %2, but " |
| 78 | + "%3 version is %4") |
| 79 | + .arg(app::SHOURNAL_RUN).arg(SHOURNAL_VERSION) |
| 80 | + .arg("kernel-module").arg(kversion.ver_str) |
| 81 | + ); |
| 82 | + } |
66 | 83 | }
|
67 | 84 |
|
68 | 85 | m_tmpFileTarget = stdiocpp::tmpfile(O_NOATIME); // tmpfile auto deletes..
|
|
0 commit comments