dirs.go 856 B

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