@@ -240,13 +240,19 @@ test_io_read_write(void)
240
240
{
241
241
const char * path_in = "/usr/share/dict/words" ;
242
242
char path_out [] = "/tmp/dispatchtest_io.XXXXXX" ;
243
- const size_t siz_in = 1024 * 1024 ;
244
243
245
244
int in = open (path_in , O_RDONLY );
246
245
if (in == -1 ) {
247
246
test_errno ("open" , errno , 0 );
248
247
test_stop ();
249
248
}
249
+ struct stat sb ;
250
+ if (fstat (in , & sb )) {
251
+ test_errno ("fstat" , errno , 0 );
252
+ test_stop ();
253
+ }
254
+ const size_t siz_in = MIN (1024 * 1024 , sb .st_size );
255
+
250
256
int out = mkstemp (path_out );
251
257
if (out == -1 ) {
252
258
test_errno ("mkstemp" , errno , 0 );
@@ -345,6 +351,11 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
345
351
{
346
352
int fd = open (path , O_RDONLY );
347
353
if (fd == -1 ) {
354
+ // Don't stop for access permission issues
355
+ if (errno == EACCES ) {
356
+ process_data (size );
357
+ return ;
358
+ }
348
359
test_errno ("Failed to open file" , errno , 0 );
349
360
test_stop ();
350
361
}
@@ -382,16 +393,12 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
382
393
break ;
383
394
case DISPATCH_IO_READ_ON_CONCURRENT_QUEUE :
384
395
case DISPATCH_IO_READ_FROM_PATH_ON_CONCURRENT_QUEUE : {
385
- __block bool is_done = false;
386
396
__block dispatch_data_t d = dispatch_data_empty ;
387
397
void (^cleanup_handler )(int error ) = ^(int error ) {
388
398
if (error ) {
389
399
test_errno ("dispatch_io_create error" , error , 0 );
390
400
test_stop ();
391
401
}
392
- if (!is_done ) {
393
- test_long ("dispatch_io_read done" , is_done , true);
394
- }
395
402
close (fd );
396
403
process_data (dispatch_data_get_size (d ));
397
404
dispatch_release (d );
@@ -432,7 +439,6 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue,
432
439
test_stop ();
433
440
}
434
441
}
435
- is_done = done ;
436
442
});
437
443
dispatch_release (io );
438
444
break ;
@@ -569,12 +575,18 @@ test_io_from_io(void) // rdar://problem/8388909
569
575
test_ptr_notnull ("mkdtemp failed" , path );
570
576
test_stop ();
571
577
}
572
- #ifdef __APPLE__
578
+ #ifdef UF_IMMUTABLE
573
579
// Make the directory immutable
574
580
if (chflags (path , UF_IMMUTABLE ) == -1 ) {
575
581
test_errno ("chflags" , errno , 0 );
576
582
test_stop ();
577
583
}
584
+ #else
585
+ // Make the directory non-read/writeable
586
+ if (chmod (path , 0 ) == -1 ) {
587
+ test_errno ("chmod" , errno , 0 );
588
+ test_stop ();
589
+ }
578
590
#endif
579
591
* tmp = '/' ;
580
592
dispatch_io_t io = dispatch_io_create_with_path (DISPATCH_IO_RANDOM , path ,
@@ -593,7 +605,11 @@ test_io_from_io(void) // rdar://problem/8388909
593
605
dispatch_group_enter (g );
594
606
dispatch_io_write (io , 0 , tdata , q , ^(bool done , dispatch_data_t data_out ,
595
607
int err_out ) {
608
+ #ifdef UF_IMMUTABLE
596
609
test_errno ("error from write to immutable directory" , err_out , EPERM );
610
+ #else
611
+ test_errno ("error from write to write protected directory" , err_out , EACCES );
612
+ #endif
597
613
test_long ("unwritten data" , dispatch_data_get_size (data_out ), 256 );
598
614
if (!err_out && done ) {
599
615
test_stop ();
@@ -605,13 +621,21 @@ test_io_from_io(void) // rdar://problem/8388909
605
621
dispatch_release (tdata );
606
622
dispatch_release (io );
607
623
test_group_wait (g );
608
- // Change the directory to mutable
609
624
* tmp = '\0' ;
625
+ #ifdef UF_IMMUTABLE
626
+ // Change the directory to mutable
610
627
if (chflags (path , 0 ) == -1 ) {
611
628
test_errno ("chflags" , errno , 0 );
612
629
test_stop ();
613
630
}
614
- const char * path_in = "/dev/random" ;
631
+ #else
632
+ // Change the directory to user read/write/execute
633
+ if (chmod (path , S_IRUSR | S_IWUSR | S_IXUSR ) == -1 ) {
634
+ test_errno ("chmod" , errno , 0 );
635
+ test_stop ();
636
+ }
637
+ #endif
638
+ const char * path_in = "/dev/urandom" ;
615
639
int in = open (path_in , O_RDONLY );
616
640
if (in == -1 ) {
617
641
test_errno ("open" , errno , 0 );
0 commit comments