Skip to content

Commit 07b32a8

Browse files
Skryptclaude
andcommitted
Return 409 PathAlreadyExists when creating an existing directory via DFS
Azure ADLS Gen2 returns 409 when creating a directory that already exists. The SDK's CreateIfNotExistsAsync relies on this to return null/false for existing directories. Azurite was returning 201 regardless, causing CreateDirectory_AlreadyExists_ReturnsFalse to fail. Now checks if a directory blob with hdi_isfolder=true already exists before creating, and returns 409 PathAlreadyExists if so. File creates remain idempotent (overwrite) matching Azure behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fb2c8dc commit 07b32a8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/blob/dfs/handlers/PathHandler.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getDfsContext, IDfsContext } from "../DfsContext";
1111
import {
1212
sendDfsError,
1313
pathNotFound,
14+
pathAlreadyExists,
1415
filesystemNotFound,
1516
directoryNotEmpty,
1617
internalError,
@@ -53,6 +54,16 @@ export default class PathHandler {
5354
metadata[HNS_DIRECTORY_METADATA_KEY] = "true";
5455
}
5556

57+
// Azure returns 409 PathAlreadyExists when creating a directory that
58+
// already exists. This is required for the SDK's CreateIfNotExistsAsync
59+
// to correctly return null for existing directories.
60+
if (isDirectory) {
61+
const existing = await this.safeGetBlobProperties(account, filesystem, pathName);
62+
if (existing && existing.metadata?.[HNS_DIRECTORY_METADATA_KEY] === "true") {
63+
return sendDfsError(res, pathAlreadyExists(pathName));
64+
}
65+
}
66+
5667
// Ensure intermediate directories exist
5768
if (pathName.includes("/")) {
5869
await this.ensureIntermediateDirectories(account, filesystem, pathName, now);

0 commit comments

Comments
 (0)