{"record":{"id":"fc1e9166a86b3b4a","repo":"hashicorp/nomad","slug":"cannot-create-copy-s","errorCode":null,"errorMessage":"cannot create copy - %s","messagePattern":"cannot create copy - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":345,"sourceCode":"\topts.binaryPath = filepath.Join(opts.installDir, \"nomad.exe\")\n\n\t// Ensure the install directory exists\n\tif err = c.winPaths.CreateDirectory(opts.installDir, false); err != nil {\n\t\treturn fmt.Errorf(\"could not create binary install directory - %s\", err)\n\t}\n\n\t// Create a new copy of the current binary to install\n\texeFile, err := os.Open(exePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot open current nomad path for install - %s\", err)\n\t}\n\tdefer exeFile.Close()\n\n\t// Copy into a temporary file which can then be moved\n\t// into the correct location.\n\tdstFile, err := os.CreateTemp(os.TempDir(), \"nomad*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot create copy - %s\", err)\n\t}\n\tdefer dstFile.Close()\n\n\tif _, err = io.Copy(dstFile, exeFile); err != nil {\n\t\treturn fmt.Errorf(\"cannot write nomad binary for install - %s\", err)\n\t}\n\tdstFile.Close()\n\n\t// With a copy ready to be moved into place, ensure that\n\t// the path is clear then move the file.\n\tif err = os.RemoveAll(opts.binaryPath); err != nil {\n\t\treturn fmt.Errorf(\"cannot remove existing nomad binary install - %s\", err)\n\t}\n\n\tif err = os.Rename(dstFile.Name(), opts.binaryPath); err != nil {\n\t\treturn fmt.Errorf(\"cannot install new nomad binary - %s\", err)\n\t}\n","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L327-L363","documentation":"binaryInstall wraps the error from os.CreateTemp, which creates the temporary copy of the nomad binary used for the Windows service installation. It indicates the temp file could not be created, typically due to filesystem or permission problems in the system temp directory. The wrapped OS error carries the concrete cause.","triggerScenarios":"os.TempDir() is unwritable, the disk holding the temp dir is full, antivirus/permissions block temp file creation, or TMP/TEMP env vars point to a nonexistent path while performInstall installs the Windows service.","commonSituations":"Running the installer under a service account with no write access to %TEMP%; full system drive; restricted environments where the temp dir is mounted noexec or read-only.","solutions":["Check the OS error wrapped in the message for the concrete cause (permission denied, no space left, etc.)","Verify TMP/TEMP point to an existing writable directory, or run as an account with write access to it","Free disk space on the drive holding the temp directory","Exclude the installer from antivirus/EDR that blocks temp file creation"],"exampleFix":"// before (reading TMP from a stale env var)\nset TMP=C:\\nonexistent\n// after\nset TMP=C:\\Windows\\Temp","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(os.TempDir()); err != nil || fi.Mode()&0200 == 0 {\n    return fmt.Errorf(\"temp dir %s not writable: %v\", os.TempDir(), err)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"cannot create copy\") {\n        // check TMP writability / disk space before retrying\n    }\n}","preventionTips":["Run service installs elevated or as an account with writable %TEMP%","Monitor free disk space on the system drive","Avoid redirecting TMP to network or read-only paths"],"tags":["go","windows","filesystem","permissions"],"backgroundTag":"temp-file-create-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}