Make the regex more maintainable declaring it as a variable, breaking it
up and commenting it by using the x flag.

Also remove the part that parses our Debian revision (e.g. -pve1) from
the version, as we do not actually include that in our Ceph builds.

The part of the regex that parses the build commit hash is made
mandatory (remove '?' after its group).

Signed-off-by: Max Carrara <m.carr...@proxmox.com>
---
 PVE/Ceph/Tools.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm
index 087c4ef3..a00d23e1 100644
--- a/PVE/Ceph/Tools.pm
+++ b/PVE/Ceph/Tools.pm
@@ -68,7 +68,18 @@ sub get_local_version {
 
     return undef if !defined $ceph_version;
 
-    if ($ceph_version =~ 
/^ceph.*\sv?(\d+(?:\.\d+)+(?:-pve\d+)?)\s+(?:\(([a-zA-Z0-9]+)\))?/) {
+    my $re_ceph_version = qr/
+       # Skip ahead to the version, which may optionally start with 'v'
+       ^ceph.*\sv?
+
+       # Parse the version X.Y, X.Y.Z, etc.
+       ( \d+ (?:\.\d+)+ ) \s+
+
+       # Parse the git commit hash between parentheses
+       (?: \( ([a-zA-Z0-9]+) \) )
+    /x;
+
+    if ($ceph_version =~ /$re_ceph_version/) {
        my ($version, $buildcommit) = ($1, $2);
        my $subversions = [ split(/\.|-/, $version) ];
 
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to