Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package config

import (
"fmt"
"os"
"path/filepath"
"strings"
)

// collectConfigFiles scans searchPaths for files ending in suffix and returns
// a name -> filepath map. Earlier paths take priority (first occurrence wins).
// The name is derived by trimming the suffix from the filename.
func collectConfigFiles(searchPaths []string, suffix string) (map[string]string, error) {
files := make(map[string]string)

for _, dir := range searchPaths {
entries, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
continue
}
return nil, fmt.Errorf("failed to read directory %s: %w", dir, err)
}

for _, entry := range entries {
if entry.IsDir() {
continue
}
if !strings.HasSuffix(entry.Name(), suffix) {
continue
}

name := strings.TrimSuffix(entry.Name(), suffix)
if _, exists := files[name]; !exists {
files[name] = filepath.Join(dir, entry.Name())
}
}
}

return files, nil
}
30 changes: 5 additions & 25 deletions config/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"gopkg.in/ini.v1"
)

const featureSuffix = ".feature"

// Feature represents a parsed .feature configuration file
type Feature struct {
Name string // Derived from filename (e.g., "devel" from "devel.feature")
Expand All @@ -35,31 +37,9 @@ func LoadFeatures(customPath string) ([]*Feature, error) {
}

// Collect all .feature files, with earlier paths taking priority
featureFiles := make(map[string]string) // feature name -> file path

for _, dir := range searchPaths {
entries, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
continue
}
return nil, fmt.Errorf("failed to read directory %s: %w", dir, err)
}

for _, entry := range entries {
if entry.IsDir() {
continue
}
if !strings.HasSuffix(entry.Name(), ".feature") {
continue
}

featureName := strings.TrimSuffix(entry.Name(), ".feature")
if _, exists := featureFiles[featureName]; !exists {
// Earlier paths take priority
featureFiles[featureName] = filepath.Join(dir, entry.Name())
}
}
featureFiles, err := collectConfigFiles(searchPaths, featureSuffix)
if err != nil {
return nil, err
}

if len(featureFiles) == 0 {
Expand Down
31 changes: 5 additions & 26 deletions config/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"cmp"
"fmt"
"os"
"path/filepath"
"runtime"
"slices"
"strings"

"gopkg.in/ini.v1"
)

const transferSuffix = ".transfer"

// Transfer represents a parsed .transfer configuration file
type Transfer struct {
Component string // Derived from filename
Expand Down Expand Up @@ -93,31 +94,9 @@ func LoadTransfers(customPath string) ([]*Transfer, error) {
}

// Collect all .transfer files, with earlier paths taking priority
transferFiles := make(map[string]string) // component name -> file path

for _, dir := range searchPaths {
entries, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {
continue
}
return nil, fmt.Errorf("failed to read directory %s: %w", dir, err)
}

for _, entry := range entries {
if entry.IsDir() {
continue
}
if !strings.HasSuffix(entry.Name(), ".transfer") {
continue
}

component := strings.TrimSuffix(entry.Name(), ".transfer")
if _, exists := transferFiles[component]; !exists {
// Earlier paths take priority
transferFiles[component] = filepath.Join(dir, entry.Name())
}
}
transferFiles, err := collectConfigFiles(searchPaths, transferSuffix)
if err != nil {
return nil, err
}

if len(transferFiles) == 0 {
Expand Down
Loading