Skip to content

Commit e3722b0

Browse files
authored
Swap EvalSymlinks with ResolvePath (#2455)
* Swap `EvalSymlinks` with `ResolvePath` Redo PR 1644, which swapped builtin `"path/filepath".EvalSymlinks` with `"github.com/Microsoft/go-winio/pkg/fs".ResolvePath`, since the later is able to handle deeply nested symlinks and (as of [go1.23](golang.org/doc/go1.23#pathfilepathpkgpathfilepath)), mountpoints. Signed-off-by: Hamza El-Saawy <[email protected]> * PR: update CIM test code Signed-off-by: Hamza El-Saawy <[email protected]> --------- Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent a53730e commit e3722b0

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

internal/layers/lcow.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"strings"
1212

13+
"github.com/Microsoft/go-winio/pkg/fs"
1314
"github.com/containerd/containerd/api/types"
1415
"github.com/pkg/errors"
1516
"github.com/sirupsen/logrus"
@@ -77,7 +78,13 @@ func (lc *lcowLayersCloser) Release(ctx context.Context) (retErr error) {
7778
// Returns the path at which the `rootfs` of the container can be accessed. Also, returns the path inside the
7879
// UVM at which container scratch directory is located. Usually, this path is the path at which the container
7980
// scratch VHD is mounted. However, in case of scratch sharing this is a directory under the UVM scratch.
80-
func MountLCOWLayers(ctx context.Context, containerID string, layers *LCOWLayers, guestRoot string, vm *uvm.UtilityVM) (_, _ string, _ resources.ResourceCloser, err error) {
81+
func MountLCOWLayers(
82+
ctx context.Context,
83+
containerID string,
84+
layers *LCOWLayers,
85+
guestRoot string,
86+
vm *uvm.UtilityVM,
87+
) (_, _ string, _ resources.ResourceCloser, err error) {
8188
if vm == nil {
8289
return "", "", nil, errors.New("MountLCOWLayers cannot be called for process-isolated containers")
8390
}
@@ -114,7 +121,13 @@ func MountLCOWLayers(ctx context.Context, containerID string, layers *LCOWLayers
114121
}
115122

116123
hostPath := layers.ScratchVHDPath
117-
hostPath, err = filepath.EvalSymlinks(hostPath)
124+
// For LCOW, we can reuse another container's scratch space (usually the sandbox container's).
125+
//
126+
// When sharing a scratch space, the `hostPath` will be a symlink to the sandbox.vhdx location to use.
127+
// When not sharing a scratch space, `hostPath` will be the path to the sandbox.vhdx to use.
128+
//
129+
// Evaluate the symlink here (if there is one).
130+
hostPath, err = fs.ResolvePath(hostPath)
118131
if err != nil {
119132
return "", "", nil, fmt.Errorf("failed to eval symlinks on scratch path: %w", err)
120133
}

test/functional/make_uvm_cim_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ import (
1212
"strings"
1313
"testing"
1414

15+
"github.com/Microsoft/go-winio/pkg/fs"
1516
"github.com/Microsoft/go-winio/pkg/guid"
16-
"github.com/Microsoft/hcsshim/pkg/cimfs"
17-
"github.com/Microsoft/hcsshim/pkg/extractuvm"
1817
"github.com/google/go-containerregistry/pkg/crane"
1918
v1 "github.com/google/go-containerregistry/pkg/v1"
19+
20+
"github.com/Microsoft/hcsshim/pkg/cimfs"
21+
"github.com/Microsoft/hcsshim/pkg/extractuvm"
2022
)
2123

2224
func compareFiles(t *testing.T, file1, file2 string) (bool, error) {
2325
t.Helper()
2426

25-
file1, err := filepath.EvalSymlinks(file1)
27+
file1, err := fs.ResolvePath(file1)
2628
if err != nil {
2729
return false, err
2830
}
2931

30-
file2, err = filepath.EvalSymlinks(file2)
32+
file2, err = fs.ResolvePath(file2)
3133
if err != nil {
3234
return false, err
3335
}

0 commit comments

Comments
 (0)