Skip to content

Commit 09e048c

Browse files
committed
Inline file:// path cleanup
1 parent 8991083 commit 09e048c

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

internal/modproxy/modproxy.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"os"
1212
"path"
1313
"path/filepath"
14-
"runtime"
1514
"slices"
1615
"strconv"
1716
"strings"
@@ -74,12 +73,14 @@ func httpRequest(u *neturl.URL, subpath string, cached bool) (*http.Response, er
7473
}
7574

7675
func fileRequest(u *neturl.URL, subpath string) (*http.Response, error) {
77-
root, err := fileURLToPath(u)
78-
if err != nil {
79-
return nil, err
80-
}
81-
full := filepath.Join(root, filepath.FromSlash(subpath))
82-
f, err := os.Open(full)
76+
root := u.Path
77+
if filepath.VolumeName(root) != "" {
78+
root, _ = strings.CutPrefix(root, "/")
79+
}
80+
f, err := os.Open(filepath.Join(
81+
filepath.FromSlash(root),
82+
filepath.FromSlash(subpath),
83+
))
8384
if err != nil {
8485
if os.IsNotExist(err) {
8586
return &http.Response{
@@ -103,16 +104,6 @@ func fileRequest(u *neturl.URL, subpath string) (*http.Response, error) {
103104
}, nil
104105
}
105106

106-
func fileURLToPath(u *neturl.URL) (string, error) {
107-
p := u.Path
108-
if runtime.GOOS == "windows" {
109-
if len(p) >= 3 && p[0] == '/' && p[2] == ':' {
110-
p = p[1:]
111-
}
112-
}
113-
return filepath.FromSlash(p), nil
114-
}
115-
116107
// Module contains the module path and versions
117108
type Module struct {
118109
Path string

0 commit comments

Comments
 (0)