homeassistant-addons icon indicating copy to clipboard operation
homeassistant-addons copied to clipboard

_🛠️ Refactor suggestion_

Open MaxWinterstein opened this issue 6 months ago • 0 comments

🛠️ Refactor suggestion

Improve version comparison robustness.

The current version comparison using bc assumes numeric versions but may fail with semantic versioning formats like "16.0.1" or "16-beta". Consider implementing a more robust version comparison that can handle various version string formats.

-# Check if OS_VERSION is greater than 16
-if (( $(echo "$OS_VERSION >= 16" | bc -l) )); then
+# Extract major version number for comparison
+MAJOR_VERSION=$(echo "$OS_VERSION" | sed 's/\([0-9]\+\).*/\1/')
+if [ "$MAJOR_VERSION" -ge 16 ]; then
📝 Committable suggestion

‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

# Extract major version number for comparison
MAJOR_VERSION=$(echo "$OS_VERSION" | sed 's/\([0-9]\+\).*/\1/')
if [ "$MAJOR_VERSION" -ge 16 ]; then
🤖 Prompt for AI Agents
In cups/rootfs/etc/s6-overlay/s6-rc.d/dbus-daemon/run at lines 22-23, the
version comparison uses bc which only supports numeric values and fails with
semantic versions like "16.0.1" or "16-beta". Replace this with a more robust
comparison method such as parsing the version string into components and
comparing each numeric part sequentially or using a tool like sort -V or dpkg
--compare-versions if available, to correctly handle semantic version formats.

Originally posted by @coderabbitai[bot] in https://github.com/MaxWinterstein/homeassistant-addons/pull/377#discussion_r2202470929

MaxWinterstein avatar Jul 12 '25 09:07 MaxWinterstein