{"record":{"id":"4bec191abc4411e9","repo":"cilium/cilium","slug":"failed-to-create-file-s-w","errorCode":null,"errorMessage":"failed to create file %s: %w","messagePattern":"failed to create file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cilium-cli/features/summary.go","lineNumber":252,"sourceCode":"\t\tdestPath := filepath.Join(destDir, cleanName)\n\t\tif !strings.HasPrefix(destPath, filepath.Clean(destDir)+string(os.PathSeparator)) {\n\t\t\treturn fmt.Errorf(\"file path escapes destination directory: %s\", destPath)\n\t\t}\n\n\t\tif file.FileInfo().IsDir() {\n\t\t\t// Create directories\n\t\t\tif err := os.MkdirAll(destPath, os.ModePerm); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create directory %s: %w\", destPath, err)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\t// Create directories\n\t\tos.MkdirAll(filepath.Dir(destPath), os.ModePerm)\n\n\t\t// Extract files\n\t\tdestFile, err := os.OpenFile(destPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create file %s: %w\", destPath, err)\n\t\t}\n\t\tsrcFile, err := file.Open()\n\t\tif err != nil {\n\t\t\tdestFile.Close()\n\t\t\treturn fmt.Errorf(\"failed to open file in ZIP archive %s: %w\", file.Name, err)\n\t\t}\n\t\t_, err = io.Copy(destFile, srcFile)\n\t\tdestFile.Close()\n\t\tsrcFile.Close()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to extract file %s: %w\", file.Name, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// nodesValues maps a node to value","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/cilium-cli/features/summary.go#L234-L270","documentation":"For each regular file entry, extractZip creates the destination file with os.OpenFile using the entry's stored permissions. Failure to create/open the destination file produces this wrapped error.","triggerScenarios":"os.OpenFile(destPath, O_WRONLY|O_CREATE|O_TRUNC, file.Mode()) fails: parent directory missing or unwritable, or the target exists as a directory/read-only file.","commonSituations":"Archive entries with modes like 0555 being re-extracted over existing files; disk full; antivirus or SELinux blocking writes; partial prior extraction left a directory where a file belongs.","solutions":["Clean destDir and re-extract to remove stale conflicting entries","Check free disk space and write permissions on destDir","Retry with elevated permissions if the destination is protected","Check for security software (SELinux/AppArmor) denying writes"],"exampleFix":"// before\nextractZip(tempFile, destDir)\n// after\nos.RemoveAll(destDir)\nos.MkdirAll(destDir, 0o755)\nextractZip(tempFile, destDir)","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(destDir); err != nil || !fi.IsDir() {\n\treturn fmt.Errorf(\"destination %s must exist and be a directory\", destDir)\n}","typeGuard":null,"tryCatchPattern":"if err := extractZip(zipPath, destDir); err != nil {\n\tvar pathErr *fs.PathError\n\tif errors.As(err, &pathErr) {\n\t\tswitch {\n\t\tcase errors.Is(pathErr.Err, fs.ErrPermission): // fix perms\n\t\tcase errors.Is(pathErr.Err, syscall.ENOSPC): // free disk space\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["Ensure sufficient free disk space","Clean partial extraction state before retrying","Confirm no security software blocks file creation","Run with a user that owns destDir"],"tags":["filesystem","permissions","zip"],"backgroundTag":"file-open-permission-denied","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}