Skip to content

fs: reject existing files in MkdirAll - #7933

Open
myangitzh wants to merge 1 commit into
mainfrom
fix/mkdirall-existing-file
Open

myangitzh wants to merge 1 commit into
mainfrom
fix/mkdirall-existing-file

Conversation

@myangitzh

Copy link
Copy Markdown
Contributor

Problem

pkg/fs.MkdirAll0 treated every EEXIST from Mkdir as success when existOK was true. EEXIST also occurs when a regular file occupies the target path. The call reported success while the file remained in place. A caller that then tried to create a child under that path got ENOTDIR later.

The Python SDK's Client.makedirs(path, exist_ok=True) forwards the flag through libjfs and returned normally in this case. For example, after creating /file as a regular file, client.makedirs("/file", exist_ok=True) appeared to create or confirm a directory. The SDK now raises OSError with errno.ENOTDIR at the makedirs call.

Change

On EEXIST with existOK=true, look up the original path with Stat and accept it if it resolves to a directory. Return ENOTDIR for a non-directory and propagate lookup failures such as EACCES. If the lookup returns ENOENT, keep the creation error EEXIST, as with a dangling symlink. Update the Python SDK docstring to describe the error.

Validation

Ran the Python SDK against separate libjfs builds from before and after the fix on macOS arm64 with Python 3.14, SQLite metadata and local file storage. /file was a regular file, /dir was a directory and /link pointed to /file.

Python SDK call Before After
makedirs('/file', exist_ok=True) Returned normally OSError, errno.ENOTDIR
makedirs('/file/', exist_ok=True) Returned normally OSError, errno.ENOTDIR
makedirs('/link', exist_ok=True) Returned normally OSError, errno.ENOTDIR
makedirs('/dir', exist_ok=True) Returned normally Returned normally
makedirs('/file/child', exist_ok=True) OSError, errno.ENOTDIR OSError, errno.ENOTDIR
makedirs('/file') or makedirs('/dir') with the default exist_ok=False OSError, errno.EEXIST OSError, errno.EEXIST

Both builds left /file as a regular file with its original contents.

  • The new TestLastComponent cases failed before the fix and passed after it. They also cover directory symlinks, dangling symlinks and lookup permission errors.
  • go test ./pkg/fs ./pkg/gateway ./pkg/sync ./sdk/go -count=1 passed.
  • make test.pkg could not complete locally because the Gluster build requires pkg-config.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant