{"record":{"id":"fe3fd2eb57049c46","repo":"NationalSecurityAgency/ghidra","slug":"error-copying-original-configuration-file","errorCode":null,"errorMessage":"Error copying original configuration file","messagePattern":"Error copying original configuration file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java","lineNumber":921,"sourceCode":"\t\t\tcheckCertAuthorityFile();\n\t\t}\n\t\tcommand.add(\"-D\");\n\t\tcommand.add(dataDirectory.getAbsolutePath());\n\t\tint res = runCommand(null, command, loadLibraryVar, loadLibraryValue);\n\t\tif (res != 0) {\n\t\t\tthrow new IOException(\"Error initializing postgres database\");\n\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-","sourceCodeStart":903,"sourceCodeEnd":939,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java#L903-L939","documentation":"Thrown by initializeDataDirectory() when configFile.renameTo(configCopy) fails — i.e. postgresql.conf could not be moved to postgresql.conf.orig so BSim can write its tailored config. Java's renameTo fails across filesystems, on missing files, or on permission/lock issues.","triggerScenarios":"After a successful pg_ctl init, BSim moves postgresql.conf aside; the rename returns false and BSim aborts the whole initialization.","commonSituations":"Data directory on a filesystem where rename crosses mount boundaries; postgresql.conf held open/locked by another process; permissions changed between init and rename; antivirus/SAN/NFS rename semantics; the file was already moved by a previous interrupted run.","solutions":["Check filesystem permissions and ownership of postgresql.conf in the data directory.","Ensure the data directory is on a single local filesystem (avoid NFS rename pitfalls).","If a previous run left postgresql.conf.orig, restore the original layout before retrying.","Free any process holding the file open and retry the command."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight filesystem suitability for the rename BSim performs.\nFile conf = new File(dataDir, \"postgresql.conf\");\nFile copy = new File(dataDir, \"postgresql.conf.orig\");\nif (conf.exists() && copy.exists()) {\n    throw new IllegalStateException(\"Stale postgresql.conf.orig already present; clean up first\");\n}","typeGuard":"public boolean canAtomicallyRenameIn(File dir) {\n    return dir != null && dir.isDirectory()\n        && dir.toPath().getFileSystem().equals(dir.toPath().toAbsolutePath().getFileSystem());\n}","tryCatchPattern":"try {\n    bsimControl.start(args);\n} catch (IOException e) {\n    if (\"Error copying original configuration file\".equals(e.getMessage())) {\n        throw new UserFacingException(\"Cannot move postgresql.conf aside; check perms/fs\", e);\n    }\n    throw e;\n}","preventionTips":["Keep the BSim data directory on a single local filesystem.","Ensure the running user owns the data directory and its files.","Clean up .orig files from interrupted runs before retrying."],"tags":["postgresql","configuration","file-system","bsim","cli"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}