{"record":{"id":"086b2e335c38f6c0","repo":"chenhg5/cc-connect","slug":"create-data-dir-w","errorCode":null,"errorMessage":"create data dir: %w","messagePattern":"create data dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/windows.go","lineNumber":44,"sourceCode":"\nfunc strictPowerShell(script string) string {\n\treturn \"$ErrorActionPreference = 'Stop'\\n\" + script\n}\n\ntype schtasksManager struct{}\n\nfunc newPlatformManager() (Manager, error) {\n\tif _, err := exec.LookPath(\"powershell.exe\"); err != nil {\n\t\treturn nil, fmt.Errorf(\"powershell.exe not found: Windows Task Scheduler management requires PowerShell\")\n\t}\n\treturn &schtasksManager{}, nil\n}\n\nfunc (*schtasksManager) Platform() string { return \"schtasks\" }\n\nfunc (m *schtasksManager) Install(cfg Config) error {\n\tif err := os.MkdirAll(DefaultDataDir(), 0755); err != nil {\n\t\treturn fmt.Errorf(\"create data dir: %w\", err)\n\t}\n\tif err := os.MkdirAll(filepath.Dir(cfg.LogFile), 0755); err != nil {\n\t\treturn fmt.Errorf(\"create log dir: %w\", err)\n\t}\n\n\tscriptPath := windowsTaskScriptPath()\n\t// 0644 has weak semantics on Windows; the file ACL is what matters.\n\t// We still write 0600 so the file's POSIX bits do not advertise read\n\t// access, and rely on the user's own profile ACLs for primary defense\n\t// (the script lives under %USERPROFILE%\\.cc-connect by default).\n\t// WriteFile only applies perm on create, so Chmod the existing file\n\t// after writing to harden reinstalls of pre-existing 0644 scripts.\n\tif err := os.WriteFile(scriptPath, []byte(buildWindowsTaskScript(cfg)), 0600); err != nil {\n\t\treturn fmt.Errorf(\"write task script: %w\", err)\n\t}\n\tif err := os.Chmod(scriptPath, 0600); err != nil {\n\t\treturn fmt.Errorf(\"chmod task script: %w\", err)\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/windows.go#L26-L62","documentation":"schtasksManager.Install (Windows) first ensures cc-connect's data directory exists via os.MkdirAll(DefaultDataDir(), 0755) and wraps any failure as \"create data dir: %w\". It fires when the directory cannot be created or verified — typically a permission problem, an invalid path, or a non-directory file occupying the path. The wrapped original error (e.g. access is denied) is preserved for diagnosis.","triggerScenarios":"Running `cc-connect daemon install` on Windows when the default data dir (under %USERPROFILE%\\.cc-connect) cannot be MkdirAll'd: read-only or redirected USERPROFILE, antivirus/ACL denial, or DefaultDataDir() resolving to a drive letter that does not exist.","commonSituations":"Installing as a service account whose profile is not provisioned (TEMP-profile services); roaming profiles with deny ACLs; running from a sandboxed/readonly environment; a stale file named `.cc-connect` sitting in the profile root.","solutions":["Check the wrapped cause in the error text (e.g. \"Access is denied\") and fix that underlying ACL or path problem first","Run the install from an interactive account with a real %USERPROFILE%, or pre-create %USERPROFILE%\\.cc-connect manually with correct permissions","Verify the path is not occupied by a file: `dir %USERPROFILE%` — rename/remove any entry named `.cc-connect` that is a file","If USERPROFILE points to a missing drive, correct the environment variable or the profile for the account"],"exampleFix":"// before\n$ cc-connect daemon install\n// error: create data dir: mkdir ...: Access is denied.\n// after: pre-create with correct ACL\n> mkdir %USERPROFILE%\\.cc-connect\n> icacls %USERPROFILE%\\.cc-connect /grant \"%USERNAME%:(OI)(CI)F\"\n> cc-connect daemon install","handlingStrategy":"validation","validationCode":"dataDir := os.UserHomeDir() + \"\\\\.cc-connect\"\nif st, err := os.Stat(dataDir); err == nil && !st.IsDir() {\n    log.Fatalf(\"%s exists but is a file; remove or rename it before daemon install\", dataDir)\n}\nif err := os.MkdirAll(dataDir, 0o755); err != nil {\n    log.Fatalf(\"cannot create data dir %s: %v — fix ACLs/profile before install\", dataDir, err)\n}","typeGuard":null,"tryCatchPattern":"if err := daemon.Install(cfg); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \"create data dir\") {\n        return fmt.Errorf(\"check permissions/ACLs on %s and that USERPROFILE is valid: %w\", pe.Path, err)\n    }\n    return err\n}","preventionTips":["Ensure the account running `daemon install` has a real provisioned %USERPROFILE% (interactive logins, not TEMP-profile service accounts)","Pre-create %USERPROFILE%\\.cc-connect with correct ACLs during machine provisioning","Check that no file named `.cc-connect` occupies the profile root before installing","Verify the underlying drive exists and is writable; watch for antivirus Controlled Folder Access interference"],"tags":["windows","filesystem","mkdir","permissions","daemon"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}