Skip to content

Commit 84830ab

Browse files
MatteoPologrutoper1234lucarin91
authored
fix: check free disk space and allow to specify a different download/extraction directory (#23)
* Add --temp-dir flag to allow users to choose where to download and extract images * Check free disk space before starting an image download or extraction * Update dependencies * Manually review licenses * Update updater/download_image.go Co-authored-by: Per Tillisch <accounts@perglass.com> * Update updater/download_image.go Co-authored-by: Luca Rinaldi <lucarin@protonmail.com> * Update updater/download_image.go Co-authored-by: Luca Rinaldi <lucarin@protonmail.com> * Apply review suggestion * Change helper function name * Refactor the flow of the commands to make them more readable --------- Co-authored-by: Per Tillisch <accounts@perglass.com> Co-authored-by: Luca Rinaldi <lucarin@protonmail.com>
1 parent d6bef23 commit 84830ab

File tree

9 files changed

+306
-35
lines changed

9 files changed

+306
-35
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: github.com/shirou/gopsutil/v4/common
3+
version: v4.25.10
4+
type: go
5+
summary: 'SPDX-License-Identifier: BSD-3-Clause'
6+
homepage: https://pkg.go.dev/github.com/shirou/gopsutil/v4/common
7+
license: bsd-3-clause
8+
licenses:
9+
- sources: v4@v4.25.10/LICENSE
10+
text: |-
11+
gopsutil is distributed under BSD license reproduced below.
12+
13+
Copyright (c) 2014, WAKAYAMA Shirou
14+
All rights reserved.
15+
16+
Redistribution and use in source and binary forms, with or without modification,
17+
are permitted provided that the following conditions are met:
18+
19+
* Redistributions of source code must retain the above copyright notice, this
20+
list of conditions and the following disclaimer.
21+
* Redistributions in binary form must reproduce the above copyright notice,
22+
this list of conditions and the following disclaimer in the documentation
23+
and/or other materials provided with the distribution.
24+
* Neither the name of the gopsutil authors nor the names of its contributors
25+
may be used to endorse or promote products derived from this software without
26+
specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
39+
40+
-------
41+
internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go.
42+
43+
44+
45+
Copyright (c) 2009 The Go Authors. All rights reserved.
46+
47+
Redistribution and use in source and binary forms, with or without
48+
modification, are permitted provided that the following conditions are
49+
met:
50+
51+
* Redistributions of source code must retain the above copyright
52+
notice, this list of conditions and the following disclaimer.
53+
* Redistributions in binary form must reproduce the above
54+
copyright notice, this list of conditions and the following disclaimer
55+
in the documentation and/or other materials provided with the
56+
distribution.
57+
* Neither the name of Google Inc. nor the names of its
58+
contributors may be used to endorse or promote products derived from
59+
this software without specific prior written permission.
60+
61+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
62+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
63+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
64+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
65+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
66+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
67+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
68+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
69+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
70+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
71+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72+
- sources: v4@v4.25.10/README.md
73+
text: New BSD License (same as psutil)
74+
notices: []
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: github.com/shirou/gopsutil/v4/disk
3+
version: v4.25.10
4+
type: go
5+
summary: 'SPDX-License-Identifier: BSD-3-Clause'
6+
homepage: https://pkg.go.dev/github.com/shirou/gopsutil/v4/disk
7+
license: bsd-3-clause
8+
licenses:
9+
- sources: v4@v4.25.10/LICENSE
10+
text: |-
11+
gopsutil is distributed under BSD license reproduced below.
12+
13+
Copyright (c) 2014, WAKAYAMA Shirou
14+
All rights reserved.
15+
16+
Redistribution and use in source and binary forms, with or without modification,
17+
are permitted provided that the following conditions are met:
18+
19+
* Redistributions of source code must retain the above copyright notice, this
20+
list of conditions and the following disclaimer.
21+
* Redistributions in binary form must reproduce the above copyright notice,
22+
this list of conditions and the following disclaimer in the documentation
23+
and/or other materials provided with the distribution.
24+
* Neither the name of the gopsutil authors nor the names of its contributors
25+
may be used to endorse or promote products derived from this software without
26+
specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
39+
40+
-------
41+
internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go.
42+
43+
44+
45+
Copyright (c) 2009 The Go Authors. All rights reserved.
46+
47+
Redistribution and use in source and binary forms, with or without
48+
modification, are permitted provided that the following conditions are
49+
met:
50+
51+
* Redistributions of source code must retain the above copyright
52+
notice, this list of conditions and the following disclaimer.
53+
* Redistributions in binary form must reproduce the above
54+
copyright notice, this list of conditions and the following disclaimer
55+
in the documentation and/or other materials provided with the
56+
distribution.
57+
* Neither the name of Google Inc. nor the names of its
58+
contributors may be used to endorse or promote products derived from
59+
this software without specific prior written permission.
60+
61+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
62+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
63+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
64+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
65+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
66+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
67+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
68+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
69+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
70+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
71+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72+
- sources: v4@v4.25.10/README.md
73+
text: New BSD License (same as psutil)
74+
notices: []
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
name: github.com/shirou/gopsutil/v4/internal/common
3+
version: v4.25.10
4+
type: go
5+
summary: 'SPDX-License-Identifier: BSD-3-Clause'
6+
homepage: https://pkg.go.dev/github.com/shirou/gopsutil/v4/internal/common
7+
license: bsd-3-clause
8+
licenses:
9+
- sources: v4@v4.25.10/LICENSE
10+
text: |-
11+
gopsutil is distributed under BSD license reproduced below.
12+
13+
Copyright (c) 2014, WAKAYAMA Shirou
14+
All rights reserved.
15+
16+
Redistribution and use in source and binary forms, with or without modification,
17+
are permitted provided that the following conditions are met:
18+
19+
* Redistributions of source code must retain the above copyright notice, this
20+
list of conditions and the following disclaimer.
21+
* Redistributions in binary form must reproduce the above copyright notice,
22+
this list of conditions and the following disclaimer in the documentation
23+
and/or other materials provided with the distribution.
24+
* Neither the name of the gopsutil authors nor the names of its contributors
25+
may be used to endorse or promote products derived from this software without
26+
specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
39+
40+
-------
41+
internal/common/binary.go in the gopsutil is copied and modified from golang/encoding/binary.go.
42+
43+
44+
45+
Copyright (c) 2009 The Go Authors. All rights reserved.
46+
47+
Redistribution and use in source and binary forms, with or without
48+
modification, are permitted provided that the following conditions are
49+
met:
50+
51+
* Redistributions of source code must retain the above copyright
52+
notice, this list of conditions and the following disclaimer.
53+
* Redistributions in binary form must reproduce the above
54+
copyright notice, this list of conditions and the following disclaimer
55+
in the documentation and/or other materials provided with the
56+
distribution.
57+
* Neither the name of Google Inc. nor the names of its
58+
contributors may be used to endorse or promote products derived from
59+
this software without specific prior written permission.
60+
61+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
62+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
63+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
64+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
65+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
66+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
67+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
68+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
69+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
70+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
71+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72+
- sources: v4@v4.25.10/README.md
73+
text: New BSD License (same as psutil)
74+
notices: []

.licenses/arduino-flasher-cli/go/golang.org/x/sys/unix.dep.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
name: golang.org/x/sys/unix
3-
version: v0.36.0
3+
version: v0.37.0
44
type: go
55
summary: Package unix contains an interface to the low-level operating system primitives.
66
homepage: https://pkg.go.dev/golang.org/x/sys/unix
7-
license: bsd-3-clause
7+
license: bsd-3-clause
88
licenses:
9-
- sources: sys@v0.36.0/LICENSE
9+
- sources: sys@v0.37.0/LICENSE
1010
text: |
1111
Copyright 2009 The Go Authors.
1212
@@ -35,7 +35,7 @@ licenses:
3535
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3636
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3737
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38-
- sources: sys@v0.36.0/PATENTS
38+
- sources: sys@v0.37.0/PATENTS
3939
text: |
4040
Additional IP Rights Grant (Patents)
4141

flash.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
func newFlashCmd() *cobra.Command {
3333
var forceYes bool
34+
var tempDir string
3435
appCmd := &cobra.Command{
3536
Use: "flash",
3637
Short: "Flash a Debian image on the board",
@@ -61,15 +62,17 @@ NOTE: On Windows, required drivers are automatically installed with elevated pri
6162
" " + os.Args[0] + " flash ./my-image.tar.zst\n" +
6263
" " + os.Args[0] + " flash /path/to/debian-image.tar.zst\n" +
6364
" " + os.Args[0] + " flash /path/to/debian-image.tar.xz \n" +
64-
" " + os.Args[0] + " flash /path/to/arduino-unoq-debian-image-20250915-173 \n",
65+
" " + os.Args[0] + " flash /path/to/arduino-unoq-debian-image-20250915-173 \n" +
66+
" " + os.Args[0] + " flash latest --temp-dir /path/to/custom/tempDir \n",
6567

6668
Args: cobra.ExactArgs(1),
6769
Run: func(cmd *cobra.Command, args []string) {
6870
checkDriversInstalled()
69-
runFlashCommand(cmd.Context(), args, forceYes)
71+
runFlashCommand(cmd.Context(), args, forceYes, tempDir)
7072
},
7173
}
7274
appCmd.Flags().BoolVarP(&forceYes, "yes", "y", false, "Automatically confirm all prompts")
75+
appCmd.Flags().StringVar(&tempDir, "temp-dir", "", "Path to the directory in which the image will be downloaded and extracted")
7376
// TODO: add --clean-install flag or something similar to distinguish between keeping and purging the /home directory
7477

7578
return appCmd
@@ -86,13 +89,13 @@ func checkDriversInstalled() {
8689
}
8790
}
8891

89-
func runFlashCommand(ctx context.Context, args []string, forceYes bool) {
92+
func runFlashCommand(ctx context.Context, args []string, forceYes bool, tempDir string) {
9093
imagePath, err := paths.New(args[0]).Abs()
9194
if err != nil {
9295
feedback.Fatal(i18n.Tr("could not find image absolute path: %v", err), feedback.ErrBadArgument)
9396
}
9497

95-
err = updater.Flash(ctx, imagePath, args[0], forceYes)
98+
err = updater.Flash(ctx, imagePath, args[0], forceYes, tempDir)
9699
if err != nil {
97100
feedback.Fatal(i18n.Tr("error flashing the board: %v", err), feedback.ErrBadArgument)
98101
}

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ require (
99
github.com/jedib0t/go-pretty/v6 v6.6.8
1010
github.com/leonelquinteros/gotext v1.7.2
1111
github.com/schollz/progressbar/v3 v3.18.0
12+
github.com/shirou/gopsutil/v4 v4.25.10
1213
github.com/sirupsen/logrus v1.9.3
1314
github.com/spf13/cobra v1.9.1
14-
github.com/stretchr/testify v1.10.0
15+
github.com/stretchr/testify v1.11.1
1516
go.bug.st/cleanup v1.0.0
1617
go.bug.st/f v0.4.0
1718
)
@@ -29,13 +30,15 @@ require (
2930
github.com/davecgh/go-spew v1.1.1 // indirect
3031
github.com/dlclark/regexp2 v1.11.5 // indirect
3132
github.com/dominikbraun/graph v0.23.0 // indirect
33+
github.com/ebitengine/purego v0.9.0 // indirect
3234
github.com/elliotchance/orderedmap/v3 v3.1.0 // indirect
3335
github.com/emirpasic/gods v1.18.1 // indirect
3436
github.com/fatih/color v1.18.0 // indirect
3537
github.com/fsnotify/fsnotify v1.9.0 // indirect
3638
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
3739
github.com/go-git/go-billy/v5 v5.6.2 // indirect
3840
github.com/go-git/go-git/v5 v5.16.2 // indirect
41+
github.com/go-ole/go-ole v1.3.0 // indirect
3942
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
4043
github.com/go-task/task/v3 v3.44.1 // indirect
4144
github.com/go-task/template v0.2.0 // indirect
@@ -56,6 +59,7 @@ require (
5659
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
5760
github.com/pjbgf/sha1cd v0.3.2 // indirect
5861
github.com/pmezard/go-difflib v1.0.0 // indirect
62+
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
5963
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
6064
github.com/rivo/uniseg v0.4.7 // indirect
6165
github.com/sajari/fuzzy v1.0.0 // indirect
@@ -65,11 +69,12 @@ require (
6569
github.com/stretchr/objx v0.5.2 // indirect
6670
github.com/ulikunitz/xz v0.5.12 // indirect
6771
github.com/xanzy/ssh-agent v0.3.3 // indirect
72+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
6873
github.com/zeebo/xxh3 v1.0.2 // indirect
6974
golang.org/x/crypto v0.37.0 // indirect
7075
golang.org/x/net v0.39.0 // indirect
7176
golang.org/x/sync v0.16.0 // indirect
72-
golang.org/x/sys v0.36.0 // indirect
77+
golang.org/x/sys v0.37.0 // indirect
7378
golang.org/x/term v0.35.0 // indirect
7479
golang.org/x/text v0.24.0 // indirect
7580
gopkg.in/warnings.v0 v0.1.2 // indirect

0 commit comments

Comments
 (0)