{"record":{"id":"c39de3e8aaa03f42","repo":"moonD4rk/HackBrowserData","slug":"create-temp-dir-w","errorCode":null,"errorMessage":"create temp dir: %w","messagePattern":"create temp dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"filemanager/session.go","lineNumber":21,"sourceCode":"import (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"runtime\"\n)\n\n// Session manages temporary files for a single browser extraction run.\n// It creates an isolated temp directory and provides methods to copy\n// browser files into it. Call Cleanup() when done to remove all temp files.\ntype Session struct {\n\ttempDir string\n}\n\n// NewSession creates a session with a unique temporary directory.\nfunc NewSession() (*Session, error) {\n\tdir, err := os.MkdirTemp(\"\", \"hbd-*\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create temp dir: %w\", err)\n\t}\n\treturn &Session{tempDir: dir}, nil\n}\n\n// TempDir returns the session's temporary directory path.\nfunc (s *Session) TempDir() string {\n\treturn s.tempDir\n}\n\n// Acquire copies a browser file (or directory) from src to dst.\n// For regular files, it also copies SQLite WAL and SHM companion files\n// if they exist. For directories (e.g. LevelDB), it copies the entire\n// directory while skipping lock files.\n//\n// On Windows, if the normal copy fails (e.g. file locked by Chrome),\n// it falls back to DuplicateHandle + FileMapping to bypass exclusive locks.\nfunc (s *Session) Acquire(src, dst string, isDir bool) error {\n\tif isDir {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/filemanager/session.go#L3-L39","documentation":"NewSession wraps os.MkdirTemp failures with \"create temp dir: %w\". Every extraction run starts by creating a unique temporary directory (prefix \"hbd-\" under os.TempDir()) to stage copied browser files. If the OS refuses to create that directory, the session cannot start and no browser data can be extracted.","triggerScenarios":"Calling filemanager.NewSession() when the temp directory (TMP/TEMP on Windows, /tmp on Unix) does not exist, is not writable, is full, or when the environment TMPDIR/TMP/TEMP points to an invalid path.","commonSituations":"Running in restricted sandboxes/containers with read-only /tmp; TMPDIR pointing at a deleted or non-existent directory; disk quota exhausted; Windows services running under accounts without a writable %TEMP%; temp cleaner processes racing the tool.","solutions":["Check and fix the temp environment variables (TMP/TEMP/TMPDIR) so they point to an existing, writable directory.","Free disk space on the volume holding the temp directory.","Run the tool under a user account with write permission on the temp directory.","As a last resort, set TMPDIR to a manually created writable directory before launching (e.g. TMPDIR=/var/tmp/hbd hbd ...)."],"exampleFix":"// before\nsession, err := filemanager.NewSession()\nif err != nil {\n    return err\n}\n// after\nif err := os.MkdirAll(os.TempDir(), 0o700); err != nil {\n    return fmt.Errorf(\"temp dir unavailable: %w\", err)\n}\nsession, err := filemanager.NewSession()\nif err != nil {\n    return fmt.Errorf(\"session setup: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// verify temp location is writable before calling NewSession\nprobe := filepath.Join(os.TempDir(), \".hbd-probe\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil {\n    return fmt.Errorf(\"temp dir %s not writable: %w\", os.TempDir(), err)\n}\nos.Remove(probe)\nsession, err := filemanager.NewSession()","typeGuard":null,"tryCatchPattern":"// Go\nsession, err := filemanager.NewSession()\nif err != nil {\n    return fmt.Errorf(\"cannot create session (check TMP/TEMP/TMPDIR and disk space): %w\", err)\n}","preventionTips":["Keep TMP/TEMP/TMPDIR pointing at an existing writable directory","Monitor free disk space on the temp volume","In containers, mount a writable tmpfs at /tmp"],"tags":["temp-directory","filesystem","environment","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"0503d04d7a8d0379d060268a74f1b149e5a0aad5","analyzedAt":"2026-09-06T13:38:28.707Z","contentChangedAt":"2026-09-06T13:38:28.707Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}