{"record":{"id":"59737d2bf3098d72","repo":"github/copilot-sdk","slug":"restoring-existing-s-permissions-w","errorCode":null,"errorMessage":"restoring existing %s permissions: %w","messagePattern":"restoring existing (.+?) permissions: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/internal/embeddedcli/embeddedcli.go","lineNumber":460,"sourceCode":"}\n\nfunc installVerifiedFile(path string, reader io.Reader, expectedHash []byte, mode os.FileMode, label string) error {\n\tif _, err := os.Stat(path); err == nil {\n\t\texistingHash, err := hashFile(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"hashing existing %s: %w\", label, err)\n\t\t}\n\t\tif !bytes.Equal(existingHash, expectedHash) {\n\t\t\treturn fmt.Errorf(\"existing %s hash mismatch\", label)\n\t\t}\n\t\tif runtime.GOOS != \"windows\" && mode.Perm()&0111 != 0 {\n\t\t\tinfo, err := os.Stat(path)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"checking existing %s permissions: %w\", label, err)\n\t\t\t}\n\t\t\tif info.Mode().Perm()&0111 == 0 {\n\t\t\t\tif err := os.Chmod(path, info.Mode().Perm()|mode.Perm()&0111); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"restoring existing %s permissions: %w\", label, err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n\n\ttmp, err := os.CreateTemp(filepath.Dir(path), \".copilot-runtime-pair-*.tmp\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating temporary %s: %w\", label, err)\n\t}\n\ttmpPath := tmp.Name()\n\th := sha256.New()\n\t_, err = io.Copy(io.MultiWriter(tmp, h), reader)\n\tif err1 := tmp.Chmod(mode); err1 != nil && err == nil {\n\t\terr = err1\n\t}\n\tif err1 := tmp.Close(); err1 != nil && err == nil {\n\t\terr = err1","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/internal/embeddedcli/embeddedcli.go#L442-L478","documentation":"If an existing, hash-verified file lacks the execute bits required by the asset mode, installVerifiedFile adds them via os.Chmod(path, existingPerm | mode&0111). This error wraps a Chmod failure — the file's permissions could not be updated to make it executable.","triggerScenarios":"os.Chmod fails while restoring the executable bit on an existing hash-matching file, typically because the current user is not the file's owner and lacks permission to change its mode.","commonSituations":"The binary was previously installed by root (or another user) and is now being reused/verified by a non-privileged user on Linux/macOS; read-only mount points that reject chmod.","solutions":["Run the install as the file's owner or with elevated privileges (sudo) so chmod can succeed.","chown the installed file to the user running the application.","Remove the file and reinstall so it is created fresh with the correct mode."],"exampleFix":"// before\n$ ls -l bin/cli-server  # owned by root, no exec bit\n// after\n$ sudo chown $(whoami) bin/cli-server && $APP reinstall","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := client.InstallAt(dir); err != nil {\n    var pe *fs.PathError\n    if strings.Contains(err.Error(), \"restoring existing\") {\n        // advise running as the file owner or deleting the file\n        _ = pe\n    }\n}","preventionTips":["Install and run as the same OS user","Don't install with sudo then run as a normal user","Ensure install filesystem supports chmod (not some read-only mounts)"],"tags":["chmod","permissions","filesystem"],"backgroundTag":"file-write-permission-denied","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}