dirs.go 1.2 KB

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