Skip to content

Commit e30a362

Browse files
committed
Rewrite cp
Signed-off-by: apostasie <[email protected]>
1 parent 444c172 commit e30a362

File tree

4 files changed

+658
-192
lines changed

4 files changed

+658
-192
lines changed

cmd/nerdctl/container/container_cp_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ func processCpOptions(cmd *cobra.Command, args []string) (types.ContainerCpOptio
115115
}
116116

117117
container2host := srcSpec.Container != nil
118-
var container string
118+
var containerReq string
119119
if container2host {
120-
container = *srcSpec.Container
120+
containerReq = *srcSpec.Container
121121
} else {
122-
container = *destSpec.Container
122+
containerReq = *destSpec.Container
123123
}
124124
return types.ContainerCpOptions{
125125
GOptions: globalOptions,
126126
Container2Host: container2host,
127-
ContainerReq: container,
127+
ContainerReq: containerReq,
128128
DestPath: destSpec.Path,
129129
SrcPath: srcSpec.Path,
130130
FollowSymLink: flagL,

pkg/cmd/container/cp_linux.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,22 @@ func Cp(ctx context.Context, client *containerd.Client, options types.ContainerC
3939
ctx,
4040
client,
4141
found.Container,
42-
options.Container2Host,
43-
options.DestPath,
44-
options.SrcPath,
45-
options.GOptions.Snapshotter,
46-
options.FollowSymLink)
42+
options)
4743
},
4844
}
4945
count, err := walker.Walk(ctx, options.ContainerReq)
5046

51-
if count < 1 {
52-
err = fmt.Errorf("could not find container: %s, with error: %w", options.ContainerReq, err)
47+
if count == -1 {
48+
if err == nil {
49+
panic("nil error and count == -1 from ContainerWalker.Walk should never happen")
50+
}
51+
err = fmt.Errorf("unable to copy: %w", err)
52+
} else if count == 0 {
53+
if err != nil {
54+
err = fmt.Errorf("unable to retrieve containers with error: %w", err)
55+
} else {
56+
err = fmt.Errorf("no container found for: %s", options.ContainerReq)
57+
}
5358
}
5459

5560
return err

0 commit comments

Comments
 (0)