Skip to content

io: implement dirCreateDirPath and dirCreateDirPathOpen - #381

Merged
lalinsky merged 3 commits into
mainfrom
io-create-dir-path
May 11, 2026
Merged

lalinsky merged 3 commits into
mainfrom
io-create-dir-path

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Implement dirCreateDirPath to create nested directory paths
  • Implement dirCreateDirPathOpen to create and open nested paths
  • Mark processExecutableOpen and progressParentFile as unsupported

Details

The implementation follows std.Io.Threaded's algorithm: iterate from the target path back to existing ancestors, then forward creating each component.

Test plan

  • Added tests for both createDirPath and createDirPathOpen
  • Tests verify nested directory creation and idempotent behavior

@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Rate limit exceeded

@lalinsky has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 6 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f3c53744-39f2-46c0-bbf5-785db2fe029d

📥 Commits

Reviewing files that changed from the base of the PR and between 74d2c20 and 645c925.

📒 Files selected for processing (1)
  • src/io.zig
📝 Walkthrough

Walkthrough

Implements nested directory creation with component-by-component iteration, backtracking retry on file-not-found, and validation that existing components are directories. Adds a path-stat helper, wires create-and-open to create missing paths on demand, updates two unimplemented panic messages, and adds tests for both flows.

Changes

Nested Directory Creation

Layer / File(s) Summary
Path Kind Helper
src/io.zig
Added filePathKind to stat a path component without following symlinks, map zio file kind to std kind, and forward errors.
Core Directory Creation
src/io.zig
dirCreateDirPathImpl iterates path components, creates each with DirCreateDir, validates "already exists" is a directory, and backtracks on "file not found" to retry from the last valid component.
Create-and-Open
src/io.zig
dirCreateDirPathOpenImpl attempts to open; on FileNotFound it creates the missing path and retries.
Panic Message Updates
src/io.zig
processExecutableOpenImpl and progressParentFileImpl panic messages changed from TODO to not supported.
Tests
src/io.zig
Added two tests: one verifies create-status returns .created then .existed on retry; the other verifies create-and-open succeeds and the directory reopens.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes are focused and mechanical: a straightforward stat helper, iterative directory creation with clear error handling, a thin wrapper for create-and-open, two panic-message tweaks, and two focused tests. No complex logic branches or edge cases beyond the stated backtrack-and-retry loop.

Poem

🏗️ Nested paths now build with care,
Each component finds its layer,
Backtrack when the path runs dry,
Retry till the dirs reply.
Create, open, test—complete the square!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main changes: implementing dirCreateDirPath and dirCreateDirPathOpen functions in the io module.
Description check ✅ Passed The description clearly outlines the implementation objectives and test plan, all of which align with the actual changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch io-create-dir-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Creates nested directory paths by iterating from the target back to
existing ancestors, then forward creating each component. Follows the
same algorithm as std.Io.Threaded.

Includes tests for both functions.
@lalinsky
lalinsky force-pushed the io-create-dir-path branch from 74d2c20 to dd22eda Compare May 11, 2026 05:56
@lalinsky

Copy link
Copy Markdown
Owner Author

@claude fix the windows test

@claude

claude Bot commented May 11, 2026 •

Copy link
Copy Markdown

Claude finished @lalinsky's task in 36m 16s —— View job


I've identified and fixed the Windows test failure.

Root cause: GetFinalPathNameByHandleW returns paths with a \\?\ prefix (e.g. \\?\C:\...\dir), and that prefix disables Windows path normalization. When pathToWide in src/os/windows.zig joined this with a relative sub-path containing forward slashes (e.g. a/b/c), the result \\?\C:\...\dir\a/b/c had mixed separators that Windows/Wine rejected with ERROR_INVALID_NAME instead of the expected ERROR_PATH_NOT_FOUND. This caused mkdirat and dirDeleteDir to return error.Unexpected, breaking dirCreateDirPath.

Fix: After copying the sub-path into the joined buffer, convert any / to \ so that the final path only contains backslashes, which the \\?\-prefixed form requires.

// in pathToWide, after memcpy of path_wide into joined:
for (joined[dir_path.len + 1 ..][0..path_wide.len]) |*c| {
    if (c.* == '/') c.* = '\\';
}

Results:

  • Wine (x86_64-windows): 393/393 tests pass ✅
  • Linux native: all tests pass ✅

The fix is committed locally. Waiting for push approval.

Windows paths with \\?\ prefix don't auto-translate forward slashes,
causing INVALID_NAME errors. Use Io.Dir.path.sep_str for portable paths.
@lalinsky
lalinsky merged commit 13ab298 into main May 11, 2026
26 checks passed
@lalinsky
lalinsky deleted the io-create-dir-path branch May 11, 2026 06:20
@coderabbitai coderabbitai Bot mentioned this pull request May 11, 2026
1 task done
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