Copilot commented on code in PR #14033:
URL: https://github.com/apache/cloudstack/pull/14033#discussion_r4037840798


##########
scripts/installer/export-templates.sh:
##########
@@ -16,11 +16,27 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# Kept in sync with CloudStackVersion.NEW_VERSIONING_CUTOVER_MAJOR_VERSION 
(utils module) and the
+# same constant in engine/schema/templateConfig.sh.
+NEW_VERSIONING_CUTOVER_MAJOR_VERSION=24
+
 METADATA_FILE="metadata.ini"
 IMAGE_PATH=${3:-"/usr/share/cloudstack-management/templates/systemvm/"}
 TEMPLATE_VERSION=$(awk -F "=" '/version/ {print $2}' 
${IMAGE_PATH}${METADATA_FILE} | xargs)
 TEMPLATE_PATH="/usr/share/cloudstack-management/templates/systemvm/"
-VERSION="${TEMPLATE_VERSION%.*}"
+TEMPLATE_MAJOR_VERSION="$(cut -d'.' -f1 <<<"$TEMPLATE_VERSION")"
+if [[ "$TEMPLATE_MAJOR_VERSION" -ge "$NEW_VERSIONING_CUTOVER_MAJOR_VERSION" 
]]; then
+  # New versioning (major.minor.security): the generated template files use 
the full version as-is.
+  VERSION="${TEMPLATE_VERSION}"
+else
+  # Legacy versioning drops the trailing security component only for 
four-component metadata;
+  # a valid three-component major.minor.patch value is already the filename 
version.
+  if [[ "$TEMPLATE_VERSION" == *.*.*.* ]]; then
+    VERSION="${TEMPLATE_VERSION%.*}"
+  else
+    VERSION="${TEMPLATE_VERSION}"
+  fi
+fi

Review Comment:
   The exporter assumes every metadata value with a major of at least 24 is 
valid, and the legacy wildcard matches any version with at least four 
dot-separated fields. Consequently, malformed `24.0.0.1` is accepted as a 
template prefix despite being rejected by `templateConfig.sh`, and `4.23.0.1.2` 
is truncated to another invalid prefix. Validate `TEMPLATE_VERSION` as exactly 
three or four numeric components and reject four components at the cutover 
before deriving `VERSION`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to