Skip to content

Add Solaris fcntl file locking#17110

Merged
ehuss merged 1 commit into
rust-lang:masterfrom
psumbera:solaris-fcntl-locking
Jun 23, 2026
Merged

Add Solaris fcntl file locking#17110
ehuss merged 1 commit into
rust-lang:masterfrom
psumbera:solaris-fcntl-locking

Conversation

@psumbera

Copy link
Copy Markdown
Contributor

Rust std no longer provides File::lock support on Solaris because its fcntl emulation is process-scoped rather than handle-scoped. Keep Cargo's inter-process locking working on Solaris by routing Cargo's FileLock abstraction through a Solaris-specific fcntl backend.

Use whole-file advisory locks for shared, exclusive, nonblocking, blocking, and unlock operations, while leaving other platforms on std::fs::File locking. Mark the same-process cache-lock tests ignored on Solaris because fcntl locks are process-scoped and those tests do not model separate Cargo processes.

@rustbot rustbot added A-filesystem Area: issues with filesystems S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Comment thread src/cargo/util/flock.rs Outdated
Comment on lines +505 to +508
pub enum LockKind {
Exclusive,
Shared,
}

@ehuss ehuss Jun 20, 2026

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.

Just a minor nit, is there a reason to duplicate this LockKind enum in each imp? That is, could it be lifted out?

Or, maybe a more general question, why was this added? At a glance, it seems like if each imp had the separate functions for exclusive and shared without the kind (and remove the functions in the parent module), that would simplify this and have fewer lines overall.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I originally used LockKind to keep the Solaris fcntl path centralized, since shared and exclusive locks only differ by the raw lock type.

I simplified this now: each backend exposes explicit shared/exclusive functions, and the Solaris backend keeps only a private helper that takes the raw fcntl lock type. That removes the duplicated enum and the parent wrapper functions while keeping the behavior unchanged.

Rust std no longer provides File::lock support on Solaris because its fcntl
emulation is process-scoped rather than handle-scoped. Keep Cargo's
inter-process locking working on Solaris by routing Cargo's FileLock
abstraction through a Solaris-specific fcntl backend.

Use whole-file advisory locks for shared, exclusive, nonblocking, blocking,
and unlock operations, while leaving other platforms on std::fs::File locking.
Mark the same-process cache-lock tests ignored on Solaris because fcntl locks
are process-scoped and those tests do not model separate Cargo processes.
@psumbera psumbera force-pushed the solaris-fcntl-locking branch from 040c704 to 5fe7a28 Compare June 22, 2026 08:05

@ehuss ehuss 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.

@ehuss ehuss enabled auto-merge June 22, 2026 22:55
@ehuss ehuss closed this Jun 22, 2026
auto-merge was automatically disabled June 22, 2026 22:55

Pull request was closed

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2026
@ehuss ehuss reopened this Jun 22, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2026
@ehuss ehuss enabled auto-merge June 22, 2026 22:56

@weihanglo weihanglo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, this -Zfine-grain-locking branch also needs a patch. Not blocking though.

lock.file().unlock()?;

View changes since this review

@ehuss ehuss added this pull request to the merge queue Jun 22, 2026
Merged via the queue into rust-lang:master with commit dd9ec98 Jun 23, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-filesystem Area: issues with filesystems

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants