{"record":{"id":"05abc6546f35a55e","repo":"apache/dolphinscheduler","slug":"the-file-dstpath-already-exists-in-the-bucket","errorCode":null,"errorMessage":"The file ${dstPath} already exists in the bucket ${bucketName} and overwrite is not allowed.","messagePattern":"The file (.+?) already exists in the bucket (.+?) and overwrite is not allowed\\.","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-storage-plugin/dolphinscheduler-storage-s3/src/main/java/org/apache/dolphinscheduler/plugin/storage/s3/S3StorageOperator.java","lineNumber":182,"sourceCode":"        if (resourceMetaData.isDirectory()) {\n            throw new UnsupportedOperationException(\"S3 does not support copying directories.\");\n        }\n        s3Client.copyObject(bucketName, srcPath, bucketName, dstPath);\n        if (deleteSource) {\n            s3Client.deleteObject(bucketName, srcPath);\n        }\n    }\n\n    @SneakyThrows\n    @Override\n    public void upload(String srcFile, String dstPath, boolean deleteSource, boolean overwrite) {\n        dstPath = transformAbsolutePathToS3Key(dstPath);\n\n        if (s3Client.doesObjectExist(bucketName, dstPath)) {\n            if (overwrite) {\n                s3Client.deleteObject(bucketName, dstPath);\n            } else {\n                throw new FileAlreadyExistsException(\"The file \" + dstPath + \" already exists in the bucket \"\n                        + bucketName + \" and overwrite is not allowed.\");\n            }\n        }\n\n        s3Client.putObject(bucketName, dstPath, new File(srcFile));\n\n        if (deleteSource) {\n            Files.delete(Paths.get(srcFile));\n        }\n    }\n\n    @SneakyThrows\n    @Override\n    public List<String> fetchFileContent(String filePath, int skipLineNums, int limit) {\n        filePath = transformAbsolutePathToS3Key(filePath);\n        S3Object s3Object = s3Client.getObject(bucketName, filePath);\n        try (\n                InputStreamReader inputStreamReader = new InputStreamReader(s3Object.getObjectContent());","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-storage-plugin/dolphinscheduler-storage-s3/src/main/java/org/apache/dolphinscheduler/plugin/storage/s3/S3StorageOperator.java#L164-L200","documentation":"S3StorageOperator.upload refuses to write srcFile to the S3 key dstPath when an object already exists at that key and the overwrite flag is false. Before copying, it checks doesObjectExist; only when overwrite=true does it delete the existing object and proceed. This is a safety guard against silently clobbering stored resources.","triggerScenarios":"Calling upload(srcFile, dstPath, false) (or an upload API without overwrite enabled) while the resolved S3 key already holds an object in bucketName. Happens on re-running a workflow/task that uploads to the same resource path.","commonSituations":"Re-uploading a resource file with the same name; user scripts that regenerate the same resource path; migrating resources into a bucket that already contains the target key; forgetting to set resource.upload.overwrite or pass overwrite=true.","solutions":["Set the overwrite flag to true when re-uploads to the same path are intentional","Delete the existing object first (or use a new unique dstPath) before uploading","Use a versioned/unique destination path (e.g. timestamp suffix) to avoid collisions"],"exampleFix":"// before\nstorageOperator.upload(srcFile, dstPath, false);\n// after\nstorageOperator.upload(srcFile, dstPath, true); // intentional overwrite","handlingStrategy":"validation","validationCode":"if (storageOperator.exists(dstPath) && !overwrite) {\n    throw new IllegalStateException(\"Destination exists, choose overwrite or a new path: \" + dstPath);\n}\nstorageOperator.upload(srcFile, dstPath, overwrite);","typeGuard":null,"tryCatchPattern":"try {\n    storageOperator.upload(srcFile, dstPath, false);\n} catch (FileAlreadyExistsException e) {\n    log.warn(\"Target exists: {}\", e.getMessage()); // choose new path or overwrite\n}","preventionTips":["Check existence (exists(dstPath)) before uploading when overwrite is off","Use unique, content-derived or timestamped destination keys","Decide and centralize the overwrite policy in one helper instead of ad-hoc calls"],"tags":["s3","file-already-exists","storage","upload"],"backgroundTag":"file-already-exists","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}