mirror of
https://github.com/rclone/rclone.git
synced 2025-02-19 20:11:15 +01:00
Make --include rules add their implict exclude * at the end of the filter list
This means you can mix `--include` and `--include-from` with the other filters (eg `--exclude`) but you must include all the files you want in the include statement. Fixes #280
This commit is contained in:
parent
01aa4394a6
commit
af5f4ee724
@ -152,7 +152,11 @@ Add a single include rule with `--include`.
|
|||||||
Eg `--include *.{png,jpg}` to include all `png` and `jpg` files in the
|
Eg `--include *.{png,jpg}` to include all `png` and `jpg` files in the
|
||||||
backup and no others.
|
backup and no others.
|
||||||
|
|
||||||
This adds an implicit `--exclude *` at the end of the filter list.
|
This adds an implicit `--exclude *` at the very end of the filter
|
||||||
|
list. This means you can mix `--include` and `--include-from` with the
|
||||||
|
other filters (eg `--exclude`) but you must include all the files you
|
||||||
|
want in the include statement. If this doesn't provide enough
|
||||||
|
flexibility then you must use `--filter-from`.
|
||||||
|
|
||||||
### `--include-from` - Read include patterns from file ###
|
### `--include-from` - Read include patterns from file ###
|
||||||
|
|
||||||
@ -170,7 +174,11 @@ Then use as `--include-from include-file.txt`. This will sync all
|
|||||||
|
|
||||||
This is useful if you have a lot of rules.
|
This is useful if you have a lot of rules.
|
||||||
|
|
||||||
This adds an implicit `--exclude *` at the end of the filter list.
|
This adds an implicit `--exclude *` at the very end of the filter
|
||||||
|
list. This means you can mix `--include` and `--include-from` with the
|
||||||
|
other filters (eg `--exclude`) but you must include all the files you
|
||||||
|
want in the include statement. If this doesn't provide enough
|
||||||
|
flexibility then you must use `--filter-from`.
|
||||||
|
|
||||||
### `--filter` - Add a file-filtering rule ###
|
### `--filter` - Add a file-filtering rule ###
|
||||||
|
|
||||||
|
19
fs/filter.go
19
fs/filter.go
@ -117,17 +117,14 @@ func NewFilter() (f *Filter, err error) {
|
|||||||
MinSize: int64(minSize),
|
MinSize: int64(minSize),
|
||||||
MaxSize: int64(maxSize),
|
MaxSize: int64(maxSize),
|
||||||
}
|
}
|
||||||
|
addImplicitExclude := false
|
||||||
|
|
||||||
if *includeRule != "" {
|
if *includeRule != "" {
|
||||||
err = f.Add(true, *includeRule)
|
err = f.Add(true, *includeRule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Add implicit exclude
|
addImplicitExclude = true
|
||||||
err = f.Add(false, "*")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if *includeFrom != "" {
|
if *includeFrom != "" {
|
||||||
err := forEachLine(*includeFrom, func(line string) error {
|
err := forEachLine(*includeFrom, func(line string) error {
|
||||||
@ -136,11 +133,7 @@ func NewFilter() (f *Filter, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Add implicit exclude
|
addImplicitExclude = true
|
||||||
err = f.Add(false, "*")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if *excludeRule != "" {
|
if *excludeRule != "" {
|
||||||
err = f.Add(false, *excludeRule)
|
err = f.Add(false, *excludeRule)
|
||||||
@ -176,6 +169,12 @@ func NewFilter() (f *Filter, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if addImplicitExclude {
|
||||||
|
err = f.Add(false, "*")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if *minAge != "" {
|
if *minAge != "" {
|
||||||
duration, err := ParseDuration(*minAge)
|
duration, err := ParseDuration(*minAge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -147,16 +147,15 @@ func TestNewFilterFull(t *testing.T) {
|
|||||||
}
|
}
|
||||||
got := f.DumpFilters()
|
got := f.DumpFilters()
|
||||||
want := `+ (^|/)include1$
|
want := `+ (^|/)include1$
|
||||||
- (^|/)[^/]*$
|
|
||||||
+ (^|/)include2$
|
+ (^|/)include2$
|
||||||
+ (^|/)include3$
|
+ (^|/)include3$
|
||||||
- (^|/)[^/]*$
|
|
||||||
- (^|/)exclude1$
|
- (^|/)exclude1$
|
||||||
- (^|/)exclude2$
|
- (^|/)exclude2$
|
||||||
- (^|/)exclude3$
|
- (^|/)exclude3$
|
||||||
- (^|/)filter1$
|
- (^|/)filter1$
|
||||||
+ (^|/)filter2$
|
+ (^|/)filter2$
|
||||||
- (^|/)filter3$`
|
- (^|/)filter3$
|
||||||
|
- (^|/)[^/]*$`
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("rules want %s got %s", want, got)
|
t.Errorf("rules want %s got %s", want, got)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user