@@ -24,11 +24,11 @@ import (
24
24
25
25
containerd "github.com/containerd/containerd/v2/client"
26
26
"github.com/containerd/containerd/v2/core/containers"
27
+ "github.com/containerd/containerd/v2/core/mount"
27
28
"github.com/containerd/containerd/v2/pkg/archive"
28
29
"github.com/containerd/log"
29
30
30
31
"github.com/containerd/nerdctl/v2/pkg/api/types"
31
- "github.com/containerd/nerdctl/v2/pkg/containerutil"
32
32
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
33
33
)
34
34
@@ -66,7 +66,7 @@ func exportContainer(ctx context.Context, client *containerd.Client, container c
66
66
return fmt .Errorf ("failed to get container info: %w" , err )
67
67
}
68
68
69
- root , cleanup , err = containerutil . MountSnapshotForContainer (ctx , client , conInfo , options .GOptions .Snapshotter )
69
+ root , cleanup , err = MountSnapshotForContainer (ctx , client , conInfo , options .GOptions .Snapshotter )
70
70
if cleanup != nil {
71
71
defer func () {
72
72
if cleanupErr := cleanup (); cleanupErr != nil {
@@ -162,3 +162,31 @@ func (cw *countingWriter) Write(p []byte) (n int, err error) {
162
162
cw .count += int64 (n )
163
163
return n , err
164
164
}
165
+
166
+ func MountSnapshotForContainer (ctx context.Context , client * containerd.Client , conInfo containers.Container , snapshotter string ) (string , func () error , error ) {
167
+ snapKey := conInfo .SnapshotKey
168
+ resp , err := client .SnapshotService (snapshotter ).Mounts (ctx , snapKey )
169
+ if err != nil {
170
+ return "" , nil , err
171
+ }
172
+
173
+ tempDir , err := os .MkdirTemp ("" , "nerdctl-cp-" )
174
+ if err != nil {
175
+ return "" , nil , err
176
+ }
177
+
178
+ err = mount .All (resp , tempDir )
179
+ if err != nil {
180
+ return "" , nil , err
181
+ }
182
+
183
+ cleanup := func () error {
184
+ err = mount .Unmount (tempDir , 0 )
185
+ if err != nil {
186
+ return err
187
+ }
188
+ return os .RemoveAll (tempDir )
189
+ }
190
+
191
+ return tempDir , cleanup , nil
192
+ }
0 commit comments