Skip to content

Release v1.0.0: match std file-lock API, fix platform bugs - #48

Merged
al8n merged 8 commits into
mainfrom
1.0.0
Apr 22, 2026
Merged

al8n merged 8 commits into
mainfrom
1.0.0

Conversation

@al8n

@al8n al8n commented Apr 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Prepares the 1.0.0 release. The headline change is aligning fs4's file-lock API with the signatures that shipped in std::fs::File on stable Rust 1.89+ — 0.13.x tracked the nightly shape, which then changed before stabilization. Also fixes a handful of long-standing platform bugs and several latent feature-gate typos that prevented the crate from compiling with some feature combinations.

Breaking changes

  • Rename FileExt::lock_exclusive → lock, try_lock_exclusive → try_lock (both traits, sync + async). Mirrors std::fs::File::lock / try_lock.
  • Change try_lock / try_lock_shared return type from std::io::Result<bool> to Result<(), TryLockError>. Err(TryLockError::WouldBlock) now indicates a contended lock.
  • Introduce fs4::TryLockError { Error(io::Error), WouldBlock }, mirroring std::fs::TryLockError. Includes Display, std::error::Error, From<io::Error>, and From<TryLockError> for io::Error.
  • Flatten the fs_std module: FileExt for std::fs::File now lives at the crate root. Migration: use fs4::fs_std::FileExt; → use fs4::FileExt;. All other backends (fs_err2, fs_err3, tokio, smol, async_std, fs_err2_tokio, fs_err3_tokio) remain nested.
  • Remove lock_contended_error() — use TryLockError::WouldBlock instead.

Issue fixes

Latent compile bugs fixed

  • Feature typo: #[cfg(feature = "fs-err")] in unix.rs / windows.rs — a feature that doesn't exist. Now any(feature = "fs-err2", feature = "fs-err3"). --no-default-features --features fs-err2 / fs-err3 now build.
  • Feature typo: feature = "fs-err-tokio" in cfg_async! / unix.rs / windows.rs. Now any(feature = "fs-err2-tokio", feature = "fs-err3-tokio"). --no-default-features --features fs-err2-tokio / fs-err3-tokio now build.
  • async_impl / sync_impl consistency: AIX moved to the set_len fallback branch in async to match sync; redox and cygwin added to both branches.
  • lock_impl! macro gated with #[allow(unused_macros)] so cargo clippy --no-default-features (filesystem-stats-only build) doesn't fail on -D warnings.

