{"record":{"id":"2ba1df9f2f6f978d","repo":"apache/dolphinscheduler","slug":"directory-directory-already-exists","errorCode":null,"errorMessage":"directory: ${directory} already exists","messagePattern":"directory: (.+?) already exists","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"warning","filePath":"dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java","lineNumber":128,"sourceCode":"            log.warn(\"{} -> {} should not start with / in Oss\", StorageConstants.RESOURCE_UPLOAD_PATH,\n                    resourceBaseAbsolutePath);\n            return resourceBaseAbsolutePath.substring(1);\n        }\n        return resourceBaseAbsolutePath;\n    }\n\n    @Override\n    public void close() throws IOException {\n        ossClient.shutdown();\n    }\n\n    @SneakyThrows\n    @Override\n    public void createStorageDir(String directory) {\n        directory = transformAbsolutePathToOssKey(directory);\n\n        if (ossClient.doesObjectExist(bucketName, directory)) {\n            throw new FileAlreadyExistsException(\"directory: \" + directory + \" already exists\");\n        }\n        ObjectMetadata metadata = new ObjectMetadata();\n        metadata.setContentLength(0);\n        InputStream emptyContent = new ByteArrayInputStream(new byte[0]);\n        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, directory, emptyContent, metadata);\n        ossClient.putObject(putObjectRequest);\n    }\n\n    @SneakyThrows\n    @Override\n    public void download(String srcFilePath,\n                         String dstFilePath,\n                         boolean overwrite) {\n        srcFilePath = transformAbsolutePathToOssKey(srcFilePath);\n\n        File dstFile = new File(dstFilePath);\n        if (dstFile.isDirectory()) {\n            Files.delete(dstFile.toPath());","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java#L110-L146","documentation":"OssStorageOperator.createStorageDir throws FileAlreadyExistsException when an object already exists at the transformed OSS key. OSS directories are zero-length placeholder objects, so an existing marker blocks re-creating the directory.","triggerScenarios":"Calling createStorageDir(directory) when the OSS bucket already contains an object at transformAbsolutePathToOssKey(directory).","commonSituations":"Re-running a setup/workflow that creates the same resource directory; concurrent task instances creating the same directory; a file was uploaded to the same key previously.","solutions":["Check directory existence first (existsStorageDir) or delete the object before creating","Catch FileAlreadyExistsException and treat as no-op for idempotent scripts","Use unique directory names per execution"],"exampleFix":"// before\nstorageOperator.createStorageDir(dir);\n// after\ntry {\n    storageOperator.createStorageDir(dir);\n} catch (FileAlreadyExistsException e) {\n    // directory already present — safe to ignore\n}","handlingStrategy":"validation","validationCode":"if (!storageOperator.existsStorageDir(directory)) {\n    storageOperator.createStorageDir(directory);\n}","typeGuard":null,"tryCatchPattern":"try {\n    storageOperator.createStorageDir(directory);\n} catch (FileAlreadyExistsException e) {\n    log.info(\"Directory {} already exists, ignoring\", directory);\n}","preventionTips":["Idempotent create: check-then-create or catch-and-ignore","Use per-run unique directory names","Avoid file uploads to keys you later use as directories"],"tags":["storage","oss","file-already-exists","idempotency"],"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-14T00:17:10.932Z"}