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