Testing

  • Remove all #[bench] functions from the test harness — they measured OS syscalls (flock, LockFileEx, fallocate, statvfs), not fs4 code. Drops the #![cfg_attr(test, feature(test))] requirement and lets the project build and test on stable Rust; rust-toolchain.toml switched from nightly to stable.
  • Added regression tests: allocate_preserves_eof_within_cluster (8 instances, covers file.metadata()?.len() < len in allocation code on Windows is problematic #13), allocate_idempotent (8 instances, covers Allocation on macOS is not working, while it does with fs2 #15), seven TryLockError unit tests (variants, From/Into, Display, source), and fs_stats getter + derive tests (previously uncovered by any test).
  • Fixed a long-standing test bug: assert!(available_space <= free_space) — the POSIX invariant doesn't hold on macOS APFS (purgeable space counts as available but not free). Also made the async filesystem_space test atomic (one statvfs + destructure instead of three separate calls racing against other tests).

Dependencies / tooling

  • Bumped windows-sys from 0.59 to 0.61.
  • Updated html_root_url and all README fs4 = { version = "0.13", ... } snippets to "1".
  • CI: added MinGW install step for *-pc-windows-gnu cross-compile targets (windows-sys 0.61 invokes dlltool during build, and ubuntu-latest ships only the x86_64 MinGW toolchain by default).
  • New .github/workflows/coverage.yml — per-OS matrix (linux / macos / windows) uploading to Codecov with per-OS flags, using cargo tarpaulin --engine llvm.

Migration guide

// Before (0.13.x)
use fs4::fs_std::FileExt;
match file.try_lock_exclusive()? {
    true  => { /* acquired */ }
    false => { /* contended */ }
}
file.lock_exclusive()?;

// After (1.0.0)
use fs4::{FileExt, TryLockError};
match file.try_lock() {
    Ok(())                          => { /* acquired */ }
    Err(TryLockError::WouldBlock)   => { /* contended */ }
    Err(TryLockError::Error(e))     => return Err(e),
}
file.lock()?;

Full details in CHANGELOG.md.

Test plan

  • cargo test --all-features -- --test-threads 1 — all 73 tests pass on macOS + Linux
  • cargo hack clippy --each-feature — clean across all 11 feature sets
  • cargo hack build --each-feature — clean
  • cargo check --target x86_64-pc-windows-msvc --all-features --tests — cross-compile clean
  • MSRV (cargo check on 1.75.0) — clean
  • CI matrix green (ubuntu / macos / windows, all cross targets)
  • Coverage workflow green on all three runners

@codecov

codecov Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.34524% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.37%. Comparing base (511e2d2) to head (8f7d397).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/windows.rs 90.41% 7 Missing ⚠️
src/lib.rs 40.00% 3 Missing ⚠️
src/windows/async_impl.rs 91.66% 3 Missing ⚠️
src/windows/sync_impl.rs 92.30% 3 Missing ⚠️
src/unix.rs 96.42% 1 Missing ⚠️
src/unix/async_impl.rs 90.90% 1 Missing ⚠️
src/unix/sync_impl.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #48       +/-   ##
===========================================
+ Coverage   84.53%   96.37%   +11.83%     
===========================================
  Files           7       11        +4     
  Lines         388      662      +274     
===========================================
+ Hits          328      638      +310     
+ Misses         60       24       -36     
Files with missing lines Coverage Δ
src/file_ext/async_impl.rs 98.66% <100.00%> (+0.75%) ⬆️
src/file_ext/sync_impl.rs 100.00% <100.00%> (ø)
src/fs_stats.rs 100.00% <100.00%> (+100.00%) ⬆️
src/try_lock_error.rs 100.00% <100.00%> (ø)
src/unix.rs 96.55% <96.42%> (+14.19%) ⬆️
src/unix/async_impl.rs 96.77% <90.90%> (+1.12%) ⬆️
src/unix/sync_impl.rs 96.66% <91.66%> (+2.22%) ⬆️
src/lib.rs 40.00% <40.00%> (-7.50%) ⬇️
src/windows/async_impl.rs 96.34% <91.66%> (ø)
src/windows/sync_impl.rs 96.29% <92.30%> (ø)
... and 1 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4732891...8f7d397. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@al8n
al8n requested a review from Copilot April 22, 2026 04:03
@al8n al8n changed the title fix issues Release v1.0.0: match std file-lock API, fix platform bugs Apr 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR prepares a 1.0.0 release of fs4 by aligning the lock APIs with stabilized std::fs::File semantics, fixing platform-specific allocation quirks, and updating project tooling/CI to run on stable Rust with improved coverage reporting.

Changes:

  • Introduces TryLockError and updates try_lock* APIs to return Result<(), TryLockError>; renames exclusive locking to lock(), and flattens the std FileExt export to the crate root.
  • Adjusts allocate() behavior on Windows (avoid moving EOF when allocation already covers len) and Unix/macOS (short-circuit to avoid reallocation ENOSPC), with new regression tests.
  • Updates tooling and automation: stable toolchain, rustfmt config, expanded CI matrix, and new coverage/LoC workflows.

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tea.yaml Removes tea.xyz metadata file.
src/windows/sync_impl/std_impl.rs Updates test imports to use crate-root FileExt.
src/windows/sync_impl.rs Windows sync allocation short-circuit + lock API test updates.
src/windows/async_impl.rs Windows async allocation short-circuit + lock API test updates.
src/windows.rs Updates Windows lock implementation API + feature gating for new feature names.
src/unix/sync_impl/std_impl.rs Updates test imports to use crate-root FileExt.
src/unix/sync_impl.rs Unix sync allocation short-circuit, adds targets, updates lock API tests.
src/unix/async_impl.rs Unix async allocation short-circuit/target parity + lock API tests.
src/unix.rs Updates Unix lock implementation API; statvfs uses saturating arithmetic.
src/try_lock_error.rs Adds new TryLockError type + unit tests for conversions/semantics.
src/lib.rs Bumps doc URL/version, exports FileExt at root, adds TryLockError, removes nightly-only bench dependency.
src/fs_stats.rs Reformat + adds unit tests for getters/derives.
src/file_ext/sync_impl.rs Updates FileExt trait API/docs, refactors tests (adds allocation regressions), removes benches.
src/file_ext/async_impl.rs Updates AsyncFileExt trait API/docs and adds allocation regression tests.
src/file_ext.rs Adjusts module gating for sync impl to cover fs-err features without sync.
rustfmt.toml Adds repository rustfmt configuration (2-space indentation, width, etc.).
rust-toolchain.toml Switches toolchain channel to stable.
README.md Updates badges and dependency examples to 1.x.
Cargo.toml Bumps crate to 1.0.0 and updates windows-sys version.
CHANGELOG.md Adds 1.0.0 entry documenting breaking API changes and fixes.
.gitignore Ignores **.claude/ directory pattern.
.github/workflows/loc.yml Adds workflow to compute/upload LoC to a gist.
.github/workflows/coverage.yml Adds multi-OS coverage generation + Codecov upload.
.github/workflows/ci.yml Reworks CI to stable, adds cargo-hack feature matrix, adds cross builds, reorganizes jobs.
.codecov.yml Adds Codecov configuration file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/fs_stats.rs Resolved
Comment thread .github/workflows/loc.yml Resolved
Comment thread .github/workflows/coverage.yml Resolved
Comment thread .codecov.yml Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants