Skip to content

Commit e2ae690

Browse files
committed
pkg/containerfs: remove CleanScopedPath and make it internal
The container package is the only consumer of this function in our code and there's no known external users; https://grep.app/search?q=.CleanScopedPath%28&filter[lang][0]=Go Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 47a959e commit e2ae690

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

container/container.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/docker/docker/layer"
3131
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
3232
"github.com/docker/docker/oci"
33-
"github.com/docker/docker/pkg/containerfs"
3433
"github.com/docker/docker/pkg/idtools"
3534
"github.com/docker/docker/pkg/ioutils"
3635
"github.com/docker/docker/restartmanager"
@@ -345,7 +344,7 @@ func (container *Container) GetResourcePath(path string) (string, error) {
345344
}
346345
// IMPORTANT - These are paths on the OS where the daemon is running, hence
347346
// any filepath operations must be done in an OS-agnostic way.
348-
r, e := symlink.FollowSymlinkInScope(filepath.Join(container.BaseFS, containerfs.CleanScopedPath(path)), container.BaseFS)
347+
r, e := symlink.FollowSymlinkInScope(filepath.Join(container.BaseFS, cleanScopedPath(path)), container.BaseFS)
349348

350349
// Log this here on the daemon side as there's otherwise no indication apart
351350
// from the error being propagated all the way back to the client. This makes
@@ -356,6 +355,18 @@ func (container *Container) GetResourcePath(path string) (string, error) {
356355
return r, e
357356
}
358357

358+
// cleanScopedPath prepares the given path to be combined with a mount path or
359+
// a drive-letter. On Windows, it removes any existing driveletter (e.g. "C:").
360+
// The returned path is always prefixed with a [filepath.Separator].
361+
func cleanScopedPath(path string) string {
362+
if len(path) >= 2 {
363+
if v := filepath.VolumeName(path); len(v) > 0 {
364+
path = path[len(v):]
365+
}
366+
}
367+
return filepath.Join(string(filepath.Separator), path)
368+
}
369+
359370
// GetRootResourcePath evaluates `path` in the scope of the container's root, with proper path
360371
// sanitisation. Symlinks are all scoped to the root of the container, as
361372
// though the container's root was `/`.

pkg/containerfs/containerfs.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)