Skip to content

Commit f8556f9

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

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/cargo/util/flock.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,30 +430,48 @@ fn is_on_nfs_mount(_path: &Path) -> bool {
430430
false
431431
}
432432

433+
#[cfg(all(unix, not(target_os = "solaris")))]
434+
const LOCK_SH: i32 = libc::LOCK_SH;
435+
#[cfg(all(unix, target_os = "solaris"))]
436+
const LOCK_SH: i32 = 1;
437+
#[cfg(all(unix, not(target_os = "solaris")))]
438+
const LOCK_EX: i32 = libc::LOCK_EX;
439+
#[cfg(all(unix, target_os = "solaris"))]
440+
const LOCK_EX: i32 = 2;
441+
#[cfg(all(unix, not(target_os = "solaris")))]
442+
const LOCK_NB: i32 = libc::LOCK_NB;
443+
#[cfg(all(unix, target_os = "solaris"))]
444+
const LOCK_NB: i32 = 4;
445+
#[cfg(all(unix, not(target_os = "solaris")))]
446+
const LOCK_UN: i32 = libc::LOCK_UN;
447+
#[cfg(all(unix, target_os = "solaris"))]
448+
const LOCK_UN: i32 = 8;
449+
433450
#[cfg(unix)]
434451
mod sys {
452+
use crate::util::flock::{LOCK_EX, LOCK_NB, LOCK_SH, LOCK_UN};
435453
use std::fs::File;
436454
use std::io::{Error, Result};
437455
use std::os::unix::io::AsRawFd;
438456

439457
pub(super) fn lock_shared(file: &File) -> Result<()> {
440-
flock(file, libc::LOCK_SH)
458+
flock(file, LOCK_SH)
441459
}
442460

443461
pub(super) fn lock_exclusive(file: &File) -> Result<()> {
444-
flock(file, libc::LOCK_EX)
462+
flock(file, LOCK_EX)
445463
}
446464

447465
pub(super) fn try_lock_shared(file: &File) -> Result<()> {
448-
flock(file, libc::LOCK_SH | libc::LOCK_NB)
466+
flock(file, LOCK_SH | LOCK_NB)
449467
}
450468

451469
pub(super) fn try_lock_exclusive(file: &File) -> Result<()> {
452-
flock(file, libc::LOCK_EX | libc::LOCK_NB)
470+
flock(file, LOCK_EX | LOCK_NB)
453471
}
454472

455473
pub(super) fn unlock(file: &File) -> Result<()> {
456-
flock(file, libc::LOCK_UN)
474+
flock(file, LOCK_UN)
457475
}
458476

459477
pub(super) fn error_contended(err: &Error) -> bool {
@@ -493,18 +511,18 @@ mod sys {
493511
l_pid: 0,
494512
l_pad: [0, 0, 0, 0],
495513
};
496-
flock.l_type = if flag & libc::LOCK_UN != 0 {
514+
flock.l_type = if flag & LOCK_UN != 0 {
497515
libc::F_UNLCK
498-
} else if flag & libc::LOCK_EX != 0 {
516+
} else if flag & LOCK_EX != 0 {
499517
libc::F_WRLCK
500-
} else if flag & libc::LOCK_SH != 0 {
518+
} else if flag & LOCK_SH != 0 {
501519
libc::F_RDLCK
502520
} else {
503521
panic!("unexpected flock() operation")
504522
};
505523

506524
let mut cmd = libc::F_SETLKW;
507-
if (flag & libc::LOCK_NB) != 0 {
525+
if (flag & LOCK_NB) != 0 {
508526
cmd = libc::F_SETLK;
509527
}
510528

0 commit comments

Comments
 (0)