Repository navigation
Conversation
| .open(path) | ||
| .or_else(|err| OpenOptions::new().read(true).open(path).map_err(|_| err)) | ||
| .map_err(|err| { | ||
| USimpleError::new( |
There was a problem hiding this comment.
could you please use a thiserror enum for the errors (like chcpu's errors.rs)? there are 5 USimpleError::new + format! here
There was a problem hiding this comment.
Done. The errors are now a FlockError enum in errors.rs. I checked all error paths against util-linux 2.42 and messages and exit codes are unchanged
| .arg( | ||
| Arg::new(options::NONBLOCK) | ||
| .short('n') | ||
| .long("nonblocking") |
There was a problem hiding this comment.
util-linux calls it --nonblock, not --nonblocking
it only works now because of infer_long_args
There was a problem hiding this comment.
The util-linux 2.42 man page and --help list -n, --nb, --nonblocking, so I kept that as the long name. I added nonblock as an explicit alias, so it no longer depends on infer_long_args. All three spellings are covered by test_nonblocking_long_and_alias.
| .create(true) | ||
| .truncate(false) | ||
| .open(path) | ||
| .or_else(|err| OpenOptions::new().read(true).open(path).map_err(|_| err)) |
There was a problem hiding this comment.
please add a test for the read-only file fallback
There was a problem hiding this comment.
Added test_read_only_lock_file. I checked that it fails without the fallback.
| continue; | ||
| } | ||
| } | ||
| return Err(USimpleError::new( |
There was a problem hiding this comment.
a blocking flock interrupted by a signal (EINTR) ends up here with 65, is it expected?
There was a problem hiding this comment.
Good catch, not intended. EINTR is now retried.
| let nonblock = matches.get_flag(options::NONBLOCK); | ||
| let conflict_exit_code = *matches.get_one::<u8>(options::CONFLICT_EXIT_CODE).unwrap(); | ||
| let operation = lock_mode(&matches).operation(); | ||
| let file_or_fd = matches.get_one(options::FILE_OR_FD).unwrap(); |
There was a problem hiding this comment.
already read in lock_target, could be dedup, no?
There was a problem hiding this comment.
Done. It is read once in uumain and passed to lock_target.
| let file = File::create(&lockfile).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) }, |
There was a problem hiding this comment.
almost the same code 5 times, could you please add a helper that holds the lock?
and a SAFETY comment on the unsafe
There was a problem hiding this comment.
Done. Added hold_lock() with SAFETY comment.
| } | ||
|
|
||
| #[test] | ||
| fn test_short_v_is_invalid() { |
There was a problem hiding this comment.
this will break as soon as --verbose is implemented, do we need it?
|
thanks for the patch! |
Support the file, directory and file descriptor forms with -s/-x/-u, -n, -w, -E and -c. Exit codes follow util-linux. Not yet implemented: -o, -F, --verbose, --fcntl.
dafdd0a to
5119e0d
Compare
Fixes #694
Adds a first implemention of
flockwith the core functionality fromflock(1):flock FILE CMD [ARGS…],flock FILE -c CMDandflock FD-s/-x/-e/-u(the last one wins, as in util-linux),-n/--nb, -w, -E, -cDifferences from util-linux:
-wpolls with LOCK_NB every 5 ms instead of using a timerNot implemented yet (follow-up PRs):
-o, -F, --verbose, --fcntl, --start, --length.