in command-runner/internal/containers/finch/finch_run.go [293:323]
func (cr *finchContainer) copyIn(containerPath string, hostPath string, useGitIgnore bool) common.Executor {
return func(ctx context.Context) error {
log.Ctx(ctx).Debug().Msgf("Writing %s from %s", containerPath, hostPath)
if f, err := os.Stat(hostPath); err != nil {
return fmt.Errorf("unable to copyIn from hostPath=%s: %w", hostPath, err)
} else if filepath.Ext(hostPath) == ".tar" {
// TODO: implement
return fmt.Errorf("copyIn for tar file is not implemented")
} else if f.IsDir() {
if useGitIgnore {
tempDir, err := os.MkdirTemp(fs.TmpDir(), "finch-copyin")
if err != nil {
return fmt.Errorf("failed to create temp dir: %w", err)
}
defer os.RemoveAll(tempDir)
err = copyDir(ctx, tempDir, hostPath, useGitIgnore)
if err != nil {
return fmt.Errorf("failed to copyDir: %w", err)
}
hostPath = fmt.Sprintf("%s/.", tempDir)
}
if _, rerr, err := cr.f.RunWithoutStdio(ctx, "cp", hostPath, fmt.Sprintf("%s:%s", cr.id, containerPath)); err != nil {
return fmt.Errorf("failed to copy content to container: %w\n%s", err, rerr)
}
return nil
} else {
return fmt.Errorf("unsupported srcPath=%s", hostPath)
}
}
}