Skip to content

Commit fe9e148

Browse files
committed
Don't use on Solaris libc::LOCK_* which were removed from libc in version 0.2.162
1 parent 6d1f6be commit fe9e148

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/cargo/util/flock.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,23 +437,58 @@ mod sys {
437437
use std::os::unix::io::AsRawFd;
438438

439439
pub(super) fn lock_shared(file: &File) -> Result<()> {
440-
flock(file, libc::LOCK_SH)
440+
#[cfg(not(target_os = "solaris"))]
441+
{
442+
flock(file, libc::LOCK_SH)
443+
}
444+
#[cfg(target_os = "solaris")]
445+
{
446+
flock(file, 1)
447+
}
441448
}
442449

443450
pub(super) fn lock_exclusive(file: &File) -> Result<()> {
444-
flock(file, libc::LOCK_EX)
451+
#[cfg(not(target_os = "solaris"))]
452+
{
453+
flock(file, libc::LOCK_EX)
454+
}
455+
#[cfg(target_os = "solaris")]
456+
{
457+
flock(file, 2)
458+
}
445459
}
446460

447461
pub(super) fn try_lock_shared(file: &File) -> Result<()> {
448-
flock(file, libc::LOCK_SH | libc::LOCK_NB)
462+
#[cfg(not(target_os = "solaris"))]
463+
{
464+
flock(file, libc::LOCK_SH | libc::LOCK_NB)
465+
}
466+
#[cfg(target_os = "solaris")]
467+
{
468+
flock(file, 1 | 4)
469+
}
449470
}
450471

451472
pub(super) fn try_lock_exclusive(file: &File) -> Result<()> {
452-
flock(file, libc::LOCK_EX | libc::LOCK_NB)
473+
#[cfg(not(target_os = "solaris"))]
474+
{
475+
flock(file, libc::LOCK_EX | libc::LOCK_NB)
476+
}
477+
#[cfg(target_os = "solaris")]
478+
{
479+
flock(file, 2 | 4)
480+
}
453481
}
454482

455483
pub(super) fn unlock(file: &File) -> Result<()> {
456-
flock(file, libc::LOCK_UN)
484+
#[cfg(not(target_os = "solaris"))]
485+
{
486+
flock(file, libc::LOCK_UN)
487+
}
488+
#[cfg(target_os = "solaris")]
489+
{
490+
flock(file, 8)
491+
}
457492
}
458493

459494
pub(super) fn error_contended(err: &Error) -> bool {
@@ -493,18 +528,18 @@ mod sys {
493528
l_pid: 0,
494529
l_pad: [0, 0, 0, 0],
495530
};
496-
flock.l_type = if flag & libc::LOCK_UN != 0 {
531+
flock.l_type = if flag & 8 != 0 {
497532
libc::F_UNLCK
498-
} else if flag & libc::LOCK_EX != 0 {
533+
} else if flag & 2 != 0 {
499534
libc::F_WRLCK
500-
} else if flag & libc::LOCK_SH != 0 {
535+
} else if flag & 1 != 0 {
501536
libc::F_RDLCK
502537
} else {
503538
panic!("unexpected flock() operation")
504539
};
505540

506541
let mut cmd = libc::F_SETLKW;
507-
if (flag & libc::LOCK_NB) != 0 {
542+
if (flag & 4) != 0 {
508543
cmd = libc::F_SETLK;
509544
}
510545

0 commit comments

Comments
 (0)