| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/io/::{AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#}; |
| 4 | |
| 5 | use craterust-analyzer cargo advisory-lock 0.3.0 crate/::{AdvisoryFileLockrust-analyzer cargo advisory-lock 0.3.0 AdvisoryFileLock#, FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#, FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#}; |
| 6 | |
| 7 | impl AdvisoryFileLockrust-analyzer cargo advisory-lock 0.3.0 AdvisoryFileLock# for Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# { |
| 8 | fn lockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[File][AdvisoryFileLock]lock().(&self, file_lock_mode: FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 9 | self.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().().lockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[i32][AdvisoryFileLock]lock().(file_lock_mode) |
| 10 | } |
| 11 | |
| 12 | fn try_lockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[File][AdvisoryFileLock]try_lock().(&self, file_lock_mode: FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 13 | self.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().().try_lockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[i32][AdvisoryFileLock]try_lock().(file_lock_mode) |
| 14 | } |
| 15 | |
| 16 | fn unlockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[File][AdvisoryFileLock]unlock().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 17 | self.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().().unlockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[i32][AdvisoryFileLock]unlock().() |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | impl AdvisoryFileLockrust-analyzer cargo advisory-lock 0.3.0 AdvisoryFileLock# for RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd# { |
| 22 | fn lockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[i32][AdvisoryFileLock]lock().(&self, file_lock_mode: FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 23 | lock_filerust-analyzer cargo advisory-lock 0.3.0 unix/lock_file().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, file_lock_mode, false) |
| 24 | } |
| 25 | |
| 26 | fn try_lockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[i32][AdvisoryFileLock]try_lock().(&self, file_lock_mode: FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 27 | lock_filerust-analyzer cargo advisory-lock 0.3.0 unix/lock_file().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, file_lock_mode, true) |
| 28 | } |
| 29 | |
| 30 | fn unlockrust-analyzer cargo advisory-lock 0.3.0 unix/impl#[i32][AdvisoryFileLock]unlock().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 31 | unlock_filerust-analyzer cargo advisory-lock 0.3.0 unix/unlock_file().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | fn lock_filerust-analyzer cargo advisory-lock 0.3.0 unix/lock_file().( |
| 36 | raw_fd: RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#, |
| 37 | file_lock_mode: FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#, |
| 38 | immediate: bool, |
| 39 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 40 | let mut flags = match file_lock_mode { |
| 41 | FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#::Sharedrust-analyzer cargo advisory-lock 0.3.0 FileLockMode#Shared# => libcrust-analyzer cargo libc 0.2.189 crate/::LOCK_SHrust-analyzer cargo libc 0.2.189 unix/linux_like/LOCK_SH., |
| 42 | FileLockModerust-analyzer cargo advisory-lock 0.3.0 FileLockMode#::Exclusiverust-analyzer cargo advisory-lock 0.3.0 FileLockMode#Exclusive# => libcrust-analyzer cargo libc 0.2.189 crate/::LOCK_EXrust-analyzer cargo libc 0.2.189 unix/linux_like/LOCK_EX., |
| 43 | }; |
| 44 | if immediate { |
| 45 | flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitOrAssign<Self>`]bitor_assign().libcrust-analyzer cargo libc 0.2.189 crate/::LOCK_NBrust-analyzer cargo libc 0.2.189 unix/linux_like/LOCK_NB.; |
| 46 | } |
| 47 | |
| 48 | let result = unsafe { libcrust-analyzer cargo libc 0.2.189 crate/::flockrust-analyzer cargo libc 0.2.189 flock().(raw_fd, flags) }; |
| 49 | if result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0 { |
| 50 | let last_os_error = Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().(); |
| 51 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(match last_os_error.raw_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]raw_os_error().() { |
| 52 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(code) if code rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().libcrust-analyzer cargo libc 0.2.189 crate/::EWOULDBLOCKrust-analyzer cargo libc 0.2.189 unix/linux_like/linux_l4re_shared/EWOULDBLOCK. => FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#::AlreadyLockedrust-analyzer cargo advisory-lock 0.3.0 FileLockError#AlreadyLocked#, |
| 53 | _ => FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#::Iorust-analyzer cargo advisory-lock 0.3.0 FileLockError#Io#(last_os_error), |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 58 | } |
| 59 | |
| 60 | fn unlock_filerust-analyzer cargo advisory-lock 0.3.0 unix/unlock_file().(raw_fd: RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#> { |
| 61 | let result = unsafe { libcrust-analyzer cargo libc 0.2.189 crate/::flockrust-analyzer cargo libc 0.2.189 flock().(raw_fd, libcrust-analyzer cargo libc 0.2.189 crate/::LOCK_UNrust-analyzer cargo libc 0.2.189 unix/linux_like/LOCK_UN.) }; |
| 62 | if result rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 63 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 64 | } else { |
| 65 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FileLockErrorrust-analyzer cargo advisory-lock 0.3.0 FileLockError#::Iorust-analyzer cargo advisory-lock 0.3.0 FileLockError#Io#(Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().())) |
| 66 | } |
| 67 | } |