Skip to content

Commit caab911

Browse files
committed
Moved function to the correct file
1 parent b4e9777 commit caab911

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

arduino/resources/download.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,43 @@
1616
package resources
1717

1818
import (
19+
"fmt"
20+
"os"
1921
"time"
2022

2123
"github.com/arduino/arduino-cli/arduino"
2224
"github.com/arduino/arduino-cli/httpclient"
25+
paths "github.com/arduino/go-paths-helper"
2326
"go.bug.st/downloader/v2"
2427
)
2528

29+
// Download a DownloadResource.
30+
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config) (*downloader.Downloader, error) {
31+
path, err := r.ArchivePath(downloadDir)
32+
if err != nil {
33+
return nil, fmt.Errorf(tr("getting archive path: %s"), err)
34+
}
35+
36+
if _, err := path.Stat(); os.IsNotExist(err) {
37+
// normal download
38+
} else if err == nil {
39+
// check local file integrity
40+
ok, err := r.TestLocalArchiveIntegrity(downloadDir)
41+
if err != nil || !ok {
42+
if err := path.Remove(); err != nil {
43+
return nil, fmt.Errorf(tr("removing corrupted archive file: %s"), err)
44+
}
45+
} else {
46+
// File is cached, nothing to do here
47+
return nil, nil
48+
}
49+
} else {
50+
return nil, fmt.Errorf(tr("getting archive file info: %s"), err)
51+
}
52+
53+
return downloader.DownloadWithConfig(path.String(), r.URL, *config)
54+
}
55+
2656
// GetDownloaderConfig returns the downloader configuration based on
2757
// current settings.
2858
func GetDownloaderConfig() (*downloader.Config, error) {

arduino/resources/helpers.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ package resources
1717

1818
import (
1919
"fmt"
20-
"os"
2120

2221
"github.com/arduino/go-paths-helper"
23-
"go.bug.st/downloader/v2"
2422
)
2523

2624
// ArchivePath returns the path of the Archive of the specified DownloadResource relative
@@ -41,30 +39,3 @@ func (r *DownloadResource) IsCached(downloadDir *paths.Path) (bool, error) {
4139
}
4240
return archivePath.Exist(), nil
4341
}
44-
45-
// Download a DownloadResource.
46-
func (r *DownloadResource) Download(downloadDir *paths.Path, config *downloader.Config) (*downloader.Downloader, error) {
47-
path, err := r.ArchivePath(downloadDir)
48-
if err != nil {
49-
return nil, fmt.Errorf(tr("getting archive path: %s"), err)
50-
}
51-
52-
if _, err := path.Stat(); os.IsNotExist(err) {
53-
// normal download
54-
} else if err == nil {
55-
// check local file integrity
56-
ok, err := r.TestLocalArchiveIntegrity(downloadDir)
57-
if err != nil || !ok {
58-
if err := path.Remove(); err != nil {
59-
return nil, fmt.Errorf(tr("removing corrupted archive file: %s"), err)
60-
}
61-
} else {
62-
// File is cached, nothing to do here
63-
return nil, nil
64-
}
65-
} else {
66-
return nil, fmt.Errorf(tr("getting archive file info: %s"), err)
67-
}
68-
69-
return downloader.DownloadWithConfig(path.String(), r.URL, *config)
70-
}

0 commit comments

Comments
 (0)