{"record":{"id":"4d1044a80c3daf3e","repo":"NationalSecurityAgency/ghidra","slug":"unable-to-delete-temporary-file-listfile-getabso","errorCode":null,"errorMessage":"Unable to delete temporary file: {listFile.getAbsolutePath()}","messagePattern":"Unable to delete temporary file: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java","lineNumber":1050,"sourceCode":"\t\telse if (dir.isDirectory() == false) {\n\t\t\tthrow new IOException(dir.getAbsolutePath() + \": is not a directory\");\n\t\t}\n\t\tdir = dir.getCanonicalFile();\n\t\treturn dir;\n\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;","sourceCodeStart":1032,"sourceCodeEnd":1068,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java#L1032-L1068","documentation":"Thrown by deleteTemporaryDirectory when an individual file within the temp directory cannot be deleted (listFile.delete() returns false). File.delete() fails when the file is locked, the process lacks permission, or the file is in use. The exception aborts cleanup, potentially leaving remaining files and the directory behind.","triggerScenarios":"A file inside the temp directory is still open or locked by another process or thread when deleteTemporaryDirectory tries to clean up. On Windows, this is common when a FileWriter or other handle hasn't been closed. On Unix, it can be a permission issue.","commonSituations":"A prior FileWriter was not closed properly (leaked handle) and the OS still holds the file open; another BSim thread or process is reading the file; antivirus or backup software scanning the temp directory on Windows; the file was created by a process running as a different user.","solutions":["Ensure all FileWriter and file handles are properly closed (use try-with-resources) before cleanup runs.","Run cleanup with the same user that created the files.","On Windows, disable or exclude the temp directory from antivirus scanning.","Make cleanup best-effort: catch and log individual file deletion failures rather than aborting."],"exampleFix":"// before\nfor (File listFile : listFiles) {\n    if (!listFile.delete()) {\n        throw new IOException(\"Unable to delete temporary file: \" + listFile.getAbsolutePath());\n    }\n}\n\n// after — best-effort, collect failures\nList<String> failed = new ArrayList<>();\nfor (File listFile : listFiles) {\n    if (!listFile.delete()) {\n        failed.add(listFile.getAbsolutePath());\n    }\n}\nif (!failed.isEmpty()) {\n    Msg.warn(this, \"Could not delete \" + failed.size() + \" temp files: \" + failed);\n}","handlingStrategy":"try-catch","validationCode":"// Ensure all file handles are closed before cleanup\n// Use try-with-resources for all FileWriter/FileInputStream operations\ntry (FileWriter w = new FileWriter(file)) {\n    manager.saveXml(w);\n} // handle closed here, safe to delete afterward","typeGuard":"// No type guard — this is a runtime file-lock issue.\n// Best prevention is ensuring handles are closed.","tryCatchPattern":"// Best-effort file deletion — don't abort on individual file failures\nfor (File listFile : listFiles) {\n    if (!listFile.delete()) {\n        Msg.warn(this, \"Could not delete: \" + listFile.getAbsolutePath());\n        // System.gc() may help release handles on some JVMs\n    }\n}","preventionTips":["Always use try-with-resources to close file handles before cleanup.","Ensure no concurrent process holds locks on temp files.","On Windows, exclude the temp directory from antivirus scanning.","Treat individual file deletion as best-effort during cleanup."],"tags":["bsim","file-io","temp-directory","cleanup","file-lock"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}