filter: allow multiple --exclude-if-present flags - fixes #6219

This commit is contained in:
albertony
2022-06-08 09:29:01 +02:00
parent 20aaeba547
commit f4f0e444bf
10 changed files with 31 additions and 24 deletions

View File

@@ -86,7 +86,7 @@ type Opt struct {
FilterFrom []string
ExcludeRule []string
ExcludeFrom []string
ExcludeFile string
ExcludeFile []string
IncludeRule []string
IncludeFrom []string
FilesFrom []string
@@ -392,8 +392,10 @@ func (f *Filter) ListContainsExcludeFile(entries fs.DirEntries) bool {
obj, ok := entry.(fs.Object)
if ok {
basename := path.Base(obj.Remote())
if basename == f.Opt.ExcludeFile {
return true
for _, excludeFile := range f.Opt.ExcludeFile {
if basename == excludeFile {
return true
}
}
}
}
@@ -436,12 +438,14 @@ func (f *Filter) IncludeDirectory(ctx context.Context, fs fs.Fs) func(string) (b
// empty string (for testing).
func (f *Filter) DirContainsExcludeFile(ctx context.Context, fremote fs.Fs, remote string) (bool, error) {
if len(f.Opt.ExcludeFile) > 0 {
exists, err := fs.FileExists(ctx, fremote, path.Join(remote, f.Opt.ExcludeFile))
if err != nil {
return false, err
}
if exists {
return true, nil
for _, excludeFile := range f.Opt.ExcludeFile {
exists, err := fs.FileExists(ctx, fremote, path.Join(remote, excludeFile))
if err != nil {
return false, err
}
if exists {
return true, nil
}
}
}
return false, nil