Skip to content

Commit 4c539b9

Browse files
authored
Fix bogus "wrong file size" error in some rare cases (arduino#1810)
* packagemanager: Show size difference between package_index and downloaded file This will help identify the problem: - if the file is corrupted - if the package_index is wrong - if there is a bug in the CLI (more rare... but actually possible :-) * Load package indexes after installed packages The installed packages keeps an extract of the original package_index.json, at the moment of the installation, inside a file named installed.json. This extract may turn out useful if the original package_XXX_index.json is lost or removed to keep the platform functional. On the other hand, if the original package_XXX_index.json is modified the information kept in the installed.json may be outdated and should be replaced by the upstream index: this is the reason why it's loaded after the hardware platforms.
1 parent 4fd9583 commit 4c539b9

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

arduino/resources/checksums.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (r *DownloadResource) TestLocalArchiveSize(downloadDir *paths.Path) (bool,
9494
return false, fmt.Errorf(tr("getting archive info: %s"), err)
9595
}
9696
if info.Size() != r.Size {
97-
return false, fmt.Errorf(tr("fetched archive size differs from size specified in index"))
97+
return false, fmt.Errorf("%s: %d != %d", tr("fetched archive size differs from size specified in index"), info.Size(), r.Size)
9898
}
9999

100100
return true, nil

commands/instances.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,27 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
238238
return pm.LoadToolsFromPackageDir(builtinPackage, pm.PackagesDir.Join("builtin", "tools"))
239239
}
240240

241+
// Load Platforms
242+
if profile == nil {
243+
for _, err := range pm.LoadHardware() {
244+
s := &arduino.PlatformLoadingError{Cause: err}
245+
responseError(s.ToRPCStatus())
246+
}
247+
} else {
248+
// Load platforms from profile
249+
errs := pm.LoadHardwareForProfile(
250+
profile, true, downloadCallback, taskCallback,
251+
)
252+
for _, err := range errs {
253+
s := &arduino.PlatformLoadingError{Cause: err}
254+
responseError(s.ToRPCStatus())
255+
}
256+
257+
// Load "builtin" tools
258+
_ = loadBuiltinTools()
259+
}
260+
261+
// Load packages index
241262
urls := []string{globals.DefaultIndexURL}
242263
if profile == nil {
243264
urls = append(urls, configuration.Settings.GetStringSlice("board_manager.additional_urls")...)
@@ -265,26 +286,6 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
265286
}
266287
}
267288

268-
// Load Platforms
269-
if profile == nil {
270-
for _, err := range pm.LoadHardware() {
271-
s := &arduino.PlatformLoadingError{Cause: err}
272-
responseError(s.ToRPCStatus())
273-
}
274-
} else {
275-
// Load platforms from profile
276-
errs := pm.LoadHardwareForProfile(
277-
profile, true, downloadCallback, taskCallback,
278-
)
279-
for _, err := range errs {
280-
s := &arduino.PlatformLoadingError{Cause: err}
281-
responseError(s.ToRPCStatus())
282-
}
283-
284-
// Load "builtin" tools
285-
_ = loadBuiltinTools()
286-
}
287-
288289
// We load hardware before verifying builtin tools are installed
289290
// otherwise we wouldn't find them and reinstall them each time
290291
// and they would never get reloaded.

0 commit comments

Comments
 (0)