Skip to content

Commit

Permalink
wlog: use filepath for getting checkpoint number
Browse files Browse the repository at this point in the history
This changes usage of path to be replaced with path/filepath, allowing
for filepath.Base to properly return the base directory on systems where
`/` is not the standard path separator.

This resolves an issue on Windows where intermediate folders containing
a `.` were incorrectly considered to be a part of the checkpoint name.

Related to grafana/agent#3826.

Signed-off-by: Robert Fratto <robertfratto@gmail.com>
  • Loading branch information
rfratto committed May 10, 2023
1 parent bd98fc8 commit 9e4e2a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tsdb/wlog/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"io"
"math"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -156,7 +156,7 @@ func NewWatcher(metrics *WatcherMetrics, readerMetrics *LiveReaderMetrics, logge
writer: writer,
metrics: metrics,
readerMetrics: readerMetrics,
walDir: path.Join(dir, "wal"),
walDir: filepath.Join(dir, "wal"),
name: name,
sendExemplars: sendExemplars,
sendHistograms: sendHistograms,
Expand Down Expand Up @@ -691,7 +691,7 @@ func (w *Watcher) readCheckpoint(checkpointDir string, readFn segmentReadFn) err
func checkpointNum(dir string) (int, error) {
// Checkpoint dir names are in the format checkpoint.000001
// dir may contain a hidden directory, so only check the base directory
chunks := strings.Split(path.Base(dir), ".")
chunks := strings.Split(filepath.Base(dir), ".")
if len(chunks) != 2 {
return 0, errors.Errorf("invalid checkpoint dir string: %s", dir)
}
Expand Down

0 comments on commit 9e4e2a4

Please sign in to comment.