Skip to content

Return an error when fs.create_dir finds a regular file - #33

Open
Faizaanp wants to merge 1 commit into
puddi-lang:mainfrom
Faizaanp:fix/issue-19-create-dir-file
Open

Faizaanp wants to merge 1 commit into
puddi-lang:mainfrom
Faizaanp:fix/issue-19-create-dir-file

Conversation

@Faizaanp

@Faizaanp Faizaanp commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

std.fs.create_dir on the WASI target silently returned Ok when the path was already a regular file: the embedded platform treated every successful stat as a directory component. __fs_mkdir now rejects non-directory components, returning an IoErr as the Node host does, while still succeeding for existing directories and newly created components.

What changed

  • src/platform_wasi.pud - in __fs_mkdir, each existing component descriptor type is checked. A non-directory component returns Err(__io_err(NotDirectory)), mapped to IoErr.Other through the existing "CODE\0message" convention. Existing directories and newly created components are unchanged.
  • tests/run.rs - added create_dir_rejects_file_component, a temp-dir regression test that writes a regular file and asserts an error for that file and for a path with that file as a parent component, plus success for a new directory created twice.
  • CHANGELOG.md - Unreleased/Fixed entry referencing Return an error when fs.create_dir finds a regular file #19.

How verified

Reproduction program (temp repro.pud: write file f, then fs.create_dir on f, f/sub, a fresh dir and an existing dir), run with the embedded WASI runtime via pud run repro.pud:

Before (unmodified source):

create_dir existing file (f): Ok
create_dir file component (f/sub): Err(NotDirectory)
create_dir fresh dir (d2): Ok
create_dir existing dir (d): Ok

After (fixed source):

create_dir existing file (f): Err(NotDirectory)
create_dir file component (f/sub): Err(NotDirectory)
create_dir fresh dir (d2): Ok
create_dir existing dir (d): Ok

Focused regression test:

cargo test -j 1 create_dir_rejects_file_component -- --nocapture
test create_dir_rejects_file_component ... ok
test result: ok. 1 passed; 0 failed

Wider suite (debug profile; release with Wasmtime was prohibitively slow here):

cargo test -j 1 -- --skip conformance_suite
unit tests: 3 passed; 0 failed
tests/run.rs: 6 passed; 0 failed (including create_dir_rejects_file_component)
conformance_suite: skipped as requested

Fixes #19

@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: medium ghfind author score; see https://ghfind.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return an error when fs.create_dir finds a regular file

1 participant