1
- // todo fix these CI in windows
2
- #![ cfg( not( windows) ) ]
3
- use std:: io:: prelude:: * ;
1
+ use std:: io:: { prelude:: * , SeekFrom } ;
4
2
#[ cfg( unix) ]
5
3
use std:: os:: unix:: io:: { AsRawFd , FromRawFd , RawFd } ;
6
4
#[ cfg( windows) ]
@@ -55,7 +53,7 @@ async fn basic_write() {
55
53
file. write_at ( HELLO , 0 ) . await . 0 . unwrap ( ) ;
56
54
file. sync_all ( ) . await . unwrap ( ) ;
57
55
58
- let file = std :: fs:: read ( tempfile. path ( ) ) . unwrap ( ) ;
56
+ let file = monoio :: fs:: read ( tempfile. path ( ) ) . await . unwrap ( ) ;
59
57
assert_eq ! ( file, HELLO ) ;
60
58
}
61
59
@@ -167,6 +165,7 @@ async fn poll_once(future: impl std::future::Future) {
167
165
. await ;
168
166
}
169
167
168
+ #[ allow( unused, clippy:: needless_return) ]
170
169
fn assert_invalid_fd ( fd : RawFd , base : std:: fs:: Metadata ) {
171
170
use std:: fs:: File ;
172
171
#[ cfg( unix) ]
@@ -194,6 +193,7 @@ fn assert_invalid_fd(fd: RawFd, base: std::fs::Metadata) {
194
193
}
195
194
}
196
195
196
+ #[ cfg( unix) ]
197
197
#[ monoio:: test_all]
198
198
async fn file_from_std ( ) {
199
199
let tempfile = tempfile ( ) ;
@@ -208,3 +208,44 @@ async fn file_from_std() {
208
208
file. sync_all ( ) . await . unwrap ( ) ;
209
209
read_hello ( & file) . await ;
210
210
}
211
+
212
+ #[ monoio:: test_all]
213
+ async fn position_read ( ) {
214
+ let mut tempfile = tempfile ( ) ;
215
+ tempfile. write_all ( HELLO ) . unwrap ( ) ;
216
+ tempfile. as_file_mut ( ) . sync_data ( ) . unwrap ( ) ;
217
+
218
+ let file = File :: open ( tempfile. path ( ) ) . await . unwrap ( ) ;
219
+
220
+ // Modify the file pointer.
221
+ let mut std_file = std:: fs:: File :: open ( tempfile. path ( ) ) . unwrap ( ) ;
222
+ std_file. seek ( SeekFrom :: Start ( 8 ) ) . unwrap ( ) ;
223
+
224
+ let buf = Vec :: with_capacity ( 1024 ) ;
225
+ let ( res, buf) = file. read_at ( buf, 4 ) . await ;
226
+ let n = res. unwrap ( ) ;
227
+
228
+ assert ! ( n > 0 && n <= HELLO . len( ) - 4 ) ;
229
+ assert_eq ! ( & buf, & HELLO [ 4 ..4 + n] ) ;
230
+ }
231
+
232
+ #[ monoio:: test_all]
233
+ async fn position_write ( ) {
234
+ let tempfile = tempfile ( ) ;
235
+
236
+ let file = File :: create ( tempfile. path ( ) ) . await . unwrap ( ) ;
237
+ file. write_at ( HELLO , 0 ) . await . 0 . unwrap ( ) ;
238
+ file. sync_all ( ) . await . unwrap ( ) ;
239
+
240
+ // Modify the file pointer.
241
+ let mut std_file = std:: fs:: File :: open ( tempfile. path ( ) ) . unwrap ( ) ;
242
+ std_file. seek ( SeekFrom :: Start ( 8 ) ) . unwrap ( ) ;
243
+
244
+ file. write_at ( b"monoio..." , 6 ) . await . 0 . unwrap ( ) ;
245
+ file. sync_all ( ) . await . unwrap ( ) ;
246
+
247
+ assert_eq ! (
248
+ monoio:: fs:: read( tempfile. path( ) ) . await . unwrap( ) ,
249
+ b"hello monoio..."
250
+ )
251
+ }
0 commit comments