MCPcopy
hub / github.com/kubesphere/kubekey / copyRelativeDir

Method copyRelativeDir

pkg/modules/copy/copy.go:258–291  ·  view source on GitHub ↗

copyRelativeDir copies all files from a relative directory (in the project) to the remote host.

(ctx context.Context, pj project.Project, relPath string, conn connector.Connector)

Source from the content-addressed store, hash-verified

256
257// copyRelativeDir copies all files from a relative directory (in the project) to the remote host.
258func (ca copyArgs) copyRelativeDir(ctx context.Context, pj project.Project, relPath string, conn connector.Connector) (resRrr error) {
259 defer func() {
260 resRrr = ca.ensureDestDirMode(ctx, conn)
261 }()
262 return pj.WalkDir(relPath, func(path string, d fs.DirEntry, err error) error {
263 if err != nil {
264 return err
265 }
266 // Only copy files, skip directories
267 if d.IsDir() {
268 return nil
269 }
270
271 info, err := d.Info()
272 if err != nil {
273 return errors.Wrap(err, "failed to get file info")
274 }
275
276 mode := info.Mode()
277
278 data, err := pj.ReadFile(path)
279 if err != nil {
280 return errors.Wrap(err, "failed to read file")
281 }
282
283 rel, err := pj.Rel(relPath, path)
284 if err != nil {
285 return errors.Wrap(err, "failed to get relative file path")
286 }
287 dest := filepath.Join(ca.dest, rel)
288
289 return connector.PutData(ctx, data, dest, mode, conn)
290 })
291}
292
293// ensureDestDirMode if mode args exists, ensure dest dir mode after all files copied
294func (ca copyArgs) ensureDestDirMode(ctx context.Context, conn connector.Connector) error {

Callers 1

handleRelativePathMethod · 0.95

Calls 6

ensureDestDirModeMethod · 0.95
PutDataFunction · 0.92
WalkDirMethod · 0.65
ReadFileMethod · 0.65
RelMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected