{"record":{"id":"0b0035e3114a5187","repo":"GoogleContainerTools/skaffold","slug":"copying-files-w-0b0035","errorCode":null,"errorMessage":"copying files: %w","messagePattern":"copying files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sync/sync.go","lineNumber":311,"sourceCode":"\thooksRunner := hooks.NewSyncRunner(s.kubectl, item.Artifact.ImageName, item.Image, *s.namespaces, s.formatter, item.Artifact.Sync.LifecycleHooks, opts)\n\tif err := hooksRunner.RunPreHooks(ctx, out); err != nil {\n\t\treturn fmt.Errorf(\"pre-sync hooks failed for artifact %q: %w\", item.Artifact.ImageName, err)\n\t}\n\tif err := s.sync(ctx, item); err != nil {\n\t\treturn err\n\t}\n\tif err := hooksRunner.RunPostHooks(ctx, out); err != nil {\n\t\treturn fmt.Errorf(\"post-sync hooks failed for artifact %q: %w\", item.Artifact.ImageName, err)\n\t}\n\treturn nil\n}\n\nfunc (s *PodSyncer) sync(ctx context.Context, item *Item) error {\n\tif len(item.Copy) > 0 {\n\t\tlog.Entry(ctx).Info(\"Copying files:\", item.Copy, \"to\", item.Image)\n\n\t\tif err := Perform(ctx, item.Image, item.Copy, s.copyFileFn, *s.namespaces, s.kubectl.KubeContext); err != nil {\n\t\t\treturn fmt.Errorf(\"copying files: %w\", err)\n\t\t}\n\t}\n\n\tif len(item.Delete) > 0 {\n\t\tlog.Entry(ctx).Info(\"Deleting files:\", item.Delete, \"from\", item.Image)\n\n\t\tif err := Perform(ctx, item.Image, item.Delete, s.deleteFileFn, *s.namespaces, s.kubectl.KubeContext); err != nil {\n\t\t\treturn fmt.Errorf(\"deleting files: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc Perform(ctx context.Context, image string, files syncMap, cmdFn func(context.Context, v1.Pod, v1.Container, syncMap) *exec.Cmd, namespaces []string, kubeContext string) error {\n\tif len(files) == 0 {\n\t\treturn nil\n\t}","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sync/sync.go#L293-L329","documentation":"PodSyncer.sync performs the actual copy of changed files into the running pod container(s) via Perform with the copyFileFn. When that kubectl-based copy fails, Skaffold wraps the error as 'copying files'. The syncMap (container path -> local paths) comes from the item being synced.","triggerScenarios":"Perform fails while kubectl-cp-ing files into the pod: pod restarting/evicted, container not running, kubectl exec/put network failure, or destination path not writable in the container.","commonSituations":"Pod in CrashLoopBackOff so cp target is gone; RBAC lacking exec/patch permissions on pods; destination directory read-only in the image; intermittent cluster connectivity during heavy file-change bursts.","solutions":["Run `kubectl get pods` to confirm the target pod is Running and not crash-looping, then retry the sync","Test the copy manually (kubectl cp local.txt pod:/dest/) to expose RBAC or path-permission errors","Check destination path writability in the image and correct the `dest:` in sync rules; verify kube context connectivity"],"exampleFix":"// before\nsync:\n  manual:\n    - src: '**/*.go'\n      dest: /go/src/   # read-only layer path in image\n// after\nsync:\n  manual:\n    - src: '**/*.go'\n      dest: /app/src/","handlingStrategy":"retry","validationCode":"// confirm pod is ready before syncing\nout, err := exec.Command(\"kubectl\", \"get\", \"pod\", pod, \"-o\", \"jsonpath={.status.phase}\").Output()\nif err != nil || string(out) != \"Running\" { return errors.New(\"pod not ready for sync\") }","typeGuard":null,"tryCatchPattern":"err := s.Sync(ctx, out, names, item)\nif err != nil {\n    if strings.Contains(err.Error(), \"copying files\") {\n        select {\n        case <-time.After(2 * time.Second):\n            return s.Sync(ctx, out, names, item) // pod may have restarted; retry once\n        default:\n        }\n    }\n    return err\n}","preventionTips":["Check pod health (kubectl get pods) before relying on file sync","Ensure RBAC allows pods/exec and pods/patch in target namespaces","Keep sync destination paths writable in the image; avoid syncing while a container restart is in progress"],"tags":["skaffold","sync","kubectl","pod","file-copy"],"backgroundTag":"kubectl-copy-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}