github.com/containerd/nerdctl@v1.7.7/pkg/mountutil/mountutil_other.go (about) 1 //go:build !windows 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package mountutil 20 21 import ( 22 "fmt" 23 "path/filepath" 24 "strings" 25 26 "github.com/containerd/nerdctl/pkg/mountutil/volumestore" 27 ) 28 29 func splitVolumeSpec(s string) ([]string, error) { 30 s = strings.TrimLeft(s, ":") 31 split := strings.Split(s, ":") 32 return split, nil 33 } 34 35 func handleVolumeToMount(source string, dst string, volStore volumestore.VolumeStore, createDir bool) (volumeSpec, error) { 36 switch { 37 // Handle named volumes 38 case isNamedVolume(source): 39 return handleNamedVolumes(source, volStore) 40 41 // Handle bind volumes (file paths) 42 default: 43 return handleBindMounts(source, createDir) 44 } 45 } 46 47 func cleanMount(p string) string { 48 return filepath.Clean(p) 49 } 50 51 func isValidPath(s string) (bool, error) { 52 if filepath.IsAbs(s) { 53 return true, nil 54 } 55 56 return false, fmt.Errorf("expected an absolute path, got %q", s) 57 } 58 59 /* 60 For docker compatibility on non-Windows platforms: 61 Docker allows anonymous named volumes, relative paths, and absolute paths 62 to be mounted into a container. 63 */ 64 func validateAnonymousVolumeDestination(s string) (bool, error) { 65 return true, nil 66 }