Skip to content

Commit

Permalink
change(rclone): build --filter based on include/excludes set on the c…
Browse files Browse the repository at this point in the history
…heck
  • Loading branch information
l3uddz committed Apr 27, 2020
1 parent 9cfecfa commit aadfc2b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
26 changes: 26 additions & 0 deletions rclone/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package rclone

import "fmt"

func IncludeExcludeToFilters(includes []string, excludes []string) []string {
params := make([]string, 0)

// add excludes
if len(excludes) > 0 {
for _, exclude := range excludes {
params = append(params, "--filter", fmt.Sprintf("- %s", exclude))
}
}

// were there includes?
if len(includes) > 0 {
for _, include := range includes {
params = append(params, "--filter", fmt.Sprintf("+ %s", include))
}

// includes need the below, see: https://forum.rclone.org/t/filter-or-include-exclude-help-needed/10890/2
params = append(params, "--filter", "- *")
}

return params
}
11 changes: 2 additions & 9 deletions uploader/checker/age.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/l3uddz/crop/config"
"github.com/l3uddz/crop/pathutils"
"github.com/l3uddz/crop/rclone"
"github.com/sirupsen/logrus"
"time"
)
Expand Down Expand Up @@ -69,15 +70,7 @@ func (Age) RcloneParams(cfg *config.UploaderCheck, log *logrus.Entry) []string {
}

// add filters
for _, include := range cfg.Include {
params = append(params,
"--include", include)
}

for _, exclude := range cfg.Exclude {
params = append(params,
"--exclude", exclude)
}
params = append(params, rclone.IncludeExcludeToFilters(cfg.Include, cfg.Exclude)...)

return params
}
16 changes: 2 additions & 14 deletions uploader/checker/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/l3uddz/crop/config"
"github.com/l3uddz/crop/pathutils"
"github.com/l3uddz/crop/rclone"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -33,18 +34,5 @@ func (Size) CheckFile(cfg *config.UploaderCheck, log *logrus.Entry, path pathuti
}

func (Size) RcloneParams(cfg *config.UploaderCheck, log *logrus.Entry) []string {
params := make([]string, 0)

// add filters
for _, include := range cfg.Include {
params = append(params,
"--include", include)
}

for _, exclude := range cfg.Exclude {
params = append(params,
"--exclude", exclude)
}

return params
return rclone.IncludeExcludeToFilters(cfg.Include, cfg.Exclude)
}

0 comments on commit aadfc2b

Please sign in to comment.