Skip to content

Commit a803496

Browse files
committed
Fix deprecation warnings with current nix
We no longer need to convert nix errors with from_errno() or as_errno(), and they're no longer wrapped in Option<>. This requires dropping support for nix < 0.22.
1 parent 53324cf commit a803496

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ documentation = "http://docs.rs/openat-ext"
1616
[dependencies]
1717
openat = "0.1.15"
1818
libc = "^0.2.94"
19-
nix = ">= 0.18, < 0.23"
19+
nix = ">= 0.22, < 0.23"
2020
rand = "0.8.3"
2121

2222
[dev-dependencies]

src/lib.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,7 @@ fn impl_read_to_string(mut f: File) -> io::Result<String> {
433433
}
434434

435435
fn map_nix_error(e: nix::Error) -> io::Error {
436-
match e.as_errno() {
437-
Some(os_err) => io::Error::from_raw_os_error(os_err as i32),
438-
_ => io::Error::new(io::ErrorKind::Other, e),
439-
}
436+
io::Error::from_raw_os_error(e as i32)
440437
}
441438

442439
fn copy_regfile_inner(
@@ -734,22 +731,22 @@ impl FileExt for File {
734731
let copy_result =
735732
copy_file_range(self.as_raw_fd(), None, to.as_raw_fd(), None, bytes_to_copy);
736733
if let Err(ref copy_err) = copy_result {
737-
match copy_err.as_errno() {
738-
Some(Errno::ENOSYS) | Some(Errno::EPERM) => {
734+
match copy_err {
735+
Errno::ENOSYS | Errno::EPERM => {
739736
HAS_COPY_FILE_RANGE.store(false, Ordering::Relaxed);
740737
}
741738
_ => {}
742739
}
743740
}
744741
copy_result
745742
} else {
746-
Err(nix::Error::from_errno(Errno::ENOSYS))
743+
Err(Errno::ENOSYS)
747744
};
748745
match copy_result {
749746
Ok(ret) => written += ret as u64,
750747
Err(err) => {
751-
match err.as_errno() {
752-
Some(os_err)
748+
match err {
749+
os_err
753750
if os_err == Errno::ENOSYS
754751
|| os_err == Errno::EXDEV
755752
|| os_err == Errno::EINVAL
@@ -763,8 +760,7 @@ impl FileExt for File {
763760
assert_eq!(written, 0);
764761
return fallback_file_copy(self, to);
765762
}
766-
Some(os_err) => return Err(io::Error::from_raw_os_error(os_err as i32)),
767-
_ => return Err(io::Error::new(io::ErrorKind::Other, err)),
763+
os_err => return Err(map_nix_error(os_err)),
768764
}
769765
}
770766
}

0 commit comments

Comments
 (0)