Skip to content

Commit 6dae7f9

Browse files
TBBlegabriel-samfira
authored andcommitted
Work around filepath.Walk failing to follow junction points
In Windows, a mounted scratch layer is a junction point. However, Go sees this as a symlink to itself, and hence does not walk through it. This causes testutil.DumpDir and fstest.CheckDirectoryEqualWithApplier to see an empty directory if given the mount-point as the root path. So instead, all the test work is done in a sub-directory of the snapshot. It's possible that this could be fixed in containerd/continuity for fstest.CheckDirectoryEqualWithApplier, but I have not looked into that. Signed-off-by: Paul "TBBle" Hampson <[email protected]>
1 parent 223aa03 commit 6dae7f9

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

snapshots/testsuite/helpers.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"math/rand"
2323
"os"
24+
"path/filepath"
2425

2526
"github.com/containerd/containerd/mount"
2627
"github.com/containerd/containerd/snapshots"
@@ -43,7 +44,13 @@ func applyToMounts(m []mount.Mount, work string, a fstest.Applier) (err error) {
4344
}
4445
}()
4546

46-
return a.Apply(td)
47+
tdWorkDir := filepath.Join(td, "wcow_workaround")
48+
49+
if err := os.MkdirAll(tdWorkDir, 0777); err != nil {
50+
return fmt.Errorf("failed to prepare in-image workdir: %w", err)
51+
}
52+
53+
return a.Apply(tdWorkDir)
4754
}
4855

4956
// createSnapshot creates a new snapshot in the snapshotter
@@ -99,7 +106,7 @@ func checkSnapshot(ctx context.Context, sn snapshots.Snapshotter, work, name, ch
99106
}
100107
}()
101108

102-
if err := fstest.CheckDirectoryEqual(check, td); err != nil {
109+
if err := fstest.CheckDirectoryEqual(check, filepath.Join(td, "wcow_workaround")); err != nil {
103110
return fmt.Errorf("check directory failed: %w", err)
104111
}
105112

snapshots/testsuite/testsuite.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,15 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
161161
t.Fatalf("failure reason: %+v", err)
162162
}
163163

164-
if err := initialApplier.Apply(preparing); err != nil {
164+
// Work around failure of fstest.CheckDirectoryEqualWithApplier when
165+
// pointed at a junction point on Windows, i.e. a mounted layer.
166+
preparingWorkDir := filepath.Join(preparing, "wcow_workaround")
167+
if err := os.MkdirAll(preparingWorkDir, 0777); err != nil {
168+
testutil.Unmount(t, preparing)
169+
t.Fatalf("failure reason: %+v", err)
170+
}
171+
172+
if err := initialApplier.Apply(preparingWorkDir); err != nil {
165173
testutil.Unmount(t, preparing)
166174
t.Fatalf("failure reason: %+v", err)
167175
}
@@ -199,12 +207,14 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
199207
t.Fatalf("failure reason: %+v", err)
200208
}
201209

202-
if err := fstest.CheckDirectoryEqualWithApplier(next, initialApplier); err != nil {
210+
nextWorkDir := filepath.Join(next, "wcow_workaround")
211+
212+
if err := fstest.CheckDirectoryEqualWithApplier(nextWorkDir, initialApplier); err != nil {
203213
testutil.Unmount(t, next)
204214
t.Fatalf("failure reason: %+v", err)
205215
}
206216

207-
if err := diffApplier.Apply(next); err != nil {
217+
if err := diffApplier.Apply(nextWorkDir); err != nil {
208218
testutil.Unmount(t, next)
209219
t.Fatalf("failure reason: %+v", err)
210220
}
@@ -269,7 +279,9 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
269279
t.Fatalf("failure reason: %+v", err)
270280
}
271281

272-
if err := fstest.CheckDirectoryEqualWithApplier(nextnext,
282+
nextnextWorkDir := filepath.Join(nextnext, "wcow_workaround")
283+
284+
if err := fstest.CheckDirectoryEqualWithApplier(nextnextWorkDir,
273285
fstest.Apply(initialApplier, diffApplier)); err != nil {
274286
testutil.Unmount(t, nextnext)
275287
t.Fatalf("failure reason: %+v", err)
@@ -935,7 +947,13 @@ func check128LayersMount(name string) func(ctx context.Context, t *testing.T, sn
935947
t.Fatalf("[layer %d] failed to mount on the target(%s): %+v", i, preparing, err)
936948
}
937949

938-
if err := fstest.CheckDirectoryEqual(preparing, flat); err != nil {
950+
preparingWorkDir := filepath.Join(preparing, "wcow_workaround")
951+
if err := os.MkdirAll(preparingWorkDir, 0777); err != nil {
952+
testutil.Unmount(t, preparing)
953+
t.Fatalf("[layer %d] failed to create workdir: %+v", i, err)
954+
}
955+
956+
if err := fstest.CheckDirectoryEqual(preparingWorkDir, flat); err != nil {
939957
testutil.Unmount(t, preparing)
940958
t.Fatalf("[layer %d] preparing doesn't equal to flat before apply: %+v", i, err)
941959
}
@@ -945,12 +963,12 @@ func check128LayersMount(name string) func(ctx context.Context, t *testing.T, sn
945963
t.Fatalf("[layer %d] failed to apply on flat dir: %+v", i, err)
946964
}
947965

948-
if err = applier.Apply(preparing); err != nil {
966+
if err = applier.Apply(preparingWorkDir); err != nil {
949967
testutil.Unmount(t, preparing)
950968
t.Fatalf("[layer %d] failed to apply on preparing dir: %+v", i, err)
951969
}
952970

953-
if err := fstest.CheckDirectoryEqual(preparing, flat); err != nil {
971+
if err := fstest.CheckDirectoryEqual(preparingWorkDir, flat); err != nil {
954972
testutil.Unmount(t, preparing)
955973
t.Fatalf("[layer %d] preparing doesn't equal to flat after apply: %+v", i, err)
956974
}
@@ -979,7 +997,9 @@ func check128LayersMount(name string) func(ctx context.Context, t *testing.T, sn
979997
}
980998
defer testutil.Unmount(t, view)
981999

982-
if err := fstest.CheckDirectoryEqual(view, flat); err != nil {
1000+
viewWorkDir := filepath.Join(view, "wcow_workaround")
1001+
1002+
if err := fstest.CheckDirectoryEqual(viewWorkDir, flat); err != nil {
9831003
t.Fatalf("fullview should equal to flat: %+v", err)
9841004
}
9851005
}

0 commit comments

Comments
 (0)