Skip to content

Commit f289f3b

Browse files
author
Roberto Sora
committed
replace PathEscaping with encoding in base64 for downloaded index filenames in order to be compatible on windows FS
1 parent 8f30419 commit f289f3b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

v2/pkgs/indexes.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pkgs
22

33
import (
44
"context"
5+
b64 "encoding/base64"
56
"encoding/json"
67
"io/ioutil"
78
"net/url"
@@ -31,7 +32,7 @@ func (c *Indexes) Add(ctx context.Context, payload *indexes.IndexPayload) (*inde
3132
}
3233

3334
// Download tmp file
34-
filename := url.PathEscape(payload.URL)
35+
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(payload.URL)))
3536
path := filepath.Join(c.Folder, filename+".tmp")
3637
d, err := downloader.Download(path, indexURL.String())
3738
if err != nil {
@@ -53,7 +54,7 @@ func (c *Indexes) Add(ctx context.Context, payload *indexes.IndexPayload) (*inde
5354

5455
// Get reads the index file from the Indexes Folder, unmarshaling it
5556
func (c *Indexes) Get(ctx context.Context, uri string) (index Index, err error) {
56-
filename := url.PathEscape(uri)
57+
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(uri)))
5758
path := filepath.Join(c.Folder, filename)
5859
data, err := ioutil.ReadFile(path)
5960
if err != nil {
@@ -74,17 +75,20 @@ func (c *Indexes) List(context.Context) ([]string, error) {
7475
_ = os.MkdirAll(c.Folder, 0755)
7576
// Read files
7677
files, err := ioutil.ReadDir(c.Folder)
78+
7779
if err != nil {
7880
return nil, err
7981
}
8082

8183
res := []string{}
8284
for _, file := range files {
8385
// Select only files that begin with http
84-
if !strings.HasPrefix(file.Name(), "http") {
86+
decodedFileName, _ := b64.URLEncoding.DecodeString(file.Name())
87+
fileName:=string(decodedFileName)
88+
if !strings.HasPrefix(fileName, "http") {
8589
continue
8690
}
87-
path, err := url.PathUnescape(file.Name())
91+
path, err := url.PathUnescape(fileName)
8892
if err != nil {
8993
c.Log.Warn(err)
9094
}
@@ -96,7 +100,7 @@ func (c *Indexes) List(context.Context) ([]string, error) {
96100

97101
// Remove deletes the index file from the Indexes Folder
98102
func (c *Indexes) Remove(ctx context.Context, payload *indexes.IndexPayload) (*indexes.Operation, error) {
99-
filename := url.PathEscape(payload.URL)
103+
filename := b64.StdEncoding.EncodeToString([]byte(url.PathEscape(payload.URL)))
100104
err := os.RemoveAll(filepath.Join(c.Folder, filename))
101105
if err != nil {
102106
return nil, err

0 commit comments

Comments
 (0)