{"record":{"id":"0b086f7ac95f6d05","repo":"apache/dolphinscheduler","slug":"file-dstpath-already-exists","errorCode":null,"errorMessage":"file: ${dstPath} already exists","messagePattern":"file: (.+?) already exists","errorType":"exception","errorClass":"CosServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java","lineNumber":192,"sourceCode":"        String srcCosKey = transformAbsolutePathToCOSKey(srcPath);\n        String destCosKey = transformAbsolutePathToCOSKey(dstPath);\n        CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucketName, srcCosKey, bucketName, destCosKey);\n        Copy copy = cosTransferManager.copy(copyObjectRequest, cosClient, null);\n\n        CopyResult copyResult = copy.waitForCopyResult();\n        if (copyResult != null && deleteSource) {\n            cosClient.deleteObject(bucketName, srcPath);\n        }\n    }\n\n    @SneakyThrows\n    @Override\n    public void upload(String srcFile, String dstPath, boolean deleteSource, boolean overwrite) {\n        dstPath = transformAbsolutePathToCOSKey(dstPath);\n\n        if (cosClient.doesObjectExist(bucketName, dstPath)) {\n            if (!overwrite) {\n                throw new CosServiceException(\"file: \" + dstPath + \" already exists\");\n            } else {\n                cosClient.deleteObject(bucketName, dstPath);\n            }\n        }\n\n        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, dstPath, new File(srcFile));\n        Upload upload = cosTransferManager.upload(putObjectRequest);\n        UploadResult uploadResult = upload.waitForUploadResult();\n        if (uploadResult != null && 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        String cosKey = transformAbsolutePathToCOSKey(filePath);\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-storage-plugin/dolphinscheduler-storage-cos/src/main/java/org/apache/dolphinscheduler/plugin/storage/cos/CosStorageOperator.java#L174-L210","documentation":"CosStorageOperator.upload throws CosServiceException when the target COS key already exists and overwrite=false. The check is done with cosClient.doesObjectExist before uploading. With overwrite=true the existing object is deleted and replaced instead.","triggerScenarios":"Calling upload(srcFile, dstPath, deleteSource, false) when an object already exists at the transformed dstPath key.","commonSituations":"Re-deploying resources without enabling overwrite; two workflows concurrently uploading to the same resource key; key collision after a path rename in COS.","solutions":["Pass overwrite=true to replace the existing object","Delete or rename the existing object first","Upload to a versioned/unique key if the old object must be preserved"],"exampleFix":"// before\noperator.upload(localFile, resourceKey, false, false);\n// after\noperator.upload(localFile, resourceKey, false, true); // allow replace","handlingStrategy":"try-catch","validationCode":"if (!overwrite && operator.exists(dstKey)) { /* rename dst or ask user */ }","typeGuard":null,"tryCatchPattern":"try {\n    operator.upload(src, dst, deleteSource, overwrite);\n} catch (CosServiceException e) {\n    if (e.getMessage().contains(\"already exists\")) {\n        operator.upload(src, dst, deleteSource, true); // retry with overwrite\n    } else throw e;\n}","preventionTips":["Decide overwrite policy explicitly on every upload call","Use versioned keys when old objects must survive re-uploads","Serialize concurrent uploads to the same key via locks or unique names"],"tags":["storage","cos","duplicate-resource"],"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"}