Skip to content

Commit

Permalink
Merge pull request #24 from tstromberg/overwritten
Browse files Browse the repository at this point in the history
Fix bug that silently overwrote queries from previously directories
  • Loading branch information
tstromberg authored Jan 8, 2024
2 parents 681a8f7 + 0950370 commit 5283bf5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cmd/osqtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func Apply(sourcePaths []string, output string, c Config) error {
func Pack(sourcePaths []string, output string, c Config) error {
mms := map[string]*query.Metadata{}
for _, path := range sourcePaths {
klog.Infof("Loading from %s ...", path)
mm, err := query.LoadFromDir(path)
if err != nil {
return fmt.Errorf("load from dir %s: %v", path, err)
Expand Down Expand Up @@ -377,9 +378,10 @@ func loadAndApply(paths []string, c Config) (map[string]*query.Metadata, error)
return nil, fmt.Errorf("stat: %w", err)
}

loaded := map[string]*query.Metadata{}
switch {
case s.IsDir():
mm, err = query.LoadFromDir(path)
loaded, err = query.LoadFromDir(path)
if err != nil {
return mm, fmt.Errorf("load from dir %s: %w", path, err)
}
Expand All @@ -388,16 +390,26 @@ func loadAndApply(paths []string, c Config) (map[string]*query.Metadata, error)
if err != nil {
return mm, fmt.Errorf("load pack %s: %w", path, err)
}
mm = p.Queries
loaded = p.Queries
default:
m, err := query.Load(path)
if err != nil {
return mm, fmt.Errorf("load %s: %w", path, err)
}
mm[m.Name] = m
loaded[m.Name] = m
}

for k, v := range loaded {
if mm[k] != nil {
return mm, fmt.Errorf("conflict: %q already loaded", k)
}
mm[k] = v
}

klog.Infof("Loaded %d queries from %s", len(loaded), path)
}

klog.Infof("Applying configuration to %d queries: %+v", len(mm), c)
if err := applyConfig(mm, c); err != nil {
return mm, fmt.Errorf("apply: %w", err)
}
Expand Down

0 comments on commit 5283bf5

Please sign in to comment.