Skip to content

Commit f25863b

Browse files
Merge branch 'main' into test-branch
2 parents 19c4302 + 85960e5 commit f25863b

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

cmd/nerdctl/container/container_export.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package container
33
import (
44
"fmt"
55
"os"
6+
7+
"github.com/mattn/go-isatty"
8+
"github.com/spf13/cobra"
9+
610
"github.com/containerd/nerdctl/v2/cmd/nerdctl/completion"
711
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
812
"github.com/containerd/nerdctl/v2/pkg/api/types"
913
"github.com/containerd/nerdctl/v2/pkg/clientutil"
1014
"github.com/containerd/nerdctl/v2/pkg/cmd/container"
11-
"github.com/mattn/go-isatty"
12-
"github.com/spf13/cobra"
1315
)
1416

1517
func ExportCommand() *cobra.Command {

pkg/cmd/container/export.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424

2525
containerd "github.com/containerd/containerd/v2/client"
2626
"github.com/containerd/containerd/v2/core/containers"
27+
"github.com/containerd/containerd/v2/core/mount"
2728
"github.com/containerd/containerd/v2/pkg/archive"
2829
"github.com/containerd/log"
2930

3031
"github.com/containerd/nerdctl/v2/pkg/api/types"
31-
"github.com/containerd/nerdctl/v2/pkg/containerutil"
3232
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
3333
)
3434

@@ -66,7 +66,7 @@ func exportContainer(ctx context.Context, client *containerd.Client, container c
6666
return fmt.Errorf("failed to get container info: %w", err)
6767
}
6868

69-
root, cleanup, err = containerutil.MountSnapshotForContainer(ctx, client, conInfo, options.GOptions.Snapshotter)
69+
root, cleanup, err = MountSnapshotForContainer(ctx, client, conInfo, options.GOptions.Snapshotter)
7070
if cleanup != nil {
7171
defer func() {
7272
if cleanupErr := cleanup(); cleanupErr != nil {
@@ -162,3 +162,31 @@ func (cw *countingWriter) Write(p []byte) (n int, err error) {
162162
cw.count += int64(n)
163163
return n, err
164164
}
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

Comments
 (0)