{"record":{"id":"ec5ebecc2f63794b","repo":"AdguardTeam/AdGuardHome","slug":"preparing-pending-file-w","errorCode":null,"errorMessage":"preparing pending file: %w","messagePattern":"preparing pending file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/aghrenameio/renameio_windows.go","lineNumber":69,"sourceCode":"\treturn f.file.Write(b)\n}\n\n// NewPendingFile is a wrapper around [os.CreateTemp].\n//\n// f.Close must be called to finish the renaming.\nfunc newPendingFile(filePath string, mode fs.FileMode) (f PendingFile, err error) {\n\t// Use the same directory as the file itself, because moves across\n\t// filesystems can be especially problematic.\n\tfile, err := os.CreateTemp(filepath.Dir(filePath), \"\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"opening pending file: %w\", err)\n\t}\n\n\t// TODO(e.burkov):  The [os.Chmod] implementation is useless on Windows,\n\t// investigate if it can be removed.\n\terr = os.Chmod(file.Name(), mode)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"preparing pending file: %w\", err)\n\t}\n\n\treturn &pendingFile{\n\t\tfile:       file,\n\t\ttargetPath: filePath,\n\t}, nil\n}\n","sourceCodeStart":51,"sourceCodeEnd":77,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/aghrenameio/renameio_windows.go#L51-L77","documentation":"After creating the temp file, newPendingFile applies the requested mode with os.Chmod; failure produces this error. The code itself notes os.Chmod is 'useless on Windows', so on Windows this mostly surfaces for lock/attribute issues rather than permission bits.","triggerScenarios":"os.Chmod failing on the just-created temp file — file locked by AV/indexer at that instant, read-only directory inheritance, or the file already closed/removed by external interference.","commonSituations":"Antivirus racing newly created files in the data directory; directories enforcing read-only inheritance; exotic filesystems (network shares) not supporting attribute changes.","solutions":["Retry once after a short delay to rule out transient AV locks","Exclude the working directory from real-time AV scanning","If on a network share, write locally and copy instead","Contribute upstream: the TODO suggests removing the no-op Chmod on Windows, which eliminates this failure mode"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"preparing pending file\") {\n    time.Sleep(100 * time.Millisecond)\n    // recreate pending file and retry once\n}","preventionTips":["Exclude the working directory from AV real-time scanning","Avoid network shares for atomic-write targets","Contribute upstream removal of the no-op Chmod on Windows"],"tags":["windows","chmod","file-attributes","transient-lock"],"backgroundTag":"chmod-failed","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}