containerfs.go 848 B

12345678910111213141516171819202122232425
  1. package containerfs // import "github.com/docker/docker/pkg/containerfs"
  2. import (
  3. "path/filepath"
  4. "github.com/moby/sys/symlink"
  5. )
  6. // CleanScopedPath prepares the given path to be combined with a mount path or
  7. // a drive-letter. On Windows, it removes any existing driveletter (e.g. "C:").
  8. // The returned path is always prefixed with a [filepath.Separator].
  9. func CleanScopedPath(path string) string {
  10. if len(path) >= 2 {
  11. if v := filepath.VolumeName(path); len(v) > 0 {
  12. path = path[len(v):]
  13. }
  14. }
  15. return filepath.Join(string(filepath.Separator), path)
  16. }
  17. // ResolveScopedPath evaluates the given path scoped to the root.
  18. // For example, if root=/a, and path=/b/c, then this function would return /a/b/c.
  19. func ResolveScopedPath(root, path string) (string, error) {
  20. return symlink.FollowSymlinkInScope(filepath.Join(root, path), root)
  21. }