github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+incompatible/pkg/system/path.go (about)

     1  package system // import "github.com/docker/docker/pkg/system"
     2  
     3  const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
     4  
     5  // DefaultPathEnv is unix style list of directories to search for
     6  // executables. Each directory is separated from the next by a colon
     7  // ':' character .
     8  // For Windows containers, an empty string is returned as the default
     9  // path will be set by the container, and Docker has no context of what the
    10  // default path should be.
    11  func DefaultPathEnv(os string) string {
    12  	if os == "windows" {
    13  		return ""
    14  	}
    15  	return defaultUnixPathEnv
    16  
    17  }
    18  
    19  // PathVerifier defines the subset of a PathDriver that CheckSystemDriveAndRemoveDriveLetter
    20  // actually uses in order to avoid system depending on containerd/continuity.
    21  type PathVerifier interface {
    22  	IsAbs(string) bool
    23  }
    24  
    25  // CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter,
    26  // is the system drive.
    27  // On Linux: this is a no-op.
    28  // On Windows: this does the following>
    29  // CheckSystemDriveAndRemoveDriveLetter verifies and manipulates a Windows path.
    30  // This is used, for example, when validating a user provided path in docker cp.
    31  // If a drive letter is supplied, it must be the system drive. The drive letter
    32  // is always removed. Also, it translates it to OS semantics (IOW / to \). We
    33  // need the path in this syntax so that it can ultimately be concatenated with
    34  // a Windows long-path which doesn't support drive-letters. Examples:
    35  // C:			--> Fail
    36  // C:\			--> \
    37  // a			--> a
    38  // /a			--> \a
    39  // d:\			--> Fail
    40  func CheckSystemDriveAndRemoveDriveLetter(path string, driver PathVerifier) (string, error) {
    41  	return checkSystemDriveAndRemoveDriveLetter(path, driver)
    42  }