{"record":{"id":"167222569d896ec4","repo":"NationalSecurityAgency/ghidra","slug":"couldn-t-create-file-projectfile-getabsolutepa","errorCode":null,"errorMessage":"Couldn't create file \" + projectFile.getAbsolutePath()","messagePattern":"Couldn't create file \" \\+ projectFile\\.getAbsolutePath\\(\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/archive/RestoreTask.java","lineNumber":112,"sourceCode":"\t\t}\n\t\tcatch (CancelledException ce) {\n\t\t\tplugin.cleanupRestoredProject(projectLocator);\n\t\t\tMsg.info(this, \"Restore Archive: \" + locInfo + \" was cancelled by user.\");\n\t\t}\n\t\tcatch (Throwable e) {\n\t\t\tplugin.cleanupRestoredProject(projectLocator);\n\t\t\tString eMsg = (e.getMessage() != null) ? \":\\n\\n\" + e.getMessage() : \"\";\n\t\t\tMsg.showError(this, null, \"Restore Archive Failed\",\n\t\t\t\t\"An error occurred when restoring the project archive\\n \" + projectArchiveFile +\n\t\t\t\t\t\" to \\n \" + projectDir + eMsg,\n\t\t\t\te);\n\t\t\tMsg.info(this, \"Restore Archive: \" + locInfo + \" failed.\");\n\t\t}\n\t}\n\n\tprivate void createProjectMarkerFile() throws IOException {\n\t\tif (!projectFile.createNewFile()) {\n\t\t\tthrow new IOException(\"Couldn't create file \" + projectFile.getAbsolutePath());\n\t\t}\n\t}\n\n\tprivate void verifyArchive(GFileSystem fs, TaskMonitor monitor) throws IOException {\n\t\tif (!fs.getFSRL().getProtocol().equals(\"zip\")) {\n\t\t\tthrow new IOException(\"Not a zip file: \" + fs.getFSRL());\n\t\t}\n\t\tGFile magicFile = fs.lookup(\"/\" + ArchivePlugin.JAR_VERSION_TAG);\n\t\tif (magicFile == null) {\n\t\t\tthrow new IOException(\"Missing Ghidra Project Archive (.gar) marker file\");\n\t\t}\n\t}\n\n\t@Override\n\tprotected void processFile(GFile file, File destFSFile, TaskMonitor monitor)\n\t\t\tthrows IOException, CancelledException {\n\t\tif (!shouldSkip(file)) {\n\t\t\tsuper.processFile(file, destFSFile, monitor);","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/archive/RestoreTask.java#L94-L130","documentation":"Thrown as IOException by RestoreTask.createProjectMarkerFile when projectFile.createNewFile() returns false, meaning the marker file already exists or could not be created at the target path. RestoreTask creates this marker as part of restoring a project archive, so a failure here blocks the restore.","triggerScenarios":"createNewFile() returns false because projectFile already exists (a previous restore left it), the parent directory does not exist or is not writable, or a permissions/lock issue prevents creation.","commonSituations":"Restoring an archive into a project directory that already contains a marker file from a prior restore; restoring to a read-only or non-existent directory; disk full or path too long; another process holds the file open.","solutions":["Delete the existing marker file (or the whole restore target) before re-running restore.","Ensure the target project directory exists and is writable.","Free disk space and check for locks on the target file.","Catch IOException and report the absolute path so the user can fix permissions/conflicts."],"exampleFix":"// before\nif (!projectFile.createNewFile()) {\n    throw new IOException(\"Couldn't create file \" + projectFile.getAbsolutePath());\n}\n\n// after — clear stale marker first, and check parent writability\nFile parent = projectFile.getParentFile();\nif (parent != null && !parent.exists() && !parent.mkdirs()) {\n    throw new IOException(\"Couldn't create directory \" + parent.getAbsolutePath());\n}\nif (projectFile.exists() && !projectFile.delete()) {\n    throw new IOException(\"Existing marker not removable: \" + projectFile.getAbsolutePath());\n}\nif (!projectFile.createNewFile()) {\n    throw new IOException(\"Couldn't create file \" + projectFile.getAbsolutePath());\n}","handlingStrategy":"validation","validationCode":"File parent = projectFile.getParentFile();\nif (parent != null && !parent.exists() && !parent.mkdirs()) {\n    throw new IOException(\"Couldn't create directory \" + parent.getAbsolutePath());\n}\nif (projectFile.exists() && !projectFile.delete()) {\n    throw new IOException(\"Existing marker not removable: \" + projectFile.getAbsolutePath());\n}","typeGuard":"boolean canCreate = projectFile.getParentFile() != null && projectFile.getParentFile().canWrite() && (!projectFile.exists() || projectFile.delete());","tryCatchPattern":"try {\n    createProjectMarkerFile();\n} catch (IOException e) {\n    Msg.showError(this, null, \"Restore Failed\", e.getMessage());\n}","preventionTips":["Clear stale markers/restore targets before restoring.","Ensure the target directory exists and is writable.","Check free disk space and file locks before restore."],"tags":["ghidra","archive","restore","io","filesystem"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}