mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/backup: consistently use path.Join() when constructing paths for s3, gs and azblob
E.g. replace `fs.Dir + filePath` with `path.Join(fs.Dir, filePath)` The fs.Dir is guaranteed to end with slash - see Init() functions. The filePath may start with slash. If it starts with slash, then `fs.Dir + filePath` constructs an incorrect path with double slashes. path.Join() properly substitutes duplicate slashes with a single slash in this case. While at it, also substitute incorrect usage of filepath.Join() with path.Join() for constructing paths to object storage systems, which expect forward slashes in paths. filepath.Join() substittues forward slashes with backslashes on Windows, so this may break creating or managing backups from Windows. This is a follow-up for 0399367be602b577baf6a872ca81bf0f99ba401b Updates https://github.com/VictoriaMetrics/VictoriaMetrics-enterprise/pull/719
This commit is contained in:
parent
10d92c2600
commit
a2ad5ce773
5 changed files with 20 additions and 13 deletions
|
@ -16,7 +16,6 @@ The following `tip` changes can be tested by building VictoriaMetrics components
|
|||
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): prevent from `FATAL: cannot flush metainfo` panic when [`-remoteWrite.multitenantURL`](https://docs.victoriametrics.com/vmagent.html#multitenancy) command-line flag is set. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5357).
|
||||
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly decode zstd-encoded data blocks received via [VictoriaMetrics remote_write protocol](https://docs.victoriametrics.com/vmagent.html#victoriametrics-remote-write-protocol). See [this issue comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5301#issuecomment-1815871992).
|
||||
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly add new labels at `output_relabel_configs` during [stream aggregation](https://docs.victoriametrics.com/stream-aggregation.html). Previously this could lead to corrupted labels in output samples. Thanks to @ChengChung for providing [detailed report for this bug](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5402).
|
||||
* BUGFIX: [vmbackupmanager](https://docs.victoriametrics.com/vmbackupmanager.html): fix `vmbackupmanager` not deleting previous object versions from S3 when applying retention policy with `-deleteAllObjectVersions` command-line flag.
|
||||
|
||||
## [v1.93.8](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.8)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -277,7 +278,7 @@ func (fs *FS) DeleteFile(filePath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
bc := fs.clientForPath(path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -294,7 +295,7 @@ func (fs *FS) DeleteFile(filePath string) error {
|
|||
//
|
||||
// The file is overwritten if it exists.
|
||||
func (fs *FS) CreateFile(filePath string, data []byte) error {
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
bc := fs.clientForPath(path)
|
||||
|
||||
ctx := context.Background()
|
||||
|
@ -311,8 +312,7 @@ func (fs *FS) CreateFile(filePath string, data []byte) error {
|
|||
|
||||
// HasFile returns true if filePath exists at fs.
|
||||
func (fs *FS) HasFile(filePath string) (bool, error) {
|
||||
path := fs.Dir + filePath
|
||||
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
bc := fs.clientForPath(path)
|
||||
|
||||
ctx := context.Background()
|
||||
|
|
|
@ -45,12 +45,18 @@ type RemoteFS interface {
|
|||
// UploadPart must upload part p from r to RemoteFS.
|
||||
UploadPart(p Part, r io.Reader) error
|
||||
|
||||
// DeleteFile deletes filePath at RemoteFS
|
||||
// DeleteFile deletes filePath at RemoteFS.
|
||||
//
|
||||
// filePath must use / as directory delimiters.
|
||||
DeleteFile(filePath string) error
|
||||
|
||||
// CreateFile creates filePath at RemoteFS and puts data into it.
|
||||
//
|
||||
// filePath must use / as directory delimiters.
|
||||
CreateFile(filePath string, data []byte) error
|
||||
|
||||
// HasFile returns true if filePath exists at RemoteFS.
|
||||
//
|
||||
// filePath must use / as directory delimiters.
|
||||
HasFile(filePath string) (bool, error)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -214,7 +215,7 @@ func (fs *FS) object(p common.Part) *storage.ObjectHandle {
|
|||
//
|
||||
// The function does nothing if the filePath doesn't exists.
|
||||
func (fs *FS) DeleteFile(filePath string) error {
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
o := fs.bkt.Object(path)
|
||||
ctx := context.Background()
|
||||
if err := o.Delete(ctx); err != nil {
|
||||
|
@ -229,7 +230,7 @@ func (fs *FS) DeleteFile(filePath string) error {
|
|||
//
|
||||
// The file is overwritten if it exists.
|
||||
func (fs *FS) CreateFile(filePath string, data []byte) error {
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
o := fs.bkt.Object(path)
|
||||
ctx := context.Background()
|
||||
w := o.NewWriter(ctx)
|
||||
|
@ -250,7 +251,7 @@ func (fs *FS) CreateFile(filePath string, data []byte) error {
|
|||
|
||||
// HasFile returns ture if filePath exists at fs.
|
||||
func (fs *FS) HasFile(filePath string) (bool, error) {
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
o := fs.bkt.Object(path)
|
||||
ctx := context.Background()
|
||||
_, err := o.Attrs(ctx)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
|
@ -53,7 +54,7 @@ type FS struct {
|
|||
// Path to S3 configs file.
|
||||
ConfigFilePath string
|
||||
|
||||
// GCS bucket to use.
|
||||
// S3 bucket to use.
|
||||
Bucket string
|
||||
|
||||
// Directory in the bucket to write to.
|
||||
|
@ -300,7 +301,7 @@ func (fs *FS) DeleteFile(filePath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
input := &s3.DeleteObjectInput{
|
||||
Bucket: aws.String(fs.Bucket),
|
||||
Key: aws.String(path),
|
||||
|
@ -315,7 +316,7 @@ func (fs *FS) DeleteFile(filePath string) error {
|
|||
//
|
||||
// The file is overwritten if it already exists.
|
||||
func (fs *FS) CreateFile(filePath string, data []byte) error {
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
sr := &statReader{
|
||||
r: bytes.NewReader(data),
|
||||
}
|
||||
|
@ -338,7 +339,7 @@ func (fs *FS) CreateFile(filePath string, data []byte) error {
|
|||
|
||||
// HasFile returns true if filePath exists at fs.
|
||||
func (fs *FS) HasFile(filePath string) (bool, error) {
|
||||
path := fs.Dir + filePath
|
||||
path := path.Join(fs.Dir, filePath)
|
||||
input := &s3.GetObjectInput{
|
||||
Bucket: aws.String(fs.Bucket),
|
||||
Key: aws.String(path),
|
||||
|
|
Loading…
Reference in a new issue