1616package flasherapi
1717
1818import (
19+ "bufio"
1920 "context"
21+ "io"
2022 "log/slog"
2123 "strings"
2224
@@ -27,34 +29,42 @@ const R0_IMAGE_VERSION_ID = "20250807-136"
2729
2830// GetOSImageVersion returns the version of the OS image used in the board.
2931// It is used by the AppLab to enforce image version compatibility.
30- func GetOSImageVersion (ctx context.Context , conn remote.RemoteConn ) ( string , error ) {
32+ func GetOSImageVersion (ctx context.Context , conn remote.RemoteConn ) string {
3133
32- output , err := conn .GetCmd ( "cat" , " /etc/buildinfo"). Output ( ctx )
34+ f , err := conn .ReadFile ( " /etc/buildinfo" )
3335 if err != nil {
34- return R0_IMAGE_VERSION_ID , err
36+ slog .Warn ("Unable to read buildinfo file" , "err" , err , "using_default" , R0_IMAGE_VERSION_ID )
37+ return R0_IMAGE_VERSION_ID
3538 }
39+ defer f .Close ()
3640
37- if version , ok := ParseOSImageVersion ( string ( output ) ); ok {
38- slog .Info ("find OS Image version" , "version" , version )
39- return version , nil
41+ if version , ok := parseOSImageVersion ( f ); ok {
42+ slog .Info ("found OS Image version" , "version" , version )
43+ return version
4044 }
41- slog .Info ("Unable to find OS Image version" , "using default version " , R0_IMAGE_VERSION_ID )
42- return R0_IMAGE_VERSION_ID , nil
45+ slog .Warn ("Unable to find OS Image version" , "using_default " , R0_IMAGE_VERSION_ID )
46+ return R0_IMAGE_VERSION_ID
4347}
4448
45- func ParseOSImageVersion (buildInfo string ) (string , bool ) {
46- for _ , line := range strings .Split (buildInfo , "\n " ) {
47- line = strings .TrimSpace (line )
49+ func parseOSImageVersion (r io.Reader ) (string , bool ) {
50+ scanner := bufio .NewScanner (r )
51+ for scanner .Scan () {
52+ line := strings .TrimSpace (scanner .Text ())
4853
4954 key , value , ok := strings .Cut (line , "=" )
5055 if ! ok || key != "BUILD_ID" {
5156 continue
5257 }
5358
54- version := strings .Trim (value , " \" ' " )
59+ version := strings .Trim (value , `"' ` )
5560 if version != "" {
5661 return version , true
5762 }
5863 }
64+
65+ if err := scanner .Err (); err != nil {
66+ return "" , false
67+ }
68+
5969 return "" , false
6070}
0 commit comments