-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs2 was introduced in PR #500, but we actually don't really need that much from it. This commit removes the extra dependency in favor of doing the same directly. I think this is pretty-much equivalent to inlining the code.
- Loading branch information
Showing
4 changed files
with
25 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,23 @@ | ||
//! Common Unix definitions. | ||
use std::{fs::File, os::fd::AsRawFd as _}; | ||
|
||
pub fn try_lock_exclusive(file: &File) -> std::io::Result<()> { | ||
unsafe { | ||
if libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) == -1 { | ||
Err(std::io::Error::last_os_error()) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
pub fn unlock(file: &File) -> std::io::Result<()> { | ||
unsafe { | ||
if libc::flock(file.as_raw_fd(), libc::LOCK_UN) == -1 { | ||
Err(std::io::Error::last_os_error()) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} |