@@ -23,7 +23,7 @@ use std::collections::hash_map::Entry;
23
23
use std:: collections:: HashSet ;
24
24
use std:: ffi:: CString ;
25
25
use std:: mem:: MaybeUninit ;
26
- use std:: os:: fd:: { AsRawFd , OwnedFd , RawFd } ;
26
+ use std:: os:: fd:: { AsFd , AsRawFd , OwnedFd , RawFd } ;
27
27
use std:: os:: unix:: prelude:: MetadataExt ;
28
28
29
29
// Pull in the O_EXLOCK constant if it is defined, otherwise set it to 0.
@@ -533,11 +533,12 @@ impl EnvUniversal {
533
533
}
534
534
535
535
/// Writes our state to the fd. path is provided only for error reporting.
536
- fn write_to_fd ( & mut self , fd : RawFd , path : & wstr ) -> bool {
537
- assert ! ( fd >= 0 ) ;
538
- let mut success = true ;
536
+ fn write_to_fd ( & mut self , fd : impl AsFd , path : & wstr ) -> std:: io:: Result < usize > {
537
+ let fd = fd. as_fd ( ) ;
539
538
let contents = Self :: serialize_with_vars ( & self . vars ) ;
540
- if let Err ( err) = write_loop ( & fd, & contents) {
539
+ let res = write_loop ( & fd, & contents) ;
540
+
541
+ if let Err ( err) = res. as_ref ( ) {
541
542
let error = Errno ( err. raw_os_error ( ) . unwrap ( ) ) ;
542
543
FLOG ! (
543
544
error,
@@ -547,14 +548,13 @@ impl EnvUniversal {
547
548
error. to_string( )
548
549
) ,
549
550
) ;
550
- success = false ;
551
551
}
552
552
553
553
// Since we just wrote out this file, it matches our internal state; pretend we read from it.
554
- self . last_read_file = file_id_for_fd ( fd) ;
554
+ self . last_read_file = file_id_for_fd ( fd. as_raw_fd ( ) ) ;
555
555
556
556
// We don't close the file.
557
- success
557
+ res
558
558
}
559
559
560
560
fn move_new_vars_file_into_place ( & mut self , src : & wstr , dst : & wstr ) -> bool {
@@ -768,7 +768,7 @@ impl EnvUniversal {
768
768
let private_file_path = & delete_pfp;
769
769
770
770
// Write to it.
771
- if ! self . write_to_fd ( private_fd. as_raw_fd ( ) , & private_file_path) {
771
+ if self . write_to_fd ( & private_fd, private_file_path) . is_err ( ) {
772
772
FLOG ! ( uvar_file, "universal log write_to_fd() failed" ) ;
773
773
return false ;
774
774
}
@@ -812,7 +812,7 @@ impl EnvUniversal {
812
812
}
813
813
814
814
// Apply new file.
815
- if !self . move_new_vars_file_into_place ( & private_file_path, & real_path) {
815
+ if !self . move_new_vars_file_into_place ( private_file_path, & real_path) {
816
816
FLOG ! (
817
817
uvar_file,
818
818
"universal log move_new_vars_file_into_place() failed"
0 commit comments