{"record":{"id":"ad6873aef53e8d36","repo":"kubernetes/kops","slug":"error-setting-file-mode-for-q-v","errorCode":null,"errorMessage":"error setting file mode for %q: %v","messagePattern":"error setting file mode for %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/files.go","lineNumber":121,"sourceCode":"\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)\n\tif err != nil {\n\t\treturn changed, fmt.Errorf(\"error setting file mode for %q: %v\", destPath, err)\n\t}\n\tchanged = true\n\treturn changed, nil\n}\n\nfunc fileHasHash(f string, expected *hashing.Hash) (bool, error) {\n\tactual, err := expected.Algorithm.HashFile(f)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn false, err\n\t}\n\n\tif actual.Equal(expected) {\n\t\tklog.V(2).Infof(\"Hash matched for %q: %v\", f, expected)\n\t\treturn true, nil\n\t}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/files.go#L103-L139","documentation":"Thrown by EnsureFileMode when the file's current permission bits differ from the desired mode and os.Chmod fails while trying to fix them. Usually a permissions problem: the running user owns neither the file nor effective rights to change its mode, or the filesystem rejects chmod.","triggerScenarios":"Thrown at upup/pkg/fi/files.go:121 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check ownership of the file and adjust with chown, or run the operation as a user allowed to chmod it","Verify the desired mode is valid for the filesystem","If the mode mismatch is acceptable, align the spec's file mode with the existing one"],"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"}