-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix version comparison with minor and patch level requirements #9024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| // Version is bigger or equals to the minimum version of the app | ||
| version_compare($ncVersion, $version->getMinimumVersion(), '>=') | ||
| // Version is smaller or equals to the maximum version of the app | ||
| && version_compare($ncVersion, $version->getMaximumVersion(), '<=') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah here is what breaks, all apps currently have max-version="13"
So we need to keep the major only check for the max version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's disputable. I think if someone specifies the full version requirement like 13.0.1 (for whatever reason) we should do the full check. But of course, if max is set to 13, we should allow any version of Nextcloud 13.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we align the comparison to the same amount of digits? Then use the <= and >= operators and it would be fine. If max version is 13.0.2 we would compare against the full version if it is 13 we would only use the major version.
Codecov Report
@@ Coverage Diff @@
## master #9024 +/- ##
============================================
+ Coverage 51.91% 51.94% +0.02%
+ Complexity 25325 25323 -2
============================================
Files 1603 1605 +2
Lines 95180 95169 -11
Branches 1387 1387
============================================
+ Hits 49414 49433 +19
+ Misses 45766 45736 -30
|
|
I've added a new version comparison class to compare app requirements. I chose to move the logic into a new class because it's likely to be used in other places too and because it makes testing a lot easier. Ref #9024 (comment). There's one issue: the existing test cases fail now, because they use a |
Yes it is. The 4th digit is our internal version number to be able to trigger DB migrations ;) But they should now be used outside of our server core. So the info.xml should at most hold 3 parts. |
fb323da to
385404d
Compare
Fixed. Please see the test data to verify I implemented the compatibility logic correctly 😉 |
| $min = $version->getMinimumVersion(); | ||
| $max = $version->getMaximumVersion(); | ||
| $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $min, '>='); | ||
| $maxFulfilled = $max !== '' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this is merely for backwards compatibility. Nowadays apps have to specify their min and max requirements, thus this check is not necessary anymore. However, the test data contains apps that have no max-requirement set and thus this code would fail. Since I'm not 100% sure if the app store would distribute these apps, I took the safe path and added this check defensively.
| public function isCompatible(string $actual, string $required, | ||
| string $comparator = '>='): bool { | ||
|
|
||
| if (!preg_match(self::REGEX_SERVER, $actual)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to do then only a check agains REGEX_MAJOR_MINOR_PATCH because it is excluded below anyways (in the else branch)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below only $required is checked, not $actual. And the server version is in x.x.x(.x) format, hence the special regex with the optional forth-level version.
| $ncVersion = $this->getVersion(); | ||
| $min = $version->getMinimumVersion(); | ||
| $max = $version->getMaximumVersion(); | ||
| $minFulfilled = $this->compareVersion->isCompatible($ncVersion, $min, '>='); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also catch the exceptions and log them - otherwise this gets messy and user complain about broken app pages and stuff like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also catch the exceptions and log them - otherwise this gets messy and user complain about broken app pages and stuff like that.
What shall we do in case of a thrown exception? Ignore the app? Install anyway? IMO this one is unexpected for normal use and is only thrown if the class is used wrongly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should ignore the app - would be horrible if you have one broken app installed and the app management would not work anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- catch it => Log it
- And remove from the app list so people don't even see it (so can't install)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: while we could add that (IMO ugly) check, it's not actually possible that an app would have an invalid version requirement at the moment because it's validated with the info.xml schema:
<xs:simpleType name="version">
<xs:restriction base="limited-string">
<xs:pattern value="[0-9]+(\.[0-9]+){0,2}"/>
</xs:restriction>
</xs:simpleType>
MorrisJobke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine now 👍
|
@ChristophWurst Please have a final look at my changes 😉 |
ChristophWurst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐘
|
Dumping the autoloader is missing |
If an app requires a specific minor or path level server version, the version_compare prevented the installation as only the major version had been compared and that checks obviously returns `false`. Now the full version is used for comparison, making it possible to release apps for a specific minor or patch level version of Nextcloud. Signed-off-by: Christoph Wurst <[email protected]>
Signed-off-by: Morris Jobke <[email protected]>
Signed-off-by: Roeland Jago Douma <[email protected]>
0cb1286 to
52f1f04
Compare
If an app requires a specific minor or path level server version,
the version_compare prevented the installation as only the major
version had been compared and that checks obviously returns
false.Now the full version is used for comparison, making it possible to
release apps for a specific minor or patch level version of Nextcloud.
This is a quick fix for discussion. There are probably some tests that will fail now.
cc @rullzer @nickvergessen as discussed.