@@ -4,13 +4,13 @@ import (
44 "mime"
55 "os"
66 "path/filepath"
7- "regexp"
87 "strings"
98
109 "github.com/aws/aws-sdk-go/aws"
1110 "github.com/aws/aws-sdk-go/aws/credentials"
1211 "github.com/aws/aws-sdk-go/aws/session"
1312 "github.com/aws/aws-sdk-go/service/s3"
13+ "github.com/bmatcuk/doublestar"
1414 "github.com/mattn/go-zglob"
1515 log "github.com/sirupsen/logrus"
1616)
@@ -75,7 +75,7 @@ type Plugin struct {
7575 PathStyle bool
7676 // Dry run without uploading/
7777 DryRun bool
78- // Regex for which files to remove from target
78+ // Glob for which files to remove from target
7979 TargetRemove string
8080}
8181
@@ -118,21 +118,12 @@ func (p *Plugin) Exec() error {
118118 }
119119
120120 if len (p .TargetRemove ) != 0 {
121- reg , regexperr := regexp .Compile (p .TargetRemove )
122-
123- if regexperr != nil {
124- log .WithFields (log.Fields {
125- "error" : regexperr ,
126- "regexp" : p .TargetRemove ,
127- }).Error ("Regular expression failed to compile" )
128- return regexperr
129- }
130121
131122 log .WithFields (log.Fields {
132- "regexp " : p .TargetRemove ,
133- }).Info ("Deleting files according to regexp " )
123+ "glob " : p .TargetRemove ,
124+ }).Info ("Deleting files according to glob " )
134125
135- log .Info ("Listing files in bucket" ) // @ToDo: Log.Debug
126+ log .Info ("Listing files in bucket" )
136127 list_input := & s3.ListObjectsInput {
137128 Bucket : & p .Bucket ,
138129 }
@@ -148,7 +139,18 @@ func (p *Plugin) Exec() error {
148139 var to_remove []string
149140 for _ , object := range s3_objects .Contents {
150141 filename := object .Key
151- if reg .MatchString (* filename ) {
142+
143+ globmatch , globerr := doublestar .PathMatch (p .TargetRemove , * filename )
144+
145+ if globerr != nil {
146+ log .WithFields (log.Fields {
147+ "error" : globerr ,
148+ "glob" : p .TargetRemove ,
149+ }).Error ("Error with provided glob" )
150+ return globerr
151+ }
152+
153+ if globmatch {
152154 to_remove = append (to_remove , * filename )
153155 }
154156 }
0 commit comments