Skip to content

Commit

Permalink
Use correct filesystem/network path separators when uploading blocks
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
aknuds1 committed Apr 14, 2022
1 parent c4fe219 commit 04d10ef
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
41 changes: 40 additions & 1 deletion .bingo/prometheus.mod
Expand Up @@ -20,4 +20,43 @@ replace (
k8s.io/klog => github.com/simonpasquier/klog-gokit v0.1.0
)

require github.com/prometheus/prometheus v2.4.3+incompatible // cmd/prometheus
require (
github.com/Azure/azure-sdk-for-go v0.0.0-00010101000000-000000000000 // indirect
github.com/Azure/go-autorest v0.0.0-00010101000000-000000000000 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aws/aws-sdk-go v1.43.39 // indirect
github.com/cockroachdb/cmux v0.0.0-00010101000000-000000000000 // indirect
github.com/cockroachdb/cockroach v0.0.0-00010101000000-000000000000 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/googleapis/gnostic v0.0.0-00010101000000-000000000000 // indirect
github.com/gophercloud/gophercloud v0.0.0-00010101000000-000000000000 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/consul/api v1.12.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oklog/oklog v0.3.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing-contrib/go-stdlib v1.0.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/prometheus/prometheus v2.4.3+incompatible // cmd/prometheus
github.com/prometheus/tsdb v0.0.0-00010101000000-000000000000 // indirect
github.com/samuel/go-zookeeper v0.0.0-20201211165307-7117e9ea2414 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
google.golang.org/api v0.74.0 // indirect
google.golang.org/genproto v0.0.0-20220413183235-5e96e2839df9 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-00010101000000-000000000000 // indirect
k8s.io/apimachinery v0.0.0-00010101000000-000000000000 // indirect
k8s.io/client-go v0.0.0-00010101000000-000000000000 // indirect
)
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
## Unreleased

### Fixed
- [#5281](https://github.com/thanos-io/thanos/pull/5281) Blocks: Use correct separators for filesystem paths and object storage paths respectively.

### Added

Expand Down
4 changes: 2 additions & 2 deletions pkg/block/block.go
Expand Up @@ -145,11 +145,11 @@ func upload(ctx context.Context, logger log.Logger, bkt objstore.Bucket, bdir st
return errors.Wrap(err, "encode meta file")
}

if err := objstore.UploadDir(ctx, logger, bkt, path.Join(bdir, ChunksDirname), path.Join(id.String(), ChunksDirname)); err != nil {
if err := objstore.UploadDir(ctx, logger, bkt, filepath.Join(bdir, ChunksDirname), path.Join(id.String(), ChunksDirname)); err != nil {
return cleanUp(logger, bkt, id, errors.Wrap(err, "upload chunks"))
}

if err := objstore.UploadFile(ctx, logger, bkt, path.Join(bdir, IndexFilename), path.Join(id.String(), IndexFilename)); err != nil {
if err := objstore.UploadFile(ctx, logger, bkt, filepath.Join(bdir, IndexFilename), path.Join(id.String(), IndexFilename)); err != nil {
return cleanUp(logger, bkt, id, errors.Wrap(err, "upload index"))
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/objstore/objstore.go
Expand Up @@ -7,7 +7,9 @@ import (
"bytes"
"context"
"io"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -178,15 +180,19 @@ func UploadDir(ctx context.Context, logger log.Logger, bkt Bucket, srcdir, dstdi
if !df.IsDir() {
return errors.Errorf("%s is not a directory", srcdir)
}
return filepath.Walk(srcdir, func(src string, fi os.FileInfo, err error) error {
return filepath.WalkDir(srcdir, func(src string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if fi.IsDir() {
if d.IsDir() {
return nil
}
dst := filepath.Join(dstdir, strings.TrimPrefix(src, srcdir))
srcRel, err := filepath.Rel(srcdir, src)
if err != nil {
return errors.Wrap(err, "getting relative path")
}

dst := path.Join(dstdir, filepath.ToSlash(srcRel))
return UploadFile(ctx, logger, bkt, src, dst)
})
}
Expand Down

0 comments on commit 04d10ef

Please sign in to comment.