Skip to content

Commit 54bf95c

Browse files
fix: support absolute file paths in check-schema (#23991) (#27067)
Co-authored-by: davidby-influx <72418212+davidby-influx@users.noreply.github.com> closes #23987
1 parent 38156bc commit 54bf95c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

cmd/influxd/inspect/type_conflicts/check_schema.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/influxdata/influxdb/v2/kit/cli"
14+
errors2 "github.com/influxdata/influxdb/v2/pkg/errors"
1415
"github.com/influxdata/influxdb/v2/tsdb"
1516
"github.com/spf13/cobra"
1617
"github.com/spf13/viper"
@@ -82,6 +83,11 @@ func checkSchemaRunE(_ *cobra.Command, tc TypeConflictChecker) error {
8283

8384
// Get a set of every measurement/field/type tuple present.
8485
var schema Schema
86+
87+
tc.Path, err = filepath.Abs(tc.Path)
88+
if err != nil {
89+
return err
90+
}
8591
schema, err = tc.readFields()
8692
if err != nil {
8793
return err
@@ -109,8 +115,7 @@ func (tc *TypeConflictChecker) readFields() (Schema, error) {
109115
} else {
110116
root = path.Dir(tc.Path)
111117
}
112-
fileSystem := os.DirFS(".")
113-
err = fs.WalkDir(fileSystem, root, func(path string, d fs.DirEntry, err error) error {
118+
err = filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) (rErr error) {
114119
if err != nil {
115120
return fmt.Errorf("error walking file: %w", err)
116121
}
@@ -128,6 +133,9 @@ func (tc *TypeConflictChecker) readFields() (Schema, error) {
128133
}
129134

130135
dirs := strings.Split(path, string(os.PathSeparator))
136+
if len(dirs) < 4 {
137+
return fmt.Errorf("wrong directory structure for InfluxDB: %q", path)
138+
}
131139
bucket := dirs[len(dirs)-4]
132140
rp := dirs[len(dirs)-3]
133141
fmt.Printf("Processing %s\n", path)
@@ -139,7 +147,7 @@ func (tc *TypeConflictChecker) readFields() (Schema, error) {
139147
}
140148
return fmt.Errorf("unable to open file %q: %w", path, err)
141149
}
142-
defer mfs.Close()
150+
defer errors2.Capture(&rErr, mfs.Close)()
143151

144152
measurements := mfs.MeasurementNames()
145153
for _, m := range measurements {

0 commit comments

Comments
 (0)