github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/helper/mount/mount_linux.go (about)

     1  //go:build linux
     2  // +build linux
     3  
     4  package mount
     5  
     6  import (
     7  	"github.com/moby/sys/mount"
     8  	"github.com/moby/sys/mountinfo"
     9  )
    10  
    11  // mounter provides the default implementation of mount.Mounter
    12  // for the linux platform.
    13  // Currently it delegates to the docker `mount` package.
    14  type mounter struct {
    15  }
    16  
    17  // New returns a Mounter for the current system.
    18  func New() Mounter {
    19  	return &mounter{}
    20  }
    21  
    22  // IsNotAMountPoint determines if a directory is not a mountpoint.
    23  // It does this by checking the path against the contents of /proc/self/mountinfo
    24  func (m *mounter) IsNotAMountPoint(path string) (bool, error) {
    25  	isMount, err := mountinfo.Mounted(path)
    26  	return !isMount, err
    27  }
    28  
    29  func (m *mounter) Mount(device, target, mountType, options string) error {
    30  	// Defer to the docker implementation of `Mount`, it's correct enough for our
    31  	// usecase and avoids us needing to shell out to the `mount` utility.
    32  	return mount.Mount(device, target, mountType, options)
    33  }