{"record":{"id":"a065d521281f3209","repo":"kubernetes/kops","slug":"error-renaming-temp-file-q-q-w","errorCode":null,"errorMessage":"error renaming temp file %q -> %q: %w","messagePattern":"error renaming temp file %q -> %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/files.go","lineNumber":101,"sourceCode":"\t\t\t}\n\t\t}\n\t}()\n\n\tif _, err := io.Copy(tempFile, in); err != nil {\n\t\treturn fmt.Errorf(\"error writing file %q: %v\", tempFile.Name(), err)\n\t}\n\n\tif err := tempFile.Chmod(fileMode); err != nil {\n\t\treturn fmt.Errorf(\"error setting mode on temp file %q: %w\", tempFile.Name(), err)\n\t}\n\n\tif err := tempFile.Close(); err != nil {\n\t\treturn fmt.Errorf(\"error closing temp file %q: %w\", tempFile.Name(), err)\n\t}\n\tcloseTempFile = false\n\n\tif err := os.Rename(tempFile.Name(), destPath); err != nil {\n\t\treturn fmt.Errorf(\"error renaming temp file %q -> %q: %w\", tempFile.Name(), destPath, err)\n\t}\n\tdeleteTempFile = false\n\n\treturn nil\n}\n\nfunc EnsureFileMode(destPath string, fileMode os.FileMode) (bool, error) {\n\tchanged := false\n\tstat, err := os.Lstat(destPath)\n\tif err != nil {\n\t\treturn changed, fmt.Errorf(\"error getting file mode for %q: %v\", destPath, err)\n\t}\n\tif (stat.Mode() & os.ModePerm) == fileMode {\n\t\treturn changed, nil\n\t}\n\tklog.Infof(\"Changing file mode for %q to %s\", destPath, fileMode)\n\n\terr = os.Chmod(destPath, fileMode)","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/files.go#L83-L119","documentation":"Thrown by writeFileContents when the atomic final step — renaming the completed temp file over the destination path — fails. Typical causes: destination is a directory, cross-device link errors if temp and destination ended up on different mounts, permission issues on the destination, or the destination file is busy/immutable.","triggerScenarios":"Thrown at upup/pkg/fi/files.go:101 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check permissions and ownership on the existing destination path","Ensure the temp file (created in the destination directory) and destination are on the same filesystem","Remove a stale directory occupying the destination path","Verify the file isn't held with immutable attributes or locks preventing replace"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}