{"record":{"id":"932cbc7d61caf0d3","repo":"NationalSecurityAgency/ghidra","slug":"error-copying-original-connection-file","errorCode":null,"errorMessage":"Error copying original connection file","messagePattern":"Error copying original connection file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java","lineNumber":928,"sourceCode":"\t\t}\n\t\tFile configCopy = new File(dataDirectory, POSTGRES_CONFIGFILE + \".orig\");\n\n\t\tif (hostAuthentication == AUTHENTICATION_PKI || localAuthentication == AUTHENTICATION_PKI) {\n\t\t\tFile rootCA = new File(dataDirectory, POSTGRES_ROOTCA);\n\t\t\tFileUtilities.copyFile(certAuthorityFile, rootCA, false, null);\n\t\t\taddCertificateName(connectingUserName);\n\t\t}\n\n\t\t// Move the original configuration file\n\t\tif (!configFile.renameTo(configCopy)) {\n\t\t\tthrow new IOException(\"Error copying original configuration file\");\n\t\t}\n\n\t\tFile hbaCopy = new File(dataDirectory, POSTGRES_CONNECTFILE + \".orig\");\n\n\t\t// Move the original connection file\n\t\tif (!hbaFile.renameTo(hbaCopy)) {\n\t\t\tthrow new IOException(\"Error copying original connection file\");\n\t\t}\n\t\t// Patch the configuration\n\t\ttuneConfig(configCopy, configFile, hbaCopy, hbaFile, serverConfigFile);\n\t\tSystem.out.println(\"Generating servers SSL certificate\");\n\t\tgenerateSelfSignedCertificate(new File(dataDirectory, \"server.crt\"),\n\t\t\tnew File(dataDirectory, \"server.key\"));\n\t}\n\n\t/**\n\t * Scan the PostgreSQL data directory from the command-line\n\t * Make sure the directory exists and establish the File object -dataDirectory-\n\t * @param params are the command-line arguments\n\t * @param slot is the position to retrieve the data directory argument\n\t * @throws IllegalArgumentException if the data directory is invalid\n\t * @throws IOException if the canonical file cannot be retrieved\n\t */\n\tprivate void scanDataDirectory(String[] params, int slot)\n\t\t\tthrows IllegalArgumentException, IOException {","sourceCodeStart":910,"sourceCodeEnd":946,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L910-L946","documentation":"Thrown by initializeDataDirectory() when hbaFile.renameTo(hbaCopy) fails — pg_hba.conf could not be moved to pg_hba.conf.orig. BSim rewrites pg_hba.conf to enforce the chosen auth method (trust/password/cert), so a failed rename halts initialization.","triggerScenarios":"Same renameTo() failure pattern as the config-file move, but for the connection/auth file pg_hba.conf, immediately after the postgresql.conf move.","commonSituations":"Cross-filesystem data directory; pg_hba.conf locked by a running postgres or monitoring tool; permission/ownership mismatch; leftover .orig from an interrupted init.","solutions":["Verify pg_hba.conf exists in the data directory and is writable/owned by the running user.","Ensure no postgres process is running against the data directory during init.","Keep the data directory on one local filesystem.","Clean up any half-applied .orig files from a previous failed run before retrying."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File hba = new File(dataDir, \"pg_hba.conf\");\nFile hbaOrig = new File(dataDir, \"pg_hba.conf.orig\");\nif (hba.exists() && !hba.canWrite()) {\n    throw new IllegalStateException(\"pg_hba.conf not writable; rename will fail\");\n}","typeGuard":"public boolean hbaReadyForPatch(File dir) {\n    File hba = new File(dir, \"pg_hba.conf\");\n    return hba.isFile() && hba.canWrite() && dir.canWrite();\n}","tryCatchPattern":"try {\n    bsimControl.start(args);\n} catch (IOException e) {\n    if (\"Error copying original connection file\".equals(e.getMessage())) {\n        throw new UserFacingException(\"Cannot move pg_hba.conf aside; check perms/fs\", e);\n    }\n    throw e;\n}","preventionTips":["Make sure no postgres is running against the dir during init.","Avoid NFS/network filesystems for the data dir where rename semantics differ.","Remove half-applied .orig files from prior failed inits."],"tags":["postgresql","configuration","authentication","file-system","bsim","cli"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}