MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / Copy

Method Copy

cli/pkg/common/docker.go:96–150  ·  view source on GitHub ↗
(ctx context.Context, file string, dest string, container string)

Source from the content-addressed store, hash-verified

94}
95
96func (d Docker) Copy(ctx context.Context, file string, dest string, container string) error {
97 srcPath := file
98 dstPath := dest
99 // Prepare destination copy info by stat-ing the container path.
100 dstInfo := archive.CopyInfo{Path: dstPath}
101 dstStat, err := d.client.ContainerStatPath(ctx, container, dstPath)
102
103 // If the destination is a symbolic link, we should evaluate it.
104 if err == nil && dstStat.Mode&os.ModeSymlink != 0 {
105 linkTarget := dstStat.LinkTarget
106 if !system.IsAbs(linkTarget) {
107 // Join with the parent directory.
108 dstParent, _ := archive.SplitPathDirEntry(dstPath)
109 linkTarget = filepath.Join(dstParent, linkTarget)
110 }
111
112 dstInfo.Path = linkTarget
113 dstStat, err = d.client.ContainerStatPath(ctx, container, linkTarget)
114 }
115
116 if err == nil {
117 dstInfo.Exists, dstInfo.IsDir = true, dstStat.Mode.IsDir()
118 }
119
120 var (
121 content io.Reader
122 resolvedDstPath string
123 )
124
125 // Prepare source copy info.
126 srcInfo, err := archive.CopyInfoSourcePath(srcPath, true)
127 if err != nil {
128 return err
129 }
130
131 srcArchive, err := archive.TarResource(srcInfo)
132 if err != nil {
133 return err
134 }
135 defer srcArchive.Close()
136
137 dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, dstInfo)
138 if err != nil {
139 return err
140 }
141 defer preparedArchive.Close()
142
143 resolvedDstPath = dstDir
144 content = preparedArchive
145
146 options := types.CopyToContainerOptions{
147 AllowOverwriteDirWithFile: true,
148 }
149 return d.client.CopyToContainer(ctx, container, resolvedDstPath, content, options)
150}
151
152func (d Docker) Start(ctx context.Context, container string) error {
153 err := d.client.ContainerStart(ctx, container, types.ContainerStartOptions{})

Callers 7

AddLabelsFunction · 0.80
getReaderFunction · 0.80
CopyFileMethod · 0.80
dockerCreateAndRunFunction · 0.80
TunnelMultipleFunction · 0.80
copyFileFunction · 0.80
copyFileFunction · 0.80

Calls 1

JoinMethod · 0.45

Tested by

no test coverage detected