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
3 changes: 2 additions & 1 deletion backup/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"backup-rsync/backup/internal"
"fmt"
"slices"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,7 +39,7 @@ func buildConfigCommand() *cobra.Command {
Short: "Manage configuration",
}

for _, verb := range configVerbs {
for verb := range slices.Values(configVerbs) {
configCmd.AddCommand(&cobra.Command{
Use: verb.use,
Short: verb.short,
Expand Down
3 changes: 2 additions & 1 deletion backup/cmd/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log/slog"
"slices"
"strings"
"time"

Expand All @@ -31,7 +32,7 @@ func parseSetFlags(cmd *cobra.Command) map[string]string {
setFlags, _ := cmd.Flags().GetStringArray("set")
overrides := make(map[string]string, len(setFlags))

for _, s := range setFlags {
for s := range slices.Values(setFlags) {
key, value, ok := strings.Cut(s, "=")
if ok {
overrides[key] = value
Expand Down
12 changes: 6 additions & 6 deletions backup/internal/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type CoverageChecker struct {
}

func (c *CoverageChecker) IsExcludedGlobally(path string, mappings []Mapping) bool {
for _, mapping := range mappings {
for _, exclusion := range mapping.Exclusions {
for mapping := range slices.Values(mappings) {
for exclusion := range slices.Values(mapping.Exclusions) {
exclusionPath := filepath.Join(mapping.Source, exclusion)
if strings.HasPrefix(NormalizePath(path), exclusionPath) {
c.Logger.Info(fmt.Sprintf("EXCLUDED: Path '%s' is globally excluded by '%s' in source '%s'",
Expand All @@ -37,7 +37,7 @@ func (c *CoverageChecker) ListUncoveredPaths(cfg Config) []string {

seen := make(map[string]bool)

for _, mapping := range cfg.Mappings {
for mapping := range slices.Values(cfg.Mappings) {
c.checkPath(mapping.Source, cfg.Mappings, &result, seen)
}

Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *CoverageChecker) isCoveredByJob(path string, job Job) bool {
}

func (c *CoverageChecker) isCovered(path string, mappings []Mapping) bool {
for _, mapping := range mappings {
for mapping := range slices.Values(mappings) {
if slices.ContainsFunc(mapping.Jobs, func(job Job) bool {
return c.isCoveredByJob(path, job)
}) {
Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *CoverageChecker) isEffectivelyCovered(path string, mappings []Mapping)

allCovered := true

for _, child := range children {
for child := range slices.Values(children) {
covered := c.IsExcludedGlobally(child, mappings) || c.isCovered(child, mappings) ||
c.isEffectivelyCovered(child, mappings)
if !covered {
Expand All @@ -162,7 +162,7 @@ func getChildDirectories(fs afero.Fs, path string) ([]string, error) {
return nil, fmt.Errorf("failed to read directory '%s': %w", path, err)
}

for _, info := range fileInfos {
for info := range slices.Values(fileInfos) {
if info.IsDir() {
children = append(children, filepath.Join(path, info.Name()))
}
Expand Down
12 changes: 6 additions & 6 deletions backup/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Config struct {
// AllJobs returns a flat list of all jobs across all mappings.
func (cfg Config) AllJobs() []Job {
var jobs []Job
for _, m := range cfg.Mappings {
for m := range slices.Values(cfg.Mappings) {
jobs = append(jobs, m.Jobs...)
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func (cfg Config) Apply(rsync JobCommand, logger *slog.Logger) error {
counts := make(map[JobStatus]int)
allJobs := cfg.AllJobs()

for _, job := range allJobs {
for job := range slices.Values(allJobs) {
status := job.Apply(rsync)
rsync.ReportJobStatus(job.Name, status, logger)
counts[status]++
Expand Down Expand Up @@ -240,7 +240,7 @@ func ValidateJobNames(jobs []Job) error {

nameSet := make(map[string]bool)

for _, job := range jobs {
for job := range slices.Values(jobs) {
if nameSet[job.Name] {
invalidNames = append(invalidNames, "duplicate job name: "+job.Name)
} else {
Expand Down Expand Up @@ -288,7 +288,7 @@ func ValidateTemplateVars(cfg Config) error {

var missing []string

for _, v := range cfg.Template.Variables {
for v := range slices.Values(cfg.Template.Variables) {
if _, ok := cfg.Variables[v]; !ok {
missing = append(missing, v)
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func loadTemplateConfig(templatePath string) (Config, error) {
}

func expandIncludes(cfg *Config, configDir string) error {
for _, inc := range cfg.Include {
for inc := range slices.Values(cfg.Include) {
templatePath := inc.Uses
if !filepath.IsAbs(templatePath) {
templatePath = filepath.Join(configDir, templatePath)
Expand Down Expand Up @@ -357,7 +357,7 @@ func expandIncludes(cfg *Config, configDir string) error {
}

func mergeOverrides(cfg Config, overrides []map[string]string) Config {
for _, override := range overrides {
for override := range slices.Values(overrides) {
if cfg.Variables == nil {
cfg.Variables = make(map[string]string)
}
Expand Down
5 changes: 3 additions & 2 deletions backup/internal/macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"errors"
"fmt"
"slices"
"strings"
"unicode"
)
Expand Down Expand Up @@ -210,7 +211,7 @@ func findInnermostMacro(input string) (int, int, string, string, bool) {
func ValidateNoUnresolvedMacros(cfg Config) error {
var errs []error

for _, mapping := range cfg.Mappings {
for mapping := range slices.Values(cfg.Mappings) {
for _, field := range []struct {
name, value string
}{
Expand All @@ -224,7 +225,7 @@ func ValidateNoUnresolvedMacros(cfg Config) error {
}
}

for _, job := range mapping.Jobs {
for job := range slices.Values(mapping.Jobs) {
for _, field := range []struct {
name, value string
}{
Expand Down
3 changes: 2 additions & 1 deletion backup/internal/rsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"os"
"path/filepath"
"slices"
"strings"
)

Expand Down Expand Up @@ -120,7 +121,7 @@ func ArgumentsForJob(job Job, logPath string, simulate bool) []string {
args = append(args, "--log-file="+logPath)
}

for _, excl := range job.Exclusions {
for excl := range slices.Values(job.Exclusions) {
args = append(args, "--exclude="+excl)
}

Expand Down
3 changes: 2 additions & 1 deletion backup/internal/testutil/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testutil

import (
"fmt"
"slices"
"strings"
)

Expand Down Expand Up @@ -66,7 +67,7 @@ func (b *ConfigBuilder) AddJobToMapping(name, source, target string, opts ...Job
}

job := jobDef{name: name, source: source, target: target}
for _, opt := range opts {
for opt := range slices.Values(opts) {
opt(&job)
}

Expand Down
7 changes: 5 additions & 2 deletions backup/internal/testutil/job.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package testutil

import "backup-rsync/backup/internal"
import (
"backup-rsync/backup/internal"
"slices"
)

// TestJobOpt configures a test Job struct.
type TestJobOpt func(*internal.Job)
Expand All @@ -17,7 +20,7 @@ func NewTestJob(opts ...TestJobOpt) internal.Job {
Exclusions: []string{"*.tmp"},
}

for _, opt := range opts {
for opt := range slices.Values(opts) {
opt(&job)
}

Expand Down
Loading