{"record":{"id":"23f47058b16ffe72","repo":"NationalSecurityAgency/ghidra","slug":"unable-to-delete-temp-directory-tempdir-getabsol","errorCode":null,"errorMessage":"Unable to delete temp directory: {tempDir.getAbsolutePath()}","messagePattern":"Unable to delete temp directory: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java","lineNumber":1055,"sourceCode":"\t}\n\n\tprivate void deleteTemporaryDirectory(File tempDir) throws IOException {\n\t\tif (!tempDir.exists()) {\n\t\t\treturn;\n\t\t}\n\t\tFile[] listFiles = tempDir.listFiles();\n\t\tif (listFiles == null) {\n\t\t\tthrow new IOException(\n\t\t\t\t\"Could not list files in temp directory: \" + tempDir.getAbsolutePath());\n\t\t}\n\t\tfor (File listFile : listFiles) {\n\t\t\tif (!listFile.delete()) {\n\t\t\t\tthrow new IOException(\n\t\t\t\t\t\"Unable to delete temporary file: \" + listFile.getAbsolutePath());\n\t\t\t}\n\t\t}\n\t\tif (!tempDir.delete()) {\n\t\t\tthrow new IOException(\"Unable to delete temp directory: \" + tempDir.getAbsolutePath());\n\t\t}\n\t}\n\n\tprivate class UpdateRepository extends IterateRepository {\n\t\tprivate File outdirectory;\n\t\tprivate String repo;\n\t\tprivate boolean overwrite;\n\t\tprivate DatabaseInformation info;\n\t\tprivate LSHVectorFactory vectorFactory;\n\n\t\tpublic UpdateRepository(File outdir, String rp, boolean owrite, DatabaseInformation i,\n\t\t\t\tLSHVectorFactory vFactory) {\n\t\t\toutdirectory = outdir;\n\t\t\trepo = rp;\n\t\t\toverwrite = owrite;\n\t\t\tinfo = i;\n\t\t\tvectorFactory = vFactory;\n\t\t}","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java#L1037-L1073","documentation":"Thrown by deleteTemporaryDirectory when tempDir.delete() returns false after all contained files have been successfully deleted. Directory.delete() only succeeds if the directory is empty and no process holds a lock on it. If another process re-created a file in the directory between the file-deletion loop and the directory deletion, or if the OS holds a handle, this fails.","triggerScenarios":"The directory is not empty at deletion time (a concurrent process wrote a new file); the directory itself is locked by another process (e.g., a shell with cwd inside it on Windows); permissions prevent deletion of the directory entry.","commonSituations":"Concurrent BSim runs sharing the same temp directory; a shell or file browser has the directory open; Windows Explorer holding a handle; another process re-populated the directory between file cleanup and directory deletion.","solutions":["Ensure no concurrent processes use the same temp directory.","Close any shells or tools that may have the directory as their working directory.","Make the final directory deletion best-effort (log instead of throw) since leftover empty directories are low-impact.","Use a unique temp directory name per run to avoid contention."],"exampleFix":"// before\nif (!tempDir.delete()) {\n    throw new IOException(\"Unable to delete temp directory: \" + tempDir.getAbsolutePath());\n}\n\n// after — best-effort cleanup\nif (!tempDir.delete()) {\n    Msg.warn(this, \"Unable to delete temp directory (may be in use): \" + tempDir.getAbsolutePath());\n}","handlingStrategy":"try-catch","validationCode":"// No pre-validation can prevent this — it is a runtime concurrency issue.\n// Ensure no concurrent processes use the same temp directory.\n// Use unique directory names per run to avoid contention.","typeGuard":"// No type guard applicable — runtime filesystem state issue.","tryCatchPattern":"// Best-effort directory deletion at end of cleanup\nif (!tempDir.delete()) {\n    Msg.warn(this, \"Could not delete temp directory: \" + tempDir.getAbsolutePath() +\n        \" (may be in use by another process)\");\n    // Register for deletion on JVM exit as fallback\n    tempDir.deleteOnExit();\n}","preventionTips":["Use unique temp directory names per run to avoid contention.","Ensure no other process has the directory as its working directory.","Treat final directory deletion as best-effort.","Call deleteOnExit() as a fallback for stubborn directories."],"tags":["bsim","file-io","temp-directory","cleanup","concurrency"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}