Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc9da144

Browse files
Add --temp-dir flag to allow users to choose where to download and extract images
1 parentfb5dcd7 commitc9da144

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

‎flash.go‎

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

3232
funcnewFlashCmd()*cobra.Command {
3333
varforceYesbool
34+
vartempDirstring
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
returnappCmd
@@ -86,13 +89,13 @@ func checkDriversInstalled() {
8689
}
8790
}
8891

89-
funcrunFlashCommand(ctx context.Context,args []string,forceYesbool) {
92+
funcrunFlashCommand(ctx context.Context,args []string,forceYesbool,tempDirstring) {
9093
imagePath,err:=paths.New(args[0]).Abs()
9194
iferr!=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
iferr!=nil {
97100
feedback.Fatal(i18n.Tr("error flashing the board: %v",err),feedback.ErrBadArgument)
98101
}

‎updater/download_image.go‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ type Release struct {
4646
// DownloadConfirmCB is a function that is called when a Debian image is ready to be downloaded.
4747
typeDownloadConfirmCBfunc(targetstring) (bool,error)
4848

49-
funcDownloadAndExtract(client*Client,targetVersionstring,upgradeConfirmCbDownloadConfirmCB,forceYesbool) (*paths.Path,string,error) {
50-
tmpZip,version,err:=DownloadImage(client,targetVersion,upgradeConfirmCb,forceYes)
49+
funcDownloadAndExtract(client*Client,targetVersionstring,upgradeConfirmCbDownloadConfirmCB,forceYesbool,tempDirstring) (*paths.Path,string,error) {
50+
tmpZip,version,err:=DownloadImage(client,targetVersion,upgradeConfirmCb,forceYes,tempDir)
5151
iferr!=nil {
5252
returnnil,"",fmt.Errorf("error downloading the image: %v",err)
5353
}
@@ -69,7 +69,7 @@ func DownloadAndExtract(client *Client, targetVersion string, upgradeConfirmCb D
6969
returnimagePath,version,nil
7070
}
7171

72-
funcDownloadImage(client*Client,targetVersionstring,upgradeConfirmCbDownloadConfirmCB,forceYesbool) (*paths.Path,string,error) {
72+
funcDownloadImage(client*Client,targetVersionstring,upgradeConfirmCbDownloadConfirmCB,forceYesbool,tempDirstring) (*paths.Path,string,error) {
7373
varerrerror
7474

7575
feedback.Print(i18n.Tr("Checking for Debian image releases"))
@@ -112,7 +112,7 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo
112112
deferdownload.Close()
113113

114114
// Download the zip
115-
temp,err:=GetTempDir("download-")
115+
temp,err:=GetTempDir("download-",tempDir)
116116
iferr!=nil {
117117
returnnil,"",fmt.Errorf("could not create temporary download directory: %w",err)
118118
}
@@ -166,14 +166,18 @@ func ExtractImage(archive, temp *paths.Path) error {
166166

167167
// GetTempDir returns a temporary directory inside the user's cache directory.
168168
// The caller is responsible for removing the directory when no longer needed.
169-
funcGetTempDir(prefixstring) (*paths.Path,error) {
170-
userCacheDir,err:=os.UserCacheDir()
171-
iferr!=nil {
172-
returnnil,fmt.Errorf("could not get user's cache directory: %w",err)
173-
}
169+
funcGetTempDir(prefixstring,tempDirstring) (*paths.Path,error) {
170+
cacheDir:=paths.New(tempDir)
171+
172+
ifcacheDir==nil {
173+
userCacheDir,err:=os.UserCacheDir()
174+
iferr!=nil {
175+
returnnil,fmt.Errorf("could not get user's cache directory: %w",err)
176+
}
174177

175-
cacheDir:=paths.New(userCacheDir,"arduino-flasher-cli")
176-
_=cacheDir.MkdirAll()
178+
cacheDir=paths.New(userCacheDir,"arduino-flasher-cli")
179+
_=cacheDir.MkdirAll()
180+
}
177181

178182
temp,err:=paths.MkTempDir(cacheDir.String(),prefix)
179183
iferr!=nil {

‎updater/flasher.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/arduino/arduino-flasher-cli/updater/artifacts"
2929
)
3030

31-
funcFlash(ctx context.Context,imagePath*paths.Path,versionstring,forceYesbool)error {
31+
funcFlash(ctx context.Context,imagePath*paths.Path,versionstring,forceYesbool,tempDirstring)error {
3232
if!imagePath.Exist() {
3333
client:=NewClient()
3434

@@ -43,7 +43,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
4343
}
4444
yes:=strings.ToLower(yesInput)=="yes"||strings.ToLower(yesInput)=="y"
4545
returnyes,nil
46-
},forceYes)
46+
},forceYes,tempDir)
4747

4848
iferr!=nil {
4949
returnfmt.Errorf("could not download and extract the image: %v",err)
@@ -59,7 +59,7 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
5959
version=v
6060
imagePath=tempImagePath
6161
}elseif!imagePath.IsDir() {
62-
temp,err:=GetTempDir("extract-")
62+
temp,err:=GetTempDir("extract-",tempDir)
6363
iferr!=nil {
6464
returnfmt.Errorf("error creating a temporary directory to extract the archive: %v",err)
6565
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp