Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows fixes #101

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ on: [push]

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.18.0'
- run: go test ./pmtiles
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.18.0'
- run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
10 changes: 7 additions & 3 deletions pmtiles/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ func NormalizeBucketKey(bucket string, prefix string, key string) (string, strin
}
return u.Scheme + "://" + u.Host + dir, file, nil
} else {
fileprotocol := "file://"
if string(os.PathSeparator) != "/" {
fileprotocol += "/"
}
if prefix != "" {
abs, err := filepath.Abs(prefix)
if err != nil {
return "", "", err
}
return "file://" + abs, key, nil
return fileprotocol + filepath.ToSlash(abs), key, nil
}
abs, err := filepath.Abs(key)
if err != nil {
return "", "", err
}
return "file://" + filepath.Dir(abs), filepath.Base(abs), nil
return fileprotocol + filepath.ToSlash(filepath.Dir(abs)), filepath.Base(abs), nil
}
}

Expand All @@ -116,7 +120,7 @@ func OpenBucket(ctx context.Context, bucketURL string, bucketPrefix string) (Buc
if err != nil {
return nil, err
}
if bucketPrefix != "/" && bucketPrefix != "." {
if bucketPrefix != "" && bucketPrefix != "/" && bucketPrefix != "." {
bucket = blob.PrefixedBucket(bucket, path.Clean(bucketPrefix)+string(os.PathSeparator))
}
wrapped_bucket := BucketAdapter{bucket}
Expand Down
13 changes: 11 additions & 2 deletions pmtiles/bucket_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pmtiles

import (
"fmt"
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)
Expand All @@ -14,6 +14,15 @@ func TestNormalizeLocalFile(t *testing.T) {
assert.True(t, strings.HasPrefix(bucket, "file://"))
}

func TestNormalizeLocalFileWindows(t *testing.T) {
if string(os.PathSeparator) != "/" {
bucket, key, _ := NormalizeBucketKey("", "", "\\foo\\bar.pmtiles")
assert.Equal(t, "bar.pmtiles", key)
assert.True(t, strings.HasSuffix(bucket, "/foo"))
assert.True(t, strings.HasPrefix(bucket, "file://"))
}
}

func TestNormalizeHttp(t *testing.T) {
bucket, key, _ := NormalizeBucketKey("", "", "http://example.com/foo/bar.pmtiles")
assert.Equal(t, "bar.pmtiles", key)
Expand All @@ -25,10 +34,10 @@ func TestNormalizeAwsSdkVersion(t *testing.T) {
assert.Equal(t, "abc", key)
assert.Equal(t, "s3://mybucket?awssdk=v2&endpoint=https%3A%2F%2Ffoo.bar", bucket)
}

func TestNormalizePathPrefixServer(t *testing.T) {
bucket, key, _ := NormalizeBucketKey("", "../foo", "")
assert.Equal(t, "", key)
fmt.Println(bucket)
assert.True(t, strings.HasSuffix(bucket, "/foo"))
assert.True(t, strings.HasPrefix(bucket, "file://"))
}