{"record":{"id":"442fb775f34d420e","repo":"prestodb/presto","slug":"file-already-exists","errorCode":null,"errorMessage":"File already exists:","messagePattern":"File already exists:","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/s3/PrestoS3FileSystem.java","lineNumber":433,"sourceCode":"        }\n        return (length != null) ? Long.parseLong(length) : metadata.getContentLength();\n    }\n\n    @Override\n    public FSDataInputStream open(Path path, int bufferSize)\n    {\n        return new FSDataInputStream(\n                new BufferedFSInputStream(\n                        new PrestoS3InputStream(s3, getBucketName(uri), path, maxAttempts, maxBackoffTime, maxRetryTime),\n                        bufferSize));\n    }\n\n    @Override\n    public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress)\n            throws IOException\n    {\n        if ((!overwrite) && exists(path)) {\n            throw new IOException(\"File already exists:\" + path);\n        }\n\n        if (!stagingDirectory.exists()) {\n            createDirectories(stagingDirectory.toPath());\n        }\n        if (!stagingDirectory.isDirectory()) {\n            throw new IOException(\"Configured staging path is not a directory: \" + stagingDirectory);\n        }\n        File tempFile = createTempFile(stagingDirectory.toPath(), \"presto-s3-\", \".tmp\").toFile();\n\n        String key = keyFromPath(qualifiedPath(path));\n        return new FSDataOutputStream(\n                new PrestoS3OutputStream(s3,\n                        getBucketName(uri),\n                        key,\n                        tempFile,\n                        sseEnabled,\n                        sseType,","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/s3/PrestoS3FileSystem.java#L415-L451","documentation":"create(path, ..., overwrite=false) throws IOException if an object already exists at the target key. S3 has no atomic create-new semantics, so the connector explicitly checks exists(path) first and refuses to clobber without overwrite=true.","triggerScenarios":"Calling FileSystem.create with overwrite=false on a path that already has an object; two writers targeting the same key where the second uses overwrite=false.","commonSituations":"Job retries re-creating output files; Hive insert into an existing unpartitioned table location; concurrent tasks writing the same temp key; leftover files from a previous failed run.","solutions":["Pass overwrite=true if replacement is intended (matches 'INSERT OVERWRITE' semantics).","Delete the existing object first, or write to a unique temp key and rename.","Ensure downstream consumers clean up prior output before reruns.","Use unique staging keys (timestamp/uuid) per task attempt."],"exampleFix":"// before\nFSDataOutputStream out = fs.create(path, permission, false, bufferSize, replication, blockSize, progress);\n// after\nFSDataOutputStream out = fs.create(path, permission, true, bufferSize, replication, blockSize, progress);\n// or check first:\nif (fs.exists(path) && !allowOverwrite) throw new IllegalStateException(\"refusing to overwrite \" + path);","handlingStrategy":"try-catch","validationCode":"if (!overwrite && fs.exists(path)) {\n    throw new IllegalStateException(\"target exists; enable overwrite or pick a new key: \" + path);\n}","typeGuard":"null","tryCatchPattern":"try {\n    out = fs.create(path, permission, overwrite, bufferSize, replication, blockSize, progress);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"File already exists:\")) {\n        // use overwrite=true or write to a unique temp key\n    }\n    throw e;\n}","preventionTips":["Use unique staging keys per attempt (uuid/timestamp).","Clean up prior output before rerunning idempotent jobs.","Pass overwrite=true explicitly when clobbering is intended.","Avoid concurrent writers to the same key."],"tags":["s3","filesystem","io","overwrite-conflict"],"backgroundTag":"file-already-exists","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}