Skip to content

Commit 7edf79e

Browse files
committed
Fix local path parsing on Windows
1 parent 16cd87b commit 7edf79e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

commands/instances.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/url"
2424
"os"
2525
"path"
26+
"runtime"
2627

2728
"github.com/arduino/arduino-cli/arduino/builder"
2829
"github.com/arduino/arduino-cli/arduino/cores"
@@ -212,8 +213,15 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
212213
continue
213214
}
214215

216+
logrus.WithField("url", URL).Print("Updating index")
217+
215218
if URL.Scheme == "file" {
216219
path := paths.New(URL.Path)
220+
if runtime.GOOS == "windows" {
221+
// Parsed local file URLs on Windows are returned with a leading /
222+
// so we remove it
223+
path = paths.New(URL.Path[1:])
224+
}
217225
pathJSON, err := path.Abs()
218226
if err != nil {
219227
return nil, fmt.Errorf("can't get absolute path of %v: %w", path, err)
@@ -223,7 +231,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
223231
return nil, fmt.Errorf("invalid package index in %s: %s", pathJSON, err)
224232
}
225233

226-
fi, _ := os.Stat(URL.Path)
234+
fi, _ := os.Stat(path.String())
227235
downloadCB(&rpc.DownloadProgress{
228236
File: "Updating index: " + pathJSON.Base(),
229237
TotalSize: fi.Size(),
@@ -232,8 +240,6 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
232240
continue
233241
}
234242

235-
logrus.WithField("url", URL).Print("Updating index")
236-
237243
var tmp *paths.Path
238244
if tmpFile, err := ioutil.TempFile("", ""); err != nil {
239245
return nil, fmt.Errorf("creating temp file for index download: %s", err)
@@ -669,6 +675,11 @@ func createInstance(ctx context.Context, getLibOnly bool) (*createInstanceResult
669675

670676
if URL.Scheme == "file" {
671677
path := paths.New(URL.Path)
678+
if runtime.GOOS == "windows" {
679+
// Parsed local file URLs on Windows are returned with a leading /
680+
// so we remove it
681+
path = paths.New(URL.Path[1:])
682+
}
672683
pathJSON, err := path.Abs()
673684
if err != nil {
674685
return nil, fmt.Errorf("can't get absolute path of %v: %w", path, err)

test/test_core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ def ordered(obj):
356356

357357

358358
def test_core_update_with_local_url(run_command):
359-
test_index = Path(__file__).parent / "testdata" / "test_index.json"
359+
test_index = str(Path(__file__).parent / "testdata" / "test_index.json")
360+
if platform.system() == "Windows":
361+
test_index = f"/{test_index}".replace("\\", "/")
362+
360363
res = run_command(f'core update-index --additional-urls="file://{test_index}"')
361364
assert res.ok
362365
assert "Updating index: test_index.json downloaded" in res.stdout

0 commit comments

Comments
 (0)