11use nix:: errno:: Errno ;
2+ use nix:: fcntl:: AtFlags ;
3+ use nix:: fcntl:: OFlag ;
24use nix:: fcntl:: open;
35use nix:: fcntl:: openat;
46use nix:: fcntl:: renameat;
5- use nix:: fcntl:: AtFlags ;
6- use nix:: fcntl:: OFlag ;
77use nix:: libc;
8+ use nix:: sys:: stat:: Mode ;
89use nix:: sys:: stat:: fchmod;
910use nix:: sys:: stat:: fstatat;
1011use nix:: sys:: stat:: mode_t;
11- use nix:: sys:: stat:: Mode ;
12- use nix:: unistd:: fchown;
13- use nix:: unistd:: fsync;
14- use nix:: unistd:: unlinkat;
1512use nix:: unistd:: Gid ;
1613use nix:: unistd:: Uid ;
1714use nix:: unistd:: UnlinkatFlags ;
18- use rand:: distr:: Alphanumeric ;
15+ use nix:: unistd:: fchown;
16+ use nix:: unistd:: fsync;
17+ use nix:: unistd:: unlinkat;
1918use rand:: Rng ;
19+ use rand:: distr:: Alphanumeric ;
2020use std:: ffi:: OsStr ;
2121use std:: ffi:: OsString ;
2222use std:: fs:: File ;
@@ -99,6 +99,7 @@ impl Dir {
9999 OFlag :: O_DIRECTORY | OFlag :: O_CLOEXEC ,
100100 Mode :: empty ( ) ,
101101 ) ?;
102+ // SAFETY: `fd` is an exclusively owned file descriptor, and it's open
102103 Ok ( unsafe { Self :: from_raw_fd ( fd) } )
103104 }
104105}
@@ -120,7 +121,8 @@ impl AsRawFd for Dir {
120121impl FromRawFd for Dir {
121122 unsafe fn from_raw_fd ( fd : RawFd ) -> Self {
122123 Self {
123- fd : OwnedFd :: from_raw_fd ( fd) ,
124+ // SAFETY: upheld by the caller
125+ fd : unsafe { OwnedFd :: from_raw_fd ( fd) } ,
124126 }
125127 }
126128}
@@ -190,6 +192,7 @@ fn create_temporary_file(
190192 }
191193 } ;
192194
195+ // SAFETY: `file_fd` is an exclusively owned file descriptor, and it's open
193196 let file = unsafe { File :: from_raw_fd ( file_fd) } ;
194197 let temporary_name = random_name. into_os_string ( ) ;
195198 Ok ( ( file, temporary_name) )
0 commit comments