diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index 2986abb905df..9d73e14bcca3 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -395,8 +395,38 @@ mod sys { #[cfg(target_os = "solaris")] fn flock(file: &File, flag: libc::c_int) -> Result<()> { - // Solaris lacks flock(), so simply succeed with a no-op - Ok(()) + // Solaris lacks flock(), so try to emulate using fcntl() + let mut flock = libc::flock { + l_type: 0, + l_whence: 0, + l_start: 0, + l_len: 0, + l_sysid: 0, + l_pid: 0, + l_pad: [0, 0, 0, 0], + }; + if (flag & libc::LOCK_SH) != 0 { + flock.l_type |= libc::F_RDLCK; + } + if (flag & libc::LOCK_EX) != 0 { + flock.l_type |= libc::F_WRLCK; + } + if (flag & libc::LOCK_UN) != 0 { + flock.l_type |= libc::F_UNLCK; + } + + let mut ltype = libc::F_SETLKW; + if (flag & libc::LOCK_NB) != 0 { + ltype = libc::F_SETLK; + } + + let ret = unsafe { libc::fcntl(file.as_raw_fd(), ltype, &flock) }; + + if ret < 0 { + Err(Error::last_os_error()) + } else { + Ok(()) + } } }