{"record":{"id":"0f0c025f4b3e0d4b","repo":"larksuite/cli","slug":"cannot-inspect-opened-file-links-w","errorCode":null,"errorMessage":"cannot inspect opened file links: %w","messagePattern":"cannot inspect opened file links: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/vfs/localfileio/openvalidated_windows.go","lineNumber":54,"sourceCode":"\treturn f, nil\n}\n\n// inspectOpenedFile validates the opened handle. pre is nil when there is no\n// prior Stat to compare against.\nfunc inspectOpenedFile(f *os.File, pre os.FileInfo) error {\n\tpost, err := f.Stat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot stat opened file: %w\", err)\n\t}\n\tif pre != nil && !os.SameFile(pre, post) {\n\t\treturn fmt.Errorf(\"file changed between validation and open\")\n\t}\n\tif !post.Mode().IsRegular() {\n\t\treturn fmt.Errorf(\"not a regular file (directories, devices, FIFOs, and sockets are refused)\")\n\t}\n\tvar handleInfo syscall.ByHandleFileInformation\n\tif err := syscall.GetFileInformationByHandle(syscall.Handle(f.Fd()), &handleInfo); err != nil {\n\t\treturn fmt.Errorf(\"cannot inspect opened file links: %w\", err)\n\t}\n\tif handleInfo.NumberOfLinks > 1 {\n\t\treturn fmt.Errorf(\"file has multiple hard links, so the other names it can be reached by \" +\n\t\t\t\"cannot be checked (hint: copy the file and use the copy instead)\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":36,"sourceCodeEnd":62,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/vfs/localfileio/openvalidated_windows.go#L36-L62","documentation":"The Windows API GetFileInformationByHandle failed when the library tried to read ByHandleFileInformation (used to count hard links) for the opened file. The library needs the link count to enforce its hard-link safety check, so when the count cannot be read it refuses the open rather than skipping the check. The wrapped cause carries the underlying syscall error.","triggerScenarios":"Calling openValidated on Windows when GetFileInformationByHandle fails on the freshly opened handle — e.g. unsupported filesystem (FAT32/exFAT network share semantics), handle became invalid, or insufficient permissions on exotic volumes.","commonSituations":"Files on non-NTFS filesystems or network mounts (SMB shares, WSL mounts) with restricted file information, security software interfering with handle queries, or corrupt/unclean filesystem state.","solutions":["Move or copy the file onto a local NTFS volume and open it there","Inspect the wrapped OS error (%w) to identify the failing syscall and volume type","Retry; if caused by transient AV/driver interference, a repeat open often succeeds","Use the library's non-validated open path only if the hard-link guarantee is not required for your use case"],"exampleFix":"// before: opening directly from a network share\nf, err := openValidated(`\\\\server\\share\\data.json`, pre)\n// after: copy to a local NTFS temp file first\nlocal := filepath.Join(os.TempDir(), \"data.json\")\nif err := copyFile(`\\\\server\\share\\data.json`, local); err != nil { return err }\nf, err := openValidated(local, nil)","handlingStrategy":"fallback","validationCode":"// ensure a local NTFS-style volume\nabs, _ := filepath.Abs(path)\nvol := filepath.VolumeName(abs)\nif vol == \"\" || isRemoteUNC(vol) { return fmt.Errorf(\"%s is not on a local volume\", abs) }","typeGuard":null,"tryCatchPattern":"f, err := openValidated(path, pre)\nif err != nil && strings.Contains(err.Error(), \"cannot inspect opened file links\") {\n    // fall back to copying to local temp and opening the copy\n    local := filepath.Join(os.TempDir(), filepath.Base(path))\n    if cerr := copyFile(path, local); cerr != nil { return cerr }\n    f, err = openValidated(local, nil)\n}\nreturn err","preventionTips":["Work on local NTFS volumes rather than SMB shares, FAT/exFAT, or exotic mounts","Disable or configure security software that hooks handle queries","Keep filesystems healthy (run chkdsk after suspected corruption)"],"tags":["windows","filesystem","syscall","hard-links"],"backgroundTag":"getfileinformationbyhandle-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}