Repository: rclone/rclone
File: fs/filter/filter.go (Go)

Code before:
// DirContainsExcludeFile checks if exclude file is present in a
// directory. If fs is nil, it works properly if ExcludeFile is an
// empty string (for testing).
func (f *Filter) DirContainsExcludeFile(ctx context.Context, fremote fs.Fs, remote string) (bool, error) {
	if len(f.Opt.ExcludeFile) > 0 {
		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
}

// Include returns whether this object should be included into the
// sync or not and logs the reason for exclusion if not included
func (f *Filter) Include(remote string, size int64, modTime time.Time, metadata fs.Metadata) bool {
	// filesFrom takes precedence
	if f.files != nil {
		_, include := f.files[remote]
		if !include {
			fs.Debugf(nil, "Excluded (FilesFrom Filter): %s", remote)
		}
		return include
	}
	if !f.ModTimeFrom.IsZero() && modTime.Before(f.ModTimeFrom) {
		fs.Debugf(nil, "Excluded (ModTime Filter): %s", remote)
		return false
	}
	if !f.ModTimeTo.IsZero() && modTime.After(f.ModTimeTo) {
		fs.Debugf(nil, "Excluded (ModTime Filter): %s", remote)
		return false
	}
	if f.Opt.MinSize >= 0 && size < int64(f.Opt.MinSize) {
		fs.Debugf(nil, "Excluded (Size Filter): %s", remote)
		return false
	}
	if f.Opt.MaxSize >= 0 && size > int64(f.Opt.MaxSize) {
		fs.Debugf(nil, "Excluded (Size Filter): %s", remote)
		return false
	}
	if f.metaRules.len() > 0 {
		metadatas := make([]string, 0, len(metadata)+1)
		for key, value := range metadata {
			metadatas = append(metadatas, fmt.Sprintf("%s=%s", key, value))
		}
		if len(metadata) == 0 {

Review comment (bug):
These debugs should be

    fs.Debugf(remote, "Excluded (FilesFrom Filter)", remote)

Then they will appear correct in the logs.

Code after:
// DirContainsExcludeFile checks if exclude file is present in a
// directory. If fs is nil, it works properly if ExcludeFile is an
// empty string (for testing).
func (f *Filter) DirContainsExcludeFile(ctx context.Context, fremote fs.Fs, remote string) (bool, error) {
	if len(f.Opt.ExcludeFile) > 0 {
		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
}

// Include returns whether this object should be included into the
// sync or not and logs the reason for exclusion if not included
func (f *Filter) Include(remote string, size int64, modTime time.Time, metadata fs.Metadata) bool {
	// filesFrom takes precedence
	if f.files != nil {
		_, include := f.files[remote]
		if !include {
			fs.Debugf(remote, "Excluded (FilesFrom Filter)")
		}
		return include
	}
	if !f.ModTimeFrom.IsZero() && modTime.Before(f.ModTimeFrom) {
		fs.Debugf(remote, "Excluded (ModTime Filter)")
		return false
	}
	if !f.ModTimeTo.IsZero() && modTime.After(f.ModTimeTo) {
		fs.Debugf(remote, "Excluded (ModTime Filter)")
		return false
	}
	if f.Opt.MinSize >= 0 && size < int64(f.Opt.MinSize) {
		fs.Debugf(remote, "Excluded (Size Filter)")
		return false
	}
	if f.Opt.MaxSize >= 0 && size > int64(f.Opt.MaxSize) {
		fs.Debugf(remote, "Excluded (Size Filter)")
		return false
	}
	if f.metaRules.len() > 0 {
		metadatas := make([]string, 0, len(metadata)+1)
		for key, value := range metadata {
			metadatas = append(metadatas, fmt.Sprintf("%s=%s", key, value))
		}
		if len(metadata) == 0 {