Skip to content

Commit

Permalink
pkg/containerfs: unify CleanScopedPath implementation
Browse files Browse the repository at this point in the history
Use stdlib's filepath.VolumeName to get the volume-name (if present) instead
of a self-crafted implementation, and unify the implementations for Windows
and Unix.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jan 2, 2024
1 parent a5b4670 commit 90f37f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
12 changes: 12 additions & 0 deletions pkg/containerfs/containerfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import (
"github.com/moby/sys/symlink"
)

// CleanScopedPath prepares the given path to be combined with a mount path or
// a drive-letter. On Windows, it removes any existing driveletter (e.g. "C:").
// The returned path is always prefixed with a [filepath.Separator].
func CleanScopedPath(path string) string {
if len(path) >= 2 {
if v := filepath.VolumeName(path); len(v) > 0 {
path = path[len(v):]
}
}
return filepath.Join(string(filepath.Separator), path)
}

// ResolveScopedPath evaluates the given path scoped to the root.
// For example, if root=/a, and path=/b/c, then this function would return /a/b/c.
func ResolveScopedPath(root, path string) (string, error) {
Expand Down
10 changes: 0 additions & 10 deletions pkg/containerfs/containerfs_unix.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/containerfs/containerfs_windows.go

This file was deleted.

0 comments on commit 90f37f4

Please sign in to comment.