@@ -184,14 +184,32 @@ func compressFolder(sourceDir string, filter string, sourceExclusionFilter strin
184
184
return outputFile .Name (), nil
185
185
}
186
186
187
- func filterMatched (filters []string , fileName string ) bool {
187
+ func filterMatched (filters []string , fileName string ) (bool , bool ) {
188
+ var matched = true
189
+ var firstMatch = true
190
+ var excluded = false
188
191
for _ , filter := range filters {
189
- matched , _ := path .Match (filter , fileName )
190
- if matched {
191
- return true
192
+ if filter [0 ] == '!' {
193
+ // it just needs to match one exclusion to be excluded.
194
+ if ! excluded {
195
+ excluded , _ = path .Match (filter [1 :], fileName )
196
+ }
197
+ } else {
198
+ // 1. If there are no inclusions everythng is considered included
199
+ // 2. If there is at least one included and nothing matches the its
200
+ // not included
201
+ // it just needs to match one thing to be matched
202
+ if firstMatch {
203
+ // Need to reset the match flag because now we need to find one.
204
+ matched = false
205
+ firstMatch = false
206
+ }
207
+ if ! matched {
208
+ matched , _ = path .Match (filter , fileName )
209
+ }
192
210
}
193
211
}
194
- return false
212
+ return matched , excluded
195
213
}
196
214
197
215
func addDirFiles (zip * zip.Writer , baseDir string , parentDir string , filters []string , exclusions []string ) {
@@ -205,11 +223,12 @@ func addDirFiles(zip *zip.Writer, baseDir string, parentDir string, filters []st
205
223
var matched = true
206
224
var excluded = false
207
225
if filters != nil {
208
- matched = filterMatched (filters , file .Name ())
209
- }
210
- if exclusions != nil {
211
- excluded = filterMatched (exclusions , file .Name ())
226
+ matched , excluded = filterMatched (filters , file .Name ())
212
227
}
228
+ // Exclusions have been moved to filters list
229
+ //if exclusions != nil {
230
+ // excluded = filterMatched(exclusions, file.Name())
231
+ //}
213
232
if matched && ! excluded {
214
233
fmt .Println ("Included: " , fileName )
215
234
dat , err := ioutil .ReadFile (parentDir + file .Name ())
0 commit comments