{"record":{"id":"a7fa7fadeab9d1f5","repo":"apache/dolphinscheduler","slug":"directory-directoryabsolutepath-already-exists","errorCode":null,"errorMessage":"directory: ${directoryAbsolutePath} already exists","messagePattern":"directory: (.+?) already exists","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-storage-plugin/dolphinscheduler-storage-gcs/src/main/java/org/apache/dolphinscheduler/plugin/storage/gcs/GcsStorageOperator.java","lineNumber":100,"sourceCode":"    }\n\n    @Override\n    public String getStorageBaseDirectory() {\n        // All directory should end with File.separator\n        if (resourceBaseAbsolutePath.startsWith(\"/\")) {\n            log.warn(\"{} -> {} should not start with / in Gcs\", StorageConstants.RESOURCE_UPLOAD_PATH,\n                    resourceBaseAbsolutePath);\n            return resourceBaseAbsolutePath.substring(1);\n        }\n        return getStorageBaseDirectory();\n    }\n\n    @SneakyThrows\n    @Override\n    public void createStorageDir(String directoryAbsolutePath) {\n        directoryAbsolutePath = transformAbsolutePathToGcsKey(directoryAbsolutePath);\n        if (exists(directoryAbsolutePath)) {\n            throw new FileAlreadyExistsException(\"directory: \" + directoryAbsolutePath + \" already exists\");\n        }\n        BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, directoryAbsolutePath)).build();\n        gcsStorage.create(blobInfo, EMPTY_STRING.getBytes(StandardCharsets.UTF_8));\n    }\n\n    @SneakyThrows\n    @Override\n    public void download(String srcFilePath, String dstFilePath, boolean overwrite) {\n        srcFilePath = transformAbsolutePathToGcsKey(srcFilePath);\n\n        File dstFile = new File(dstFilePath);\n        if (dstFile.isDirectory()) {\n            Files.delete(dstFile.toPath());\n        } else {\n            FileUtils.createDirectoryWithPermission(dstFile.getParentFile().toPath(), FileUtils.PERMISSION_755);\n        }\n\n        Blob blob = gcsStorage.get(BlobId.of(bucketName, srcFilePath));","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-storage-plugin/dolphinscheduler-storage-gcs/src/main/java/org/apache/dolphinscheduler/plugin/storage/gcs/GcsStorageOperator.java#L82-L118","documentation":"GcsStorageOperator.createStorageDir creates a GCS 'directory' by writing an empty blob at the transformed key. If a blob already exists at that key it throws FileAlreadyExistsException rather than overwriting, since GCS directories are only prefix conventions.","triggerScenarios":"Calling createStorageDir(directoryAbsolutePath) when exists(directoryAbsolutePath) finds an existing blob at the GCS key — from a previous mkdir, a file uploaded to the same path, or a leftover marker blob.","commonSituations":"Re-running workflows that recreate the same resource directory; an uploaded file occupying the directory key; stale blobs after resource reorganization.","solutions":["Check exists() first and skip creation if it returns true","Delete the existing blob via gcsStorage/Blob.delete if overwrite is safe, then retry","Use a unique directory path (tenant/timestamp scoped)"],"exampleFix":"// before\ngcs.createStorageDir(dirPath);\n// after\nif (!gcs.exists(dirPath)) {\n    gcs.createStorageDir(dirPath);\n}","handlingStrategy":"validation","validationCode":"if (gcs.exists(gcsKey)) { /* skip or pick another directory */ }","typeGuard":null,"tryCatchPattern":"try {\n    gcs.createStorageDir(dir);\n} catch (FileAlreadyExistsException e) {\n    log.info(\"GCS directory already exists, reusing: {}\", dir);\n}","preventionTips":["Guard creation with exists()","Use per-execution unique directory paths","Recall that GCS 'directories' are empty blobs at key boundaries"],"tags":["storage","gcs","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"}