Skip to content

host_env: Simplify stat, fstatat with Rustix - #8455

Open
joshuamegnauth54 wants to merge 1 commit into
RustPython:mainfrom
joshuamegnauth54:host_env-simplify-fstatat
Open

host_env: Simplify stat, fstatat with Rustix#8455
joshuamegnauth54 wants to merge 1 commit into
RustPython:mainfrom
joshuamegnauth54:host_env-simplify-fstatat

Conversation

@joshuamegnauth54

@joshuamegnauth54 joshuamegnauth54 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

According to POSIX, time_t should be 64 bits. musl changed its time_t to an i64 over five years ago. glibc provides compatibility features that declare time_t as either i32 or i64. Rustix uses the raw Linux syscall for stat which returns an i64. For our purposes, an i64 makes sense because it's modern and avoids the year 2038 problem. It also reduces our dependency on what libc defines.

Sources:

Summary

Summary by CodeRabbit

  • Bug Fixes

    • Improved file and directory metadata handling across Unix-like platforms.
    • Preserved accurate directory detection and symbolic-link behavior.
    • Improved error handling for file status operations.
    • Standardized timestamp and filesystem block metadata for more reliable results.
  • Refactor

    • Unified filesystem status operations across supported Unix-like environments.
    • Improved compatibility across Unix-like and WASI platforms while preserving Windows behavior.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: b52aead3-702d-4304-b5fa-87220018cf62

📥 Commits

Reviewing files that changed from the base of the PR and between 1c7759c and 29ee814.

📒 Files selected for processing (6)
  • crates/host_env/src/fileutils.rs
  • crates/host_env/src/io.rs
  • crates/host_env/src/posix.rs
  • crates/host_env/src/posix_unix_like.rs
  • crates/host_env/src/posix_wasi.rs
  • crates/vm/src/stdlib/os.rs
💤 Files with no reviewable changes (2)
  • crates/host_env/src/posix_wasi.rs
  • crates/host_env/src/posix.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/host_env/src/fileutils.rs
  • crates/vm/src/stdlib/os.rs
  • crates/host_env/src/io.rs

📝 Walkthrough

Walkthrough

The change replaces non-Windows libc stat operations with Rustix, moves stat_path to the Unix-like implementation, updates VM path-stat wiring, and normalizes timestamp and filesystem block fields.

Changes

Filesystem stat migration

Layer / File(s) Summary
Rustix stat primitives
crates/host_env/src/fileutils.rs, crates/host_env/src/io.rs
Non-Windows stat structures, file descriptor stat calls, directory detection, and ISDIR errors now use Rustix.
Path stat implementation and wiring
crates/host_env/src/posix_unix_like.rs, crates/host_env/src/posix.rs, crates/host_env/src/posix_wasi.rs, crates/vm/src/stdlib/os.rs
Unix-like stat_path now uses Rustix statat. The previous platform implementations are removed. stat_inner passes OsPath directly and uses DirFd::get_opt().
Stat result normalization
crates/vm/src/stdlib/os.rs
Timestamp fields use i64. Filesystem block fields use u64. NetBSD uses the shared timestamp extraction path. Block conversions use fallback values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: youknowone

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: simplifying stat and fstatat handling in host_env with Rustix.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@joshuamegnauth54
joshuamegnauth54 marked this pull request as ready for review August 5, 2026 02:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/host_env/src/fileutils.rs`:
- Line 5: Update the NetBSD branch in the OS stdlib implementation to access
StatStruct fields st_atime_nsec, st_mtime_nsec, and st_ctime_nsec, replacing the
legacy st_atimensec, st_mtimensec, and st_ctimensec names while preserving the
existing timestamp behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 30728473-f83e-44b2-88e7-d046b6050213

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa76a3 and b08a96b.

📒 Files selected for processing (6)
  • crates/host_env/src/fileutils.rs
  • crates/host_env/src/io.rs
  • crates/host_env/src/posix.rs
  • crates/host_env/src/posix_unix_like.rs
  • crates/host_env/src/posix_wasi.rs
  • crates/vm/src/stdlib/os.rs
💤 Files with no reviewable changes (2)
  • crates/host_env/src/posix_wasi.rs
  • crates/host_env/src/posix.rs

Comment thread crates/host_env/src/fileutils.rs
@joshuamegnauth54
joshuamegnauth54 marked this pull request as draft August 5, 2026 02:46

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as always, great finding!

ty<3

@joshuamegnauth54
joshuamegnauth54 force-pushed the host_env-simplify-fstatat branch from b08a96b to 1c5a481 Compare August 6, 2026 02:44
@joshuamegnauth54
joshuamegnauth54 marked this pull request as ready for review August 6, 2026 19:00
@joshuamegnauth54
joshuamegnauth54 force-pushed the host_env-simplify-fstatat branch from 1c5a481 to 71d5994 Compare August 6, 2026 19:00
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/vm/src/stdlib/os.rs`:
- Around line 1237-1243: Fix the conditional compilation around the timestamp
assignments in the enclosing function by making the NetBSD condition consistent
across both adjacent cfg attributes. Remove NetBSD from the exclusion in the
second cfg so atime, mtime, and ctime are assigned for NetBSD while retaining
the existing WASI exclusion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5da13ae1-5f7a-4177-8be0-3eaf2ee864fc

📥 Commits

Reviewing files that changed from the base of the PR and between 1c7759c and 71d5994.

📒 Files selected for processing (6)
  • crates/host_env/src/fileutils.rs
  • crates/host_env/src/io.rs
  • crates/host_env/src/posix.rs
  • crates/host_env/src/posix_unix_like.rs
  • crates/host_env/src/posix_wasi.rs
  • crates/vm/src/stdlib/os.rs
💤 Files with no reviewable changes (2)
  • crates/host_env/src/posix.rs
  • crates/host_env/src/posix_wasi.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/host_env/src/posix_unix_like.rs
  • crates/host_env/src/fileutils.rs
  • crates/host_env/src/io.rs

Comment thread crates/vm/src/stdlib/os.rs Outdated
@joshuamegnauth54
joshuamegnauth54 force-pushed the host_env-simplify-fstatat branch from 71d5994 to 62419ec Compare August 6, 2026 19:10
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

According to POSIX, `time_t` should be 64 bits. `musl` changed its
`time_t` to an `i64` over five years ago. `glibc` provides compatibility
features that declare `time_t` as either `i32` or `i64`. Rustix uses the
raw Linux syscall for stat which returns an `i64`. For our purposes, an
`i64` makes sense because it's modern and avoids the year 2038 problem.
It also reduces our dependency on what `libc` defines.

Sources:
* https://www.man7.org/linux/man-pages/man3/time_t.3type.html
* https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html
@joshuamegnauth54
joshuamegnauth54 force-pushed the host_env-simplify-fstatat branch from 62419ec to 29ee814 Compare August 7, 2026 02:52
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@joshuamegnauth54

Copy link
Copy Markdown
Contributor Author

Cargo shear failed randomly. 🤔

@fanninpm

fanninpm commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Cargo shear failed randomly. 🤔

@ShaharNaveh

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.

3 participants