Repository navigation
Conversation
Codecov Report❌ Patch coverage is
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
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
TryLockErrorand updatestry_lock*APIs to returnResult<(), TryLockError>; renames exclusive locking tolock(), and flattens thestdFileExtexport to the crate root. - Adjusts
allocate()behavior on Windows (avoid moving EOF when allocation already coverslen) 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.
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::Fileon 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
FileExt::lock_exclusive→lock,try_lock_exclusive→try_lock(both traits, sync + async). Mirrorsstd::fs::File::lock/try_lock.try_lock/try_lock_sharedreturn type fromstd::io::Result<bool>toResult<(), TryLockError>.Err(TryLockError::WouldBlock)now indicates a contended lock.fs4::TryLockError { Error(io::Error), WouldBlock }, mirroringstd::fs::TryLockError. IncludesDisplay,std::error::Error,From<io::Error>, andFrom<TryLockError> for io::Error.fs_stdmodule:FileExtforstd::fs::Filenow 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.lock_contended_error()— useTryLockError::WouldBlockinstead.Issue fixes
file.metadata()?.len() < lenin allocation code on Windows is problematic #13 — on Windows, skip the internalset_lencall when the file's existing cluster-aligned allocation already coverslen, avoiding the buffered-I/O quirks observed when EOF is moved inside an already-allocated cluster.allocatewhen the file is already at leastlenbytes long. Stops macOS'sF_PREALLOCATEpath from spuriously returningENOSPCwhenallocate(len)is re-called on an existing file.cygwinto theallocatetarget_os set so the crate compiles on cygwin.std::fs::File::lock/try_lock(stable in Rust 1.89+) win via inherent dispatch, removing theunstable_name_collisionswarning for std users on recent rustc.Latent compile bugs fixed
#[cfg(feature = "fs-err")]inunix.rs/windows.rs— a feature that doesn't exist. Nowany(feature = "fs-err2", feature = "fs-err3").--no-default-features --features fs-err2/fs-err3now build.feature = "fs-err-tokio"incfg_async!/unix.rs/windows.rs. Nowany(feature = "fs-err2-tokio", feature = "fs-err3-tokio").--no-default-features --features fs-err2-tokio/fs-err3-tokionow build.async_impl/sync_implconsistency: AIX moved to theset_lenfallback branch in async to match sync; redox and cygwin added to both branches.lock_impl!macro gated with#[allow(unused_macros)]socargo clippy --no-default-features(filesystem-stats-only build) doesn't fail on-D warnings.Testing
#[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.tomlswitched fromnightlytostable.allocate_preserves_eof_within_cluster(8 instances, coversfile.metadata()?.len() < lenin allocation code on Windows is problematic #13),allocate_idempotent(8 instances, covers Allocation on macOS is not working, while it does with fs2 #15), sevenTryLockErrorunit tests (variants,From/Into,Display,source), andfs_statsgetter + derive tests (previously uncovered by any test).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 asyncfilesystem_spacetest atomic (onestatvfs+ destructure instead of three separate calls racing against other tests).Dependencies / tooling
windows-sysfrom 0.59 to 0.61.html_root_urland all READMEfs4 = { version = "0.13", ... }snippets to"1".*-pc-windows-gnucross-compile targets (windows-sys 0.61 invokesdlltoolduring build, and ubuntu-latest ships only the x86_64 MinGW toolchain by default)..github/workflows/coverage.yml— per-OS matrix (linux / macos / windows) uploading to Codecov with per-OS flags, usingcargo tarpaulin --engine llvm.Migration guide
Full details in CHANGELOG.md.
Test plan
cargo test --all-features -- --test-threads 1— all 73 tests pass on macOS + Linuxcargo hack clippy --each-feature— clean across all 11 feature setscargo hack build --each-feature— cleancargo check --target x86_64-pc-windows-msvc --all-features --tests— cross-compile cleancargo checkon 1.75.0) — clean