Repository navigation
Implement fileStat, dirStat, and dirStatPath operations - #162
Conversation
Add support for file and directory stat operations in the std.Io interface: - Implement File.stat() to get metadata of an open file - Implement Dir.stat() to get metadata of an open directory - Implement Dir.statPath() to get metadata at a relative path These operations use the aio FileStat async operation and convert between aio's FileStatInfo and std.Io's File.Stat format. All three operations include comprehensive tests verifying file size, kind, and timestamps.
WalkthroughAdded stat operation methods to Dir and File structures enabling async metadata queries via FileStat. Integrated stdio support with aioFileStatToStdIo helper for converting aio stat results to standard Io.File.Stat format, including error translation and new test coverage. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (1)**/*.zig📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (2)📚 Learning: 2025-11-30T10:31:31.222ZApplied to files:
📚 Learning: 2025-10-10T05:59:17.087ZApplied to files:
🔇 Additional comments (8)
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. Comment |
Use statPath with "." instead of calling stat() directly on the cwd() handle, since cwd() returns a special handle (AT_FDCWD on POSIX, PEB handle on Windows) that doesn't support fstat on all platforms.
Windows doesn't handle statting "." correctly through the path conversion. Changed the test to create an actual temporary directory using std.fs.cwd().makeDir() and then stat that directory via statPath().
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
* Implement fileStat, dirStat, and dirStatPath operations Add support for file and directory stat operations in the std.Io interface: - Implement File.stat() to get metadata of an open file - Implement Dir.stat() to get metadata of an open directory - Implement Dir.statPath() to get metadata at a relative path These operations use the aio FileStat async operation and convert between aio's FileStatInfo and std.Io's File.Stat format. All three operations include comprehensive tests verifying file size, kind, and timestamps. * Fix Dir stat test for macOS and Windows Use statPath with "." instead of calling stat() directly on the cwd() handle, since cwd() returns a special handle (AT_FDCWD on POSIX, PEB handle on Windows) that doesn't support fstat on all platforms. * Fix Windows CI: create real directory for Dir stat test Windows doesn't handle statting "." correctly through the path conversion. Changed the test to create an actual temporary directory using std.fs.cwd().makeDir() and then stat that directory via statPath().
Summary
File.stat()to get metadata of an open fileDir.stat()to get metadata of an open directoryDir.statPath()to get metadata at a relative pathThese operations were previously unimplemented (marked as
@panic("TODO")).Implementation Details
FileStatasync operationaioFileStatToStdIo()to convert between aio'sFileStatInfoand std.Io'sFile.Stati64nanoseconds for timestamps, std.Io usesIo.Timestamp { nanoseconds: i96 }fileStatanddirStatcallfstat()on file descriptordirStatPathcallsfstatat()with directory fd and relative pathTest plan
File.stat()- verifies file size, kind, and timestampsDir.stat()- verifies directory kind and timestampsDir.statPath()- verifies stat via relative pathFiles Changed
src/fs/file.zig- Addedstat()method to File structsrc/fs/dir.zig- Addedstat()andstatPath()methods to Dir structsrc/stdio.zig- Implemented vtable functions and added tests