luci-app-attendedsysupgrade: Fix logic error in EFI image selection
authorJakob Haufe <sur5r@sur5r.net>
Sat, 3 Feb 2024 19:22:21 +0000 (20:22 +0100)
committerPaul Spooren <mail@aparcar.org>
Mon, 5 Feb 2024 09:05:31 +0000 (10:05 +0100)
If a non-EFI image comes first in the list of images, it would have
been selected even on an EFI system.

Signed-off-by: Jakob Haufe <sur5r@sur5r.net>
applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js

index 450af354967b78510c8b2e9130e83fd5b82ae6c3..06bc1bb068079b6640e91600dbb0c37bbab639cb 100644 (file)
@@ -85,24 +85,24 @@ return view.extend({
        },
 
        selectImage: function (images) {
-               let image;
-               for (image of images) {
-                       if (this.firmware.filesystem == image.filesystem) {
+               let firmware = this.firmware;
+               let data = this.data;
+               var filesystemFilter = function(e) {
+                       return (e.filesystem == firmware.filesystem);
+               }
+               var typeFilter = function(e) {
+                       if (firmware.target.indexOf("x86") != -1) {
                                // x86 images can be combined-efi (EFI) or combined (BIOS)
-                               if(this.firmware.target.indexOf("x86") != -1) {
-                                       if (this.data.efi && image.type == 'combined-efi') {
-                                               return image;
-                                       } else if (image.type == 'combined') {
-                                               return image;
-                                       }
+                               if (data.efi) {
+                                       return (e.type == 'combined-efi');
                                } else {
-                                       if (image.type == 'sysupgrade' || image.type == 'combined') {
-                                               return image;
-                                       }
+                                       return (e.type == 'combined');
                                }
+                       } else {
+                               return (e.type == 'sysupgrade' || e.type == 'combined');
                        }
                }
-               return null;
+               return images.filter(filesystemFilter).filter(typeFilter)[0];
        },
 
        handle200: function (response) {