github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/graphdriver/aufs/dirs.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  package aufs // import "github.com/docker/docker/daemon/graphdriver/aufs"
     5  
     6  import (
     7  	"bufio"
     8  	"os"
     9  	"path"
    10  )
    11  
    12  // Return all the directories
    13  func loadIds(root string) ([]string, error) {
    14  	dirs, err := os.ReadDir(root)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  	var 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  	var 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  }
    49  
    50  func (a *Driver) getMountpoint(id string) string {
    51  	return path.Join(a.mntPath(), id)
    52  }
    53  
    54  func (a *Driver) mntPath() string {
    55  	return path.Join(a.rootPath(), "mnt")
    56  }
    57  
    58  func (a *Driver) getDiffPath(id string) string {
    59  	return path.Join(a.diffPath(), id)
    60  }
    61  
    62  func (a *Driver) diffPath() string {
    63  	return path.Join(a.rootPath(), "diff")
    64  }