github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/sidecar/paths.go (about)

     1  package sidecar
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  )
     7  
     8  // VolumeMountPointForPath returns the mount point for the volume on which path
     9  // resides. If the path does not reside at or beneath a volume mount point, then
    10  // an empty string is returned. The provided path must be absolute, cleaned, and
    11  // fully resolved of symbolic links. This function is only valid in the context
    12  // of a Mutagen sidecar container.
    13  func VolumeMountPointForPath(path string) string {
    14  	// Verify that the path exists at or beneath a volume mount point.
    15  	if !strings.HasPrefix(path, volumeMountParent) || path == volumeMountParent {
    16  		return ""
    17  	}
    18  
    19  	// Extract the volume name.
    20  	volume := path[len(volumeMountParent):]
    21  	if index := strings.IndexByte(volume, filepath.Separator); index >= 0 {
    22  		volume = volume[:index]
    23  	}
    24  
    25  	// Validate the volume name.
    26  	if volume == "" {
    27  		return ""
    28  	}
    29  
    30  	// Compute the volume mount point.
    31  	return volumeMountParent + volume
    32  }