github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/daemon/graphdriver/aufs/dirs.go (about)

     1  package aufs
     2  
     3  import (
     4  	"bufio"
     5  	"io/ioutil"
     6  	"os"
     7  	"path"
     8  )
     9  
    10  // Return all the directories
    11  func loadIds(root string) ([]string, error) {
    12  	dirs, err := ioutil.ReadDir(root)
    13  	if err != nil {
    14  		return nil, err
    15  	}
    16  	out := []string{}
    17  	for _, d := range dirs {
    18  		if !d.IsDir() {
    19  			out = append(out, d.Name())
    20  		}
    21  	}
    22  	return out, nil
    23  }
    24  
    25  // Read the layers file for the current id and return all the
    26  // layers represented by new lines in the file
    27  //
    28  // If there are no lines in the file then the id has no parent
    29  // and an empty slice is returned.
    30  func getParentIds(root, id string) ([]string, error) {
    31  	f, err := os.Open(path.Join(root, "layers", id))
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  	defer f.Close()
    36  
    37  	out := []string{}
    38  	s := bufio.NewScanner(f)
    39  
    40  	for s.Scan() {
    41  		if t := s.Text(); t != "" {
    42  			out = append(out, s.Text())
    43  		}
    44  	}
    45  	return out, s.Err()
    46  }