2015-04-27 14:53:12 +00:00
|
|
|
// +build linux
|
|
|
|
|
2013-11-07 12:33:31 +00:00
|
|
|
package aufs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Return all the directories
|
|
|
|
func loadIds(root string) ([]string, error) {
|
|
|
|
dirs, err := ioutil.ReadDir(root)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
out := []string{}
|
|
|
|
for _, d := range dirs {
|
|
|
|
if !d.IsDir() {
|
|
|
|
out = append(out, d.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the layers file for the current id and return all the
|
|
|
|
// layers represented by new lines in the file
|
|
|
|
//
|
|
|
|
// If there are no lines in the file then the id has no parent
|
|
|
|
// and an empty slice is returned.
|
|
|
|
func getParentIds(root, id string) ([]string, error) {
|
|
|
|
f, err := os.Open(path.Join(root, "layers", id))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
out := []string{}
|
|
|
|
s := bufio.NewScanner(f)
|
|
|
|
|
|
|
|
for s.Scan() {
|
2013-11-08 19:10:33 +00:00
|
|
|
if t := s.Text(); t != "" {
|
|
|
|
out = append(out, s.Text())
|
2013-11-07 12:33:31 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-08 19:10:33 +00:00
|
|
|
return out, s.Err()
|
2013-11-07 12:33:31 +00:00
|
|
|
}
|