File tree Expand file tree Collapse file tree 2 files changed +25
-12
lines changed
Expand file tree Collapse file tree 2 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -757,22 +757,29 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
757757 |i| {
758758 let path_string = path. to_string ( ) ;
759759 match i. file_type ( ) {
760- #[ cfg( unix) ]
761- ft if ft. is_block_device ( ) => Err ( PrError :: UnknownFiletype { file : path_string } ) ,
762- #[ cfg( unix) ]
763- ft if ft. is_char_device ( ) => Err ( PrError :: UnknownFiletype { file : path_string } ) ,
764- #[ cfg( unix) ]
765- ft if ft. is_fifo ( ) => Err ( PrError :: UnknownFiletype { file : path_string } ) ,
766760 #[ cfg( unix) ]
767761 ft if ft. is_socket ( ) => Err ( PrError :: IsSocket { file : path_string } ) ,
768762 ft if ft. is_dir ( ) => Err ( PrError :: IsDirectory { file : path_string } ) ,
769- ft if ft. is_file ( ) || ft. is_symlink ( ) => {
770- Ok ( Box :: new ( File :: open ( path) . map_err ( |e| PrError :: Input {
771- source : e,
772- file : path. to_string ( ) ,
773- } ) ?) as Box < dyn Read > )
763+
764+ ft => {
765+ #[ allow( unused_mut) ]
766+ let mut is_valid = ft. is_file ( ) || ft. is_symlink ( ) ;
767+
768+ #[ cfg( unix) ]
769+ {
770+ is_valid =
771+ is_valid || ft. is_char_device ( ) || ft. is_block_device ( ) || ft. is_fifo ( ) ;
772+ }
773+
774+ if is_valid {
775+ Ok ( Box :: new ( File :: open ( path) . map_err ( |e| PrError :: Input {
776+ source : e,
777+ file : path. to_string ( ) ,
778+ } ) ?) as Box < dyn Read > )
779+ } else {
780+ Err ( PrError :: UnknownFiletype { file : path_string } )
781+ }
774782 }
775- _ => Err ( PrError :: UnknownFiletype { file : path_string } ) ,
776783 }
777784 } ,
778785 )
Original file line number Diff line number Diff line change @@ -610,3 +610,9 @@ fn test_help() {
610610fn test_version ( ) {
611611 new_ucmd ! ( ) . arg ( "--version" ) . succeeds ( ) ;
612612}
613+
614+ #[ cfg( unix) ]
615+ #[ test]
616+ fn test_pr_char_device_dev_null ( ) {
617+ new_ucmd ! ( ) . arg ( "/dev/null" ) . succeeds ( ) ;
618+ }
You can’t perform that action at this time.
0 commit comments