mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 08:36:55 +03:00
Trailing slash in -storageDataPath was causing vmrestore to panic. The fix calls filepath.Clean() in Init() to normalize the path. Added a test to verify ListParts works correctly with a trailing slash. Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10823 PR https://github.com/VictoriaMetrics/VictoriaMetrics/pull/10825 --------- Signed-off-by: JAYICE <jayice.zhou@qq.com> Co-authored-by: Max Kotliar <mkotlyar@victoriametrics.com>
31 lines
685 B
Go
31 lines
685 B
Go
package fslocal
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestFSListPartsWithTrailingSlashInDir(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "testfile"), []byte("x"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// trailing slash must not cause ListParts to panic
|
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10823
|
|
fs := &FS{Dir: dir + string(filepath.Separator)}
|
|
if err := fs.Init(); err != nil {
|
|
t.Fatalf("Init error: %s", err)
|
|
}
|
|
defer fs.MustStop()
|
|
|
|
parts, err := fs.ListParts()
|
|
if err != nil {
|
|
t.Fatalf("ListParts error: %s", err)
|
|
}
|
|
if len(parts) != 1 {
|
|
t.Fatalf("expected 1 part, got %d", len(parts))
|
|
}
|
|
}
|