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
…5281)

Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 authored Apr 26, 2022
1 parent afa15e2 commit 7cf9309
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 7cf9309

Please sign in to comment.