github.com/reds/docker@v1.11.2-rc1/builder/dockerignore/dockerignore.go (about)

     1  package dockerignore
     2  
     3  import (
     4  	"bufio"
     5  	"fmt"
     6  	"io"
     7  	"path/filepath"
     8  	"strings"
     9  )
    10  
    11  // ReadAll reads a .dockerignore file and returns the list of file patterns
    12  // to ignore. Note this will trim whitespace from each line as well
    13  // as use GO's "clean" func to get the shortest/cleanest path for each.
    14  func ReadAll(reader io.ReadCloser) ([]string, error) {
    15  	if reader == nil {
    16  		return nil, nil
    17  	}
    18  	defer reader.Close()
    19  	scanner := bufio.NewScanner(reader)
    20  	var excludes []string
    21  
    22  	for scanner.Scan() {
    23  		pattern := strings.TrimSpace(scanner.Text())
    24  		if pattern == "" {
    25  			continue
    26  		}
    27  		pattern = filepath.Clean(pattern)
    28  		pattern = filepath.ToSlash(pattern)
    29  		excludes = append(excludes, pattern)
    30  	}
    31  	if err := scanner.Err(); err != nil {
    32  		return nil, fmt.Errorf("Error reading .dockerignore: %v", err)
    33  	}
    34  	return excludes, nil
    35  }