{"record":{"id":"810c3613a415e460","repo":"AdguardTeam/AdGuardHome","slug":"opening-pending-file-w","errorCode":null,"errorMessage":"opening pending file: %w","messagePattern":"opening pending file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/aghrenameio/renameio_windows.go","lineNumber":62,"sourceCode":"\t}\n\n\treturn nil\n}\n\n// Write implements the [PendingFile] interface for *pendingFile.\nfunc (f *pendingFile) Write(b []byte) (n int, err error) {\n\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":44,"sourceCodeEnd":77,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/aghrenameio/renameio_windows.go#L44-L77","documentation":"newPendingFile (Windows implementation) creates the temp sibling file with os.CreateTemp in the target's directory; this error means temp-file creation failed — almost always a filesystem permission or path problem in the directory holding the target.","triggerScenarios":"Calling newPendingFile when filepath.Dir(filePath) doesn't exist, is read-only for the process, is not a directory, or the filesystem is full (ENOSPC); also invalid path characters on Windows.","commonSituations":"Writing config/data into a directory the service account can't write (Program Files without elevation); stale configured path pointing to a removed directory; full disks.","solutions":["Ensure the target directory exists and is writable by the service account","Run the service with an account that has write access to the data dir, or move the data dir to a writable location","Free disk space if the volume is full","Validate the configured path at startup before attempting writes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"dir := filepath.Dir(target)\nif fi, err := os.Stat(dir); err != nil || !fi.IsDir() { /* create dir or fail fast */ }\nif err := unix.Access(dir, unix.W_OK); err != nil { /* fix permissions */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create and permission data directories at install/startup time","Run the service under an account with write access to the data dir","Check disk space before write-heavy operations"],"tags":["windows","create-temp","permission","disk-full"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}