Skip to content

Commit a23f45b

Browse files
committed
refactoring
1 parent 8e59c43 commit a23f45b

File tree

2 files changed

+36
-79
lines changed

2 files changed

+36
-79
lines changed

pkg/flasherapi/flasherapi.go

Lines changed: 21 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-app-cli.
2+
//
3+
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-app-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
116
package flasherapi
217

318
import (
@@ -8,22 +23,23 @@ import (
823
"github.com/arduino/arduino-app-cli/pkg/board/remote"
924
)
1025

26+
const R0_IMAGE_VERSION_ID = "20250807-136"
27+
1128
// GetOSImageVersion returns the version of the OS image used in the board.
1229
// It is used by the AppLab to enforce image version compatibility.
1330
func GetOSImageVersion(ctx context.Context, conn remote.RemoteConn) (string, error) {
14-
const defaultVersion = "20250807-136"
1531

16-
output, err := conn.GetCmd("cat /etc/buildinfo").Output(ctx)
32+
output, err := conn.GetCmd("cat", "/etc/buildinfo").Output(ctx)
1733
if err != nil {
18-
return defaultVersion, err
34+
return R0_IMAGE_VERSION_ID, err
1935
}
2036

2137
if version, ok := ParseOSImageVersion(string(output)); ok {
2238
slog.Info("find OS Image version", "version", version)
2339
return version, nil
2440
}
25-
slog.Info("Unable to find OS Image version", "using default version", defaultVersion)
26-
return defaultVersion, nil
41+
slog.Info("Unable to find OS Image version", "using default version", R0_IMAGE_VERSION_ID)
42+
return R0_IMAGE_VERSION_ID, nil
2743
}
2844

2945
func ParseOSImageVersion(buildInfo string) (string, bool) {
@@ -42,77 +58,3 @@ func ParseOSImageVersion(buildInfo string) (string, bool) {
4258
}
4359
return "", false
4460
}
45-
46-
type OSImageRelease struct {
47-
VersionLabel string
48-
ID string
49-
Latest bool
50-
}
51-
52-
func ListAvailableOSImages() []OSImageRelease {
53-
return []OSImageRelease{
54-
{
55-
ID: "20251123-159",
56-
VersionLabel: "r159 (2025-11-23)",
57-
Latest: true,
58-
},
59-
}
60-
}
61-
62-
func IsUserPartitionPreservationSupported(conn remote.RemoteConn, targetImageVersion OSImageRelease) bool {
63-
// targetImageVersion is the version of the image to be flashed
64-
// some older versions do not support user partition preservation
65-
// so this has to be considered here
66-
return true
67-
}
68-
69-
type FlashStep string
70-
71-
const (
72-
FlashStepPrecheck FlashStep = "precheck"
73-
FlashStepDetection FlashStep = "detection"
74-
FlashStepDownloading FlashStep = "downloading"
75-
FlashStepExtracting FlashStep = "extracting"
76-
FlashStepFlashing FlashStep = "flashing"
77-
)
78-
79-
type FlashEvent struct {
80-
Step FlashStep
81-
OverallProgress int // percentage 0-100
82-
Message string // log message to show on the UI
83-
}
84-
85-
func Flash(
86-
ctx context.Context, // context to cancel to interrupt the flashing process
87-
// conn remote.RemoteConn, // is this required for the flash process?
88-
imageVersion OSImageRelease, // OS image version to flash
89-
preserveUserPartition bool, // whether to preserve the user partition or not
90-
eventCB func(event FlashEvent), // Callback, sends progress events to the caller
91-
) error {
92-
// The disk space check is done before starting the flashing process.
93-
return InsufficientDiskSpaceError{
94-
RequiredSpaceMB: 2048,
95-
AvailableSpaceMB: 1024,
96-
}
97-
}
98-
99-
// Errors returned by the Flash function above.
100-
// Assertions can be done on the caller side to show better error messages.
101-
102-
type QDLFlashError struct {
103-
Details string
104-
Cause error
105-
}
106-
107-
type DownloadError struct {
108-
Details string
109-
}
110-
111-
type InsufficientDiskSpaceError struct {
112-
RequiredSpaceMB int64
113-
AvailableSpaceMB int64
114-
}
115-
116-
func (e InsufficientDiskSpaceError) Error() string {
117-
return "insufficient disk space"
118-
}

pkg/flasherapi/flasherapi_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// This file is part of arduino-app-cli.
2+
//
3+
// Copyright 2025 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-app-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
116
package flasherapi
217

318
import "testing"

0 commit comments

Comments
 (0